Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / api / smsTransferReport / smsTransferReport.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x850f=['rawAttributes','fieldName','type','key','query','filters','intersection','model','fields','attributes','length','nolimit','order','sort','where','filter','merge','VIRTUAL','includeAll','include','findAll','rows','catch','show','params','keys','options','find','create','body','update','describe','eml-format','zip-dir','moment','util','path','sox','to-csv','fs-extra','lodash','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','offset','undefined','limit','count','set','Content-Range','apply','reject','save','then','sendStatus','error','name','send','index','map','SmsTransferReport'];(function(_0x4c0622,_0x5dacaf){var _0x1799d8=function(_0x2ba801){while(--_0x2ba801){_0x4c0622['push'](_0x4c0622['shift']());}};_0x1799d8(++_0x5dacaf);}(_0x850f,0xfe));var _0xf850=function(_0x2785f2,_0x170dce){_0x2785f2=_0x2785f2-0x0;var _0x39ad95=_0x850f[_0x2785f2];return _0x39ad95;};'use strict';var emlformat=require(_0xf850('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf850('0x1'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xf850('0x2'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xf850('0x3'));var path=require(_0xf850('0x4'));var sox=require(_0xf850('0x5'));var csv=require(_0xf850('0x6'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0xf850('0x7'));var _=require(_0xf850('0x8'));var squel=require('squel');var crypto=require(_0xf850('0x9'));var jsforce=require(_0xf850('0xa'));var deskjs=require(_0xf850('0xb'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0xf850('0xc'));var Redis=require(_0xf850('0xd'));var authService=require(_0xf850('0xe'));var qs=require('../../components/parsers/qs');var as=require(_0xf850('0xf'));var hardwareService=require(_0xf850('0x10'));var logger=require(_0xf850('0x11'))('api');var utils=require(_0xf850('0x12'));var config=require(_0xf850('0x13'));var licenseUtil=require(_0xf850('0x14'));var db=require(_0xf850('0x15'))['db'];function respondWithStatusCode(_0x452615,_0x8955a2){_0x8955a2=_0x8955a2||0xcc;return function(_0x47d06a){if(_0x47d06a){return _0x452615['sendStatus'](_0x8955a2);}return _0x452615['status'](_0x8955a2)[_0xf850('0x16')]();};}function respondWithResult(_0x100c7,_0x48dea0){_0x48dea0=_0x48dea0||0xc8;return function(_0xef7535){if(_0xef7535){return _0x100c7[_0xf850('0x17')](_0x48dea0)[_0xf850('0x18')](_0xef7535);}};}function respondWithFilteredResult(_0xfefdb3,_0x197b3b){return function(_0x1ecd6c){if(_0x1ecd6c){var _0xb6d1d3=typeof _0x197b3b[_0xf850('0x19')]===_0xf850('0x1a')&&typeof _0x197b3b[_0xf850('0x1b')]===_0xf850('0x1a');var _0x111f96=_0x1ecd6c[_0xf850('0x1c')];var _0x2eff22=_0xb6d1d3?0x0:_0x197b3b[_0xf850('0x19')];var _0x45a7ae=_0xb6d1d3?_0x1ecd6c[_0xf850('0x1c')]:_0x197b3b[_0xf850('0x19')]+_0x197b3b[_0xf850('0x1b')];var _0x1c0f5c;if(_0x45a7ae>=_0x111f96){_0x45a7ae=_0x111f96;_0x1c0f5c=0xc8;}else{_0x1c0f5c=0xce;}_0xfefdb3['status'](_0x1c0f5c);return _0xfefdb3[_0xf850('0x1d')](_0xf850('0x1e'),_0x2eff22+'-'+_0x45a7ae+'/'+_0x111f96)[_0xf850('0x18')](_0x1ecd6c);}return null;};}function patchUpdates(_0x56da0b){return function(_0x25f9b2){try{jsonpatch[_0xf850('0x1f')](_0x25f9b2,_0x56da0b,!![]);}catch(_0x30b1a2){return BPromise[_0xf850('0x20')](_0x30b1a2);}return _0x25f9b2[_0xf850('0x21')]();};}function saveUpdates(_0x8f5daa,_0x53ce2f){return function(_0x3d7ab5){if(_0x3d7ab5){return _0x3d7ab5['update'](_0x8f5daa)[_0xf850('0x22')](function(_0xf1e8d1){return _0xf1e8d1;});}return null;};}function removeEntity(_0xd04532,_0xf9ed7d){return function(_0x474a51){if(_0x474a51){return _0x474a51['destroy']()[_0xf850('0x22')](function(){_0xd04532[_0xf850('0x17')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3360de,_0x1bca50){return function(_0x2b893d){if(!_0x2b893d){_0x3360de[_0xf850('0x23')](0x194);}return _0x2b893d;};}function handleError(_0x21fa45,_0x219e36){_0x219e36=_0x219e36||0x1f4;return function(_0x339767){logger[_0xf850('0x24')](_0x339767['stack']);if(_0x339767[_0xf850('0x25')]){delete _0x339767[_0xf850('0x25')];}_0x21fa45[_0xf850('0x17')](_0x219e36)[_0xf850('0x26')](_0x339767);};}exports[_0xf850('0x27')]=function(_0x310fd4,_0x47e7d9){var _0x313d74={},_0x21ab43={},_0x565c5d={'count':0x0,'rows':[]};var _0x37faad=_[_0xf850('0x28')](db[_0xf850('0x29')][_0xf850('0x2a')],function(_0x44950d){return{'name':_0x44950d[_0xf850('0x2b')],'type':_0x44950d[_0xf850('0x2c')][_0xf850('0x2d')]};});_0x21ab43['model']=_[_0xf850('0x28')](_0x37faad,_0xf850('0x25'));_0x21ab43[_0xf850('0x2e')]=_['keys'](_0x310fd4[_0xf850('0x2e')]);_0x21ab43[_0xf850('0x2f')]=_[_0xf850('0x30')](_0x21ab43[_0xf850('0x31')],_0x21ab43[_0xf850('0x2e')]);_0x313d74['attributes']=_['intersection'](_0x21ab43[_0xf850('0x31')],qs[_0xf850('0x32')](_0x310fd4[_0xf850('0x2e')][_0xf850('0x32')]));_0x313d74[_0xf850('0x33')]=_0x313d74['attributes'][_0xf850('0x34')]?_0x313d74[_0xf850('0x33')]:_0x21ab43[_0xf850('0x31')];if(!_0x310fd4['query']['hasOwnProperty'](_0xf850('0x35'))){_0x313d74[_0xf850('0x1b')]=qs[_0xf850('0x1b')](_0x310fd4[_0xf850('0x2e')]['limit']);_0x313d74[_0xf850('0x19')]=qs[_0xf850('0x19')](_0x310fd4[_0xf850('0x2e')][_0xf850('0x19')]);}_0x313d74[_0xf850('0x36')]=qs[_0xf850('0x37')](_0x310fd4['query']['sort']);_0x313d74[_0xf850('0x38')]=qs[_0xf850('0x2f')](_['pick'](_0x310fd4[_0xf850('0x2e')],_0x21ab43['filters']),_0x37faad);if(_0x310fd4['query'][_0xf850('0x39')]){_0x313d74[_0xf850('0x38')]=_[_0xf850('0x3a')](_0x313d74[_0xf850('0x38')],{'$or':_[_0xf850('0x28')](_0x37faad,function(_0xbbf648){if(_0xbbf648[_0xf850('0x2c')]!==_0xf850('0x3b')){var _0xa9ed47={};_0xa9ed47[_0xbbf648[_0xf850('0x25')]]={'$like':'%'+_0x310fd4[_0xf850('0x2e')][_0xf850('0x39')]+'%'};return _0xa9ed47;}})});}_0x313d74=_[_0xf850('0x3a')]({},_0x313d74,_0x310fd4['options']);var _0x115caf={'where':_0x313d74[_0xf850('0x38')]};return db['SmsTransferReport']['count'](_0x115caf)[_0xf850('0x22')](function(_0x94e2d5){_0x565c5d[_0xf850('0x1c')]=_0x94e2d5;if(_0x310fd4['query'][_0xf850('0x3c')]){_0x313d74[_0xf850('0x3d')]=[{'all':!![]}];}return db[_0xf850('0x29')][_0xf850('0x3e')](_0x313d74);})['then'](function(_0x3e0d88){_0x565c5d[_0xf850('0x3f')]=_0x3e0d88;return _0x565c5d;})[_0xf850('0x22')](respondWithFilteredResult(_0x47e7d9,_0x313d74))[_0xf850('0x40')](handleError(_0x47e7d9,null));};exports[_0xf850('0x41')]=function(_0x23f217,_0x25c9f1){var _0x2e76d2={'raw':!![],'where':{'id':_0x23f217[_0xf850('0x42')]['id']}},_0x51d10b={};_0x51d10b[_0xf850('0x31')]=_[_0xf850('0x43')](db[_0xf850('0x29')]['rawAttributes']);_0x51d10b[_0xf850('0x2e')]=_[_0xf850('0x43')](_0x23f217[_0xf850('0x2e')]);_0x51d10b[_0xf850('0x2f')]=_[_0xf850('0x30')](_0x51d10b[_0xf850('0x31')],_0x51d10b[_0xf850('0x2e')]);_0x2e76d2[_0xf850('0x33')]=_[_0xf850('0x30')](_0x51d10b[_0xf850('0x31')],qs[_0xf850('0x32')](_0x23f217[_0xf850('0x2e')]['fields']));_0x2e76d2[_0xf850('0x33')]=_0x2e76d2[_0xf850('0x33')][_0xf850('0x34')]?_0x2e76d2[_0xf850('0x33')]:_0x51d10b['model'];if(_0x23f217[_0xf850('0x2e')][_0xf850('0x3c')]){_0x2e76d2[_0xf850('0x3d')]=[{'all':!![]}];}_0x2e76d2=_[_0xf850('0x3a')]({},_0x2e76d2,_0x23f217[_0xf850('0x44')]);return db['SmsTransferReport'][_0xf850('0x45')](_0x2e76d2)['then'](handleEntityNotFound(_0x25c9f1,null))[_0xf850('0x22')](respondWithResult(_0x25c9f1,null))[_0xf850('0x40')](handleError(_0x25c9f1,null));};exports['create']=function(_0xfd72cc,_0x276d50){return db[_0xf850('0x29')][_0xf850('0x46')](_0xfd72cc[_0xf850('0x47')],{})[_0xf850('0x22')](respondWithResult(_0x276d50,0xc9))[_0xf850('0x40')](handleError(_0x276d50,null));};exports[_0xf850('0x48')]=function(_0x400b87,_0x4d7721){if(_0x400b87[_0xf850('0x47')]['id']){delete _0x400b87['body']['id'];}return db['SmsTransferReport'][_0xf850('0x45')]({'where':{'id':_0x400b87[_0xf850('0x42')]['id']}})[_0xf850('0x22')](handleEntityNotFound(_0x4d7721,null))['then'](saveUpdates(_0x400b87['body'],null))[_0xf850('0x22')](respondWithResult(_0x4d7721,null))[_0xf850('0x40')](handleError(_0x4d7721,null));};exports['destroy']=function(_0x3876a0,_0xbf345){return db['SmsTransferReport'][_0xf850('0x45')]({'where':{'id':_0x3876a0[_0xf850('0x42')]['id']}})[_0xf850('0x22')](handleEntityNotFound(_0xbf345,null))['then'](removeEntity(_0xbf345,null))[_0xf850('0x40')](handleError(_0xbf345,null));};exports['describe']=function(_0x5d73ad,_0x3e2c3f){return db[_0xf850('0x29')][_0xf850('0x49')]()[_0xf850('0x22')](respondWithResult(_0x3e2c3f,null))['catch'](handleError(_0x3e2c3f,null));};