Built motion from commit c738b9ac.|2.6.25
[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 _0x5c8a=['ioredis','../../components/auth/service','../../config/logger','api','../../config/utils','end','json','offset','limit','undefined','count','status','set','Content-Range','apply','reject','save','then','destroy','sendStatus','error','name','send','index','map','rawAttributes','fieldName','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','SmsTransferReport','includeAll','include','rows','catch','show','keys','options','find','create','body','params','describe','eml-format','rimraf','zip-dir','moment','bluebird','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','papaparse'];(function(_0x53fa4d,_0x350337){var _0x2e3387=function(_0x3c4b20){while(--_0x3c4b20){_0x53fa4d['push'](_0x53fa4d['shift']());}};_0x2e3387(++_0x350337);}(_0x5c8a,0x19a));var _0xa5c8=function(_0x5f2f11,_0x166b2d){_0x5f2f11=_0x5f2f11-0x0;var _0x2e448a=_0x5c8a[_0x5f2f11];return _0x2e448a;};'use strict';var emlformat=require(_0xa5c8('0x0'));var rimraf=require(_0xa5c8('0x1'));var zipdir=require(_0xa5c8('0x2'));var jsonpatch=require('fast-json-patch');var rp=require('request-promise');var moment=require(_0xa5c8('0x3'));var BPromise=require(_0xa5c8('0x4'));var Mustache=require(_0xa5c8('0x5'));var util=require(_0xa5c8('0x6'));var path=require(_0xa5c8('0x7'));var sox=require(_0xa5c8('0x8'));var csv=require(_0xa5c8('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xa5c8('0xa'));var squel=require(_0xa5c8('0xb'));var crypto=require(_0xa5c8('0xc'));var jsforce=require(_0xa5c8('0xd'));var deskjs=require(_0xa5c8('0xe'));var toCsv=require(_0xa5c8('0x9'));var querystring=require('querystring');var Papa=require(_0xa5c8('0xf'));var Redis=require(_0xa5c8('0x10'));var authService=require(_0xa5c8('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xa5c8('0x12'))(_0xa5c8('0x13'));var utils=require(_0xa5c8('0x14'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x479189,_0xe968ae){_0xe968ae=_0xe968ae||0xcc;return function(_0x4a7983){if(_0x4a7983){return _0x479189['sendStatus'](_0xe968ae);}return _0x479189['status'](_0xe968ae)[_0xa5c8('0x15')]();};}function respondWithResult(_0x2f1b8,_0x4cb72c){_0x4cb72c=_0x4cb72c||0xc8;return function(_0x488f74){if(_0x488f74){return _0x2f1b8['status'](_0x4cb72c)[_0xa5c8('0x16')](_0x488f74);}};}function respondWithFilteredResult(_0x48c444,_0x27e7d3){return function(_0x51ef71){if(_0x51ef71){var _0x5a539f=typeof _0x27e7d3[_0xa5c8('0x17')]==='undefined'&&typeof _0x27e7d3[_0xa5c8('0x18')]===_0xa5c8('0x19');var _0x58e6b0=_0x51ef71[_0xa5c8('0x1a')];var _0x1b4a39=_0x5a539f?0x0:_0x27e7d3[_0xa5c8('0x17')];var _0x2a032a=_0x5a539f?_0x51ef71[_0xa5c8('0x1a')]:_0x27e7d3[_0xa5c8('0x17')]+_0x27e7d3[_0xa5c8('0x18')];var _0x561545;if(_0x2a032a>=_0x58e6b0){_0x2a032a=_0x58e6b0;_0x561545=0xc8;}else{_0x561545=0xce;}_0x48c444[_0xa5c8('0x1b')](_0x561545);return _0x48c444[_0xa5c8('0x1c')](_0xa5c8('0x1d'),_0x1b4a39+'-'+_0x2a032a+'/'+_0x58e6b0)['json'](_0x51ef71);}return null;};}function patchUpdates(_0x2c6345){return function(_0x289092){try{jsonpatch[_0xa5c8('0x1e')](_0x289092,_0x2c6345,!![]);}catch(_0x358c83){return BPromise[_0xa5c8('0x1f')](_0x358c83);}return _0x289092[_0xa5c8('0x20')]();};}function saveUpdates(_0x55f2b5,_0x15f566){return function(_0x3e7224){if(_0x3e7224){return _0x3e7224['update'](_0x55f2b5)[_0xa5c8('0x21')](function(_0x4b0788){return _0x4b0788;});}return null;};}function removeEntity(_0x34d0ac,_0x184201){return function(_0x374413){if(_0x374413){return _0x374413[_0xa5c8('0x22')]()[_0xa5c8('0x21')](function(){_0x34d0ac[_0xa5c8('0x1b')](0xcc)[_0xa5c8('0x15')]();});}};}function handleEntityNotFound(_0x1dcc2b,_0x1d040f){return function(_0x4eb0c4){if(!_0x4eb0c4){_0x1dcc2b[_0xa5c8('0x23')](0x194);}return _0x4eb0c4;};}function handleError(_0x13010c,_0x13d12b){_0x13d12b=_0x13d12b||0x1f4;return function(_0x1ef64e){logger[_0xa5c8('0x24')](_0x1ef64e['stack']);if(_0x1ef64e[_0xa5c8('0x25')]){delete _0x1ef64e['name'];}_0x13010c[_0xa5c8('0x1b')](_0x13d12b)[_0xa5c8('0x26')](_0x1ef64e);};}exports[_0xa5c8('0x27')]=function(_0x1dbeb4,_0xaaf30b){var _0x532e2e={},_0x432444={},_0x24e691={'count':0x0,'rows':[]};var _0x4cb36c=_[_0xa5c8('0x28')](db['SmsTransferReport'][_0xa5c8('0x29')],function(_0x5583b7){return{'name':_0x5583b7[_0xa5c8('0x2a')],'type':_0x5583b7[_0xa5c8('0x2b')]['key']};});_0x432444[_0xa5c8('0x2c')]=_[_0xa5c8('0x28')](_0x4cb36c,'name');_0x432444[_0xa5c8('0x2d')]=_['keys'](_0x1dbeb4[_0xa5c8('0x2d')]);_0x432444[_0xa5c8('0x2e')]=_[_0xa5c8('0x2f')](_0x432444[_0xa5c8('0x2c')],_0x432444['query']);_0x532e2e[_0xa5c8('0x30')]=_['intersection'](_0x432444[_0xa5c8('0x2c')],qs[_0xa5c8('0x31')](_0x1dbeb4['query'][_0xa5c8('0x31')]));_0x532e2e[_0xa5c8('0x30')]=_0x532e2e[_0xa5c8('0x30')][_0xa5c8('0x32')]?_0x532e2e[_0xa5c8('0x30')]:_0x432444[_0xa5c8('0x2c')];if(!_0x1dbeb4[_0xa5c8('0x2d')][_0xa5c8('0x33')]('nolimit')){_0x532e2e[_0xa5c8('0x18')]=qs['limit'](_0x1dbeb4[_0xa5c8('0x2d')][_0xa5c8('0x18')]);_0x532e2e[_0xa5c8('0x17')]=qs[_0xa5c8('0x17')](_0x1dbeb4[_0xa5c8('0x2d')][_0xa5c8('0x17')]);}_0x532e2e[_0xa5c8('0x34')]=qs[_0xa5c8('0x35')](_0x1dbeb4['query'][_0xa5c8('0x35')]);_0x532e2e[_0xa5c8('0x36')]=qs[_0xa5c8('0x2e')](_[_0xa5c8('0x37')](_0x1dbeb4[_0xa5c8('0x2d')],_0x432444['filters']),_0x4cb36c);if(_0x1dbeb4['query']['filter']){_0x532e2e['where']=_[_0xa5c8('0x38')](_0x532e2e[_0xa5c8('0x36')],{'$or':_[_0xa5c8('0x28')](_0x4cb36c,function(_0x366039){if(_0x366039['type']!==_0xa5c8('0x39')){var _0x2e57dc={};_0x2e57dc[_0x366039[_0xa5c8('0x25')]]={'$like':'%'+_0x1dbeb4[_0xa5c8('0x2d')]['filter']+'%'};return _0x2e57dc;}})});}_0x532e2e=_[_0xa5c8('0x38')]({},_0x532e2e,_0x1dbeb4['options']);var _0x28e72f={'where':_0x532e2e[_0xa5c8('0x36')]};return db[_0xa5c8('0x3a')][_0xa5c8('0x1a')](_0x28e72f)[_0xa5c8('0x21')](function(_0x1d87ba){_0x24e691[_0xa5c8('0x1a')]=_0x1d87ba;if(_0x1dbeb4['query'][_0xa5c8('0x3b')]){_0x532e2e[_0xa5c8('0x3c')]=[{'all':!![]}];}return db[_0xa5c8('0x3a')]['findAll'](_0x532e2e);})['then'](function(_0x404bf9){_0x24e691[_0xa5c8('0x3d')]=_0x404bf9;return _0x24e691;})[_0xa5c8('0x21')](respondWithFilteredResult(_0xaaf30b,_0x532e2e))[_0xa5c8('0x3e')](handleError(_0xaaf30b,null));};exports[_0xa5c8('0x3f')]=function(_0x5965c3,_0x1597a9){var _0x587074={'raw':!![],'where':{'id':_0x5965c3['params']['id']}},_0x10ac26={};_0x10ac26[_0xa5c8('0x2c')]=_[_0xa5c8('0x40')](db['SmsTransferReport'][_0xa5c8('0x29')]);_0x10ac26['query']=_['keys'](_0x5965c3['query']);_0x10ac26['filters']=_[_0xa5c8('0x2f')](_0x10ac26['model'],_0x10ac26[_0xa5c8('0x2d')]);_0x587074['attributes']=_[_0xa5c8('0x2f')](_0x10ac26[_0xa5c8('0x2c')],qs['fields'](_0x5965c3[_0xa5c8('0x2d')][_0xa5c8('0x31')]));_0x587074[_0xa5c8('0x30')]=_0x587074[_0xa5c8('0x30')][_0xa5c8('0x32')]?_0x587074['attributes']:_0x10ac26[_0xa5c8('0x2c')];if(_0x5965c3['query'][_0xa5c8('0x3b')]){_0x587074['include']=[{'all':!![]}];}_0x587074=_[_0xa5c8('0x38')]({},_0x587074,_0x5965c3[_0xa5c8('0x41')]);return db[_0xa5c8('0x3a')][_0xa5c8('0x42')](_0x587074)['then'](handleEntityNotFound(_0x1597a9,null))[_0xa5c8('0x21')](respondWithResult(_0x1597a9,null))[_0xa5c8('0x3e')](handleError(_0x1597a9,null));};exports[_0xa5c8('0x43')]=function(_0x1644e8,_0x45e099){return db[_0xa5c8('0x3a')][_0xa5c8('0x43')](_0x1644e8[_0xa5c8('0x44')],{})['then'](respondWithResult(_0x45e099,0xc9))['catch'](handleError(_0x45e099,null));};exports['update']=function(_0x5d68ac,_0x52827e){if(_0x5d68ac['body']['id']){delete _0x5d68ac['body']['id'];}return db[_0xa5c8('0x3a')][_0xa5c8('0x42')]({'where':{'id':_0x5d68ac[_0xa5c8('0x45')]['id']}})[_0xa5c8('0x21')](handleEntityNotFound(_0x52827e,null))[_0xa5c8('0x21')](saveUpdates(_0x5d68ac[_0xa5c8('0x44')],null))[_0xa5c8('0x21')](respondWithResult(_0x52827e,null))['catch'](handleError(_0x52827e,null));};exports[_0xa5c8('0x22')]=function(_0x1ac429,_0x4d65e6){return db[_0xa5c8('0x3a')]['find']({'where':{'id':_0x1ac429[_0xa5c8('0x45')]['id']}})[_0xa5c8('0x21')](handleEntityNotFound(_0x4d65e6,null))[_0xa5c8('0x21')](removeEntity(_0x4d65e6,null))[_0xa5c8('0x3e')](handleError(_0x4d65e6,null));};exports['describe']=function(_0x8af3e8,_0x461d36){return db[_0xa5c8('0x3a')][_0xa5c8('0x46')]()['then'](respondWithResult(_0x461d36,null))[_0xa5c8('0x3e')](handleError(_0x461d36,null));};