Built motion from commit (unavailable).|2.5.30
[motion2.git] / server / api / smsQueueReport / smsQueueReport.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 _0x19fa=['sort','where','pick','filter','VIRTUAL','merge','options','SmsQueueReport','then','includeAll','findAll','show','params','rawAttributes','length','include','find','catch','create','body','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','path','sox','to-csv','ejs','fs-extra','lodash','jsforce','desk.js','querystring','papaparse','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','status','end','json','offset','limit','count','Content-Range','apply','reject','save','update','destroy','sendStatus','error','stack','name','send','index','map','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','order'];(function(_0x29b609,_0x19d388){var _0x54c952=function(_0xb3c38d){while(--_0xb3c38d){_0x29b609['push'](_0x29b609['shift']());}};_0x54c952(++_0x19d388);}(_0x19fa,0xa9));var _0xa19f=function(_0x21f588,_0x46468d){_0x21f588=_0x21f588-0x0;var _0x3fbee2=_0x19fa[_0x21f588];return _0x3fbee2;};'use strict';var emlformat=require(_0xa19f('0x0'));var rimraf=require(_0xa19f('0x1'));var zipdir=require(_0xa19f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xa19f('0x3'));var moment=require(_0xa19f('0x4'));var BPromise=require(_0xa19f('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0xa19f('0x6'));var sox=require(_0xa19f('0x7'));var csv=require(_0xa19f('0x8'));var ejs=require(_0xa19f('0x9'));var fs=require('fs');var fs_extra=require(_0xa19f('0xa'));var _=require(_0xa19f('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xa19f('0xc'));var deskjs=require(_0xa19f('0xd'));var toCsv=require(_0xa19f('0x8'));var querystring=require(_0xa19f('0xe'));var Papa=require(_0xa19f('0xf'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0xa19f('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xa19f('0x11'));var logger=require('../../config/logger')(_0xa19f('0x12'));var utils=require(_0xa19f('0x13'));var config=require(_0xa19f('0x14'));var licenseUtil=require('../../config/license/util');var db=require(_0xa19f('0x15'))['db'];function respondWithStatusCode(_0x3d54f4,_0x282f53){_0x282f53=_0x282f53||0xcc;return function(_0x16f44e){if(_0x16f44e){return _0x3d54f4['sendStatus'](_0x282f53);}return _0x3d54f4[_0xa19f('0x16')](_0x282f53)[_0xa19f('0x17')]();};}function respondWithResult(_0xb38ca9,_0x9746b8){_0x9746b8=_0x9746b8||0xc8;return function(_0x5b2107){if(_0x5b2107){return _0xb38ca9[_0xa19f('0x16')](_0x9746b8)[_0xa19f('0x18')](_0x5b2107);}};}function respondWithFilteredResult(_0x41cf67,_0x436bff){return function(_0x1bd8c1){if(_0x1bd8c1){var _0x5b8f89=typeof _0x436bff[_0xa19f('0x19')]==='undefined'&&typeof _0x436bff[_0xa19f('0x1a')]==='undefined';var _0x5a8b26=_0x1bd8c1[_0xa19f('0x1b')];var _0x3c1237=_0x5b8f89?0x0:_0x436bff['offset'];var _0x346f4f=_0x5b8f89?_0x1bd8c1[_0xa19f('0x1b')]:_0x436bff['offset']+_0x436bff['limit'];var _0x1b8043;if(_0x346f4f>=_0x5a8b26){_0x346f4f=_0x5a8b26;_0x1b8043=0xc8;}else{_0x1b8043=0xce;}_0x41cf67[_0xa19f('0x16')](_0x1b8043);return _0x41cf67['set'](_0xa19f('0x1c'),_0x3c1237+'-'+_0x346f4f+'/'+_0x5a8b26)['json'](_0x1bd8c1);}return null;};}function patchUpdates(_0x1a4616){return function(_0x4e9518){try{jsonpatch[_0xa19f('0x1d')](_0x4e9518,_0x1a4616,!![]);}catch(_0xd8bbc8){return BPromise[_0xa19f('0x1e')](_0xd8bbc8);}return _0x4e9518[_0xa19f('0x1f')]();};}function saveUpdates(_0x1e71b2,_0x2682fa){return function(_0x449a52){if(_0x449a52){return _0x449a52[_0xa19f('0x20')](_0x1e71b2)['then'](function(_0x16062a){return _0x16062a;});}return null;};}function removeEntity(_0x107603,_0x15e86c){return function(_0x8e2610){if(_0x8e2610){return _0x8e2610[_0xa19f('0x21')]()['then'](function(){_0x107603[_0xa19f('0x16')](0xcc)[_0xa19f('0x17')]();});}};}function handleEntityNotFound(_0x2abd4e,_0x42483a){return function(_0x463564){if(!_0x463564){_0x2abd4e[_0xa19f('0x22')](0x194);}return _0x463564;};}function handleError(_0x48a395,_0x4b8165){_0x4b8165=_0x4b8165||0x1f4;return function(_0x3df8c5){logger[_0xa19f('0x23')](_0x3df8c5[_0xa19f('0x24')]);if(_0x3df8c5[_0xa19f('0x25')]){delete _0x3df8c5[_0xa19f('0x25')];}_0x48a395['status'](_0x4b8165)[_0xa19f('0x26')](_0x3df8c5);};}exports[_0xa19f('0x27')]=function(_0x20e9c4,_0x4fa03f){var _0x126cd2={},_0x10c7dd={},_0x2152e4={'count':0x0,'rows':[]};var _0x2e1bd1=_[_0xa19f('0x28')](db['SmsQueueReport']['rawAttributes'],function(_0x137107){return{'name':_0x137107[_0xa19f('0x29')],'type':_0x137107[_0xa19f('0x2a')][_0xa19f('0x2b')]};});_0x10c7dd[_0xa19f('0x2c')]=_[_0xa19f('0x28')](_0x2e1bd1,'name');_0x10c7dd[_0xa19f('0x2d')]=_[_0xa19f('0x2e')](_0x20e9c4[_0xa19f('0x2d')]);_0x10c7dd[_0xa19f('0x2f')]=_[_0xa19f('0x30')](_0x10c7dd[_0xa19f('0x2c')],_0x10c7dd['query']);_0x126cd2[_0xa19f('0x31')]=_['intersection'](_0x10c7dd[_0xa19f('0x2c')],qs[_0xa19f('0x32')](_0x20e9c4[_0xa19f('0x2d')][_0xa19f('0x32')]));_0x126cd2[_0xa19f('0x31')]=_0x126cd2['attributes']['length']?_0x126cd2[_0xa19f('0x31')]:_0x10c7dd[_0xa19f('0x2c')];if(!_0x20e9c4['query']['hasOwnProperty'](_0xa19f('0x33'))){_0x126cd2[_0xa19f('0x1a')]=qs[_0xa19f('0x1a')](_0x20e9c4['query'][_0xa19f('0x1a')]);_0x126cd2[_0xa19f('0x19')]=qs[_0xa19f('0x19')](_0x20e9c4[_0xa19f('0x2d')]['offset']);}_0x126cd2[_0xa19f('0x34')]=qs[_0xa19f('0x35')](_0x20e9c4['query'][_0xa19f('0x35')]);_0x126cd2[_0xa19f('0x36')]=qs[_0xa19f('0x2f')](_[_0xa19f('0x37')](_0x20e9c4[_0xa19f('0x2d')],_0x10c7dd[_0xa19f('0x2f')]),_0x2e1bd1);if(_0x20e9c4['query'][_0xa19f('0x38')]){_0x126cd2[_0xa19f('0x36')]=_['merge'](_0x126cd2[_0xa19f('0x36')],{'$or':_[_0xa19f('0x28')](_0x2e1bd1,function(_0x1ff75f){if(_0x1ff75f[_0xa19f('0x2a')]!==_0xa19f('0x39')){var _0x286ebb={};_0x286ebb[_0x1ff75f[_0xa19f('0x25')]]={'$like':'%'+_0x20e9c4[_0xa19f('0x2d')][_0xa19f('0x38')]+'%'};return _0x286ebb;}})});}_0x126cd2=_[_0xa19f('0x3a')]({},_0x126cd2,_0x20e9c4[_0xa19f('0x3b')]);var _0x2aa3d2={'where':_0x126cd2[_0xa19f('0x36')]};return db[_0xa19f('0x3c')][_0xa19f('0x1b')](_0x2aa3d2)[_0xa19f('0x3d')](function(_0x4a7a53){_0x2152e4[_0xa19f('0x1b')]=_0x4a7a53;if(_0x20e9c4[_0xa19f('0x2d')][_0xa19f('0x3e')]){_0x126cd2['include']=[{'all':!![]}];}return db[_0xa19f('0x3c')][_0xa19f('0x3f')](_0x126cd2);})[_0xa19f('0x3d')](function(_0x43fe4c){_0x2152e4['rows']=_0x43fe4c;return _0x2152e4;})[_0xa19f('0x3d')](respondWithFilteredResult(_0x4fa03f,_0x126cd2))['catch'](handleError(_0x4fa03f,null));};exports[_0xa19f('0x40')]=function(_0x3495d8,_0x1bc8fa){var _0x408d00={'raw':!![],'where':{'id':_0x3495d8[_0xa19f('0x41')]['id']}},_0xc43b41={};_0xc43b41[_0xa19f('0x2c')]=_[_0xa19f('0x2e')](db[_0xa19f('0x3c')][_0xa19f('0x42')]);_0xc43b41[_0xa19f('0x2d')]=_[_0xa19f('0x2e')](_0x3495d8[_0xa19f('0x2d')]);_0xc43b41['filters']=_['intersection'](_0xc43b41[_0xa19f('0x2c')],_0xc43b41['query']);_0x408d00[_0xa19f('0x31')]=_['intersection'](_0xc43b41[_0xa19f('0x2c')],qs[_0xa19f('0x32')](_0x3495d8[_0xa19f('0x2d')][_0xa19f('0x32')]));_0x408d00[_0xa19f('0x31')]=_0x408d00[_0xa19f('0x31')][_0xa19f('0x43')]?_0x408d00[_0xa19f('0x31')]:_0xc43b41[_0xa19f('0x2c')];if(_0x3495d8['query'][_0xa19f('0x3e')]){_0x408d00[_0xa19f('0x44')]=[{'all':!![]}];}_0x408d00=_[_0xa19f('0x3a')]({},_0x408d00,_0x3495d8[_0xa19f('0x3b')]);return db[_0xa19f('0x3c')][_0xa19f('0x45')](_0x408d00)[_0xa19f('0x3d')](handleEntityNotFound(_0x1bc8fa,null))[_0xa19f('0x3d')](respondWithResult(_0x1bc8fa,null))[_0xa19f('0x46')](handleError(_0x1bc8fa,null));};exports[_0xa19f('0x47')]=function(_0x5387ec,_0x30f667){return db['SmsQueueReport'][_0xa19f('0x47')](_0x5387ec[_0xa19f('0x48')],{})['then'](respondWithResult(_0x30f667,0xc9))[_0xa19f('0x46')](handleError(_0x30f667,null));};exports['update']=function(_0x52f44c,_0x167d2b){if(_0x52f44c[_0xa19f('0x48')]['id']){delete _0x52f44c[_0xa19f('0x48')]['id'];}return db[_0xa19f('0x3c')][_0xa19f('0x45')]({'where':{'id':_0x52f44c[_0xa19f('0x41')]['id']}})[_0xa19f('0x3d')](handleEntityNotFound(_0x167d2b,null))[_0xa19f('0x3d')](saveUpdates(_0x52f44c['body'],null))[_0xa19f('0x3d')](respondWithResult(_0x167d2b,null))[_0xa19f('0x46')](handleError(_0x167d2b,null));};exports[_0xa19f('0x21')]=function(_0x4b077e,_0x44f3da){return db['SmsQueueReport'][_0xa19f('0x45')]({'where':{'id':_0x4b077e['params']['id']}})[_0xa19f('0x3d')](handleEntityNotFound(_0x44f3da,null))[_0xa19f('0x3d')](removeEntity(_0x44f3da,null))[_0xa19f('0x46')](handleError(_0x44f3da,null));};exports[_0xa19f('0x49')]=function(_0x2380bd,_0x12fc4f){return db['SmsQueueReport'][_0xa19f('0x49')]()[_0xa19f('0x3d')](respondWithResult(_0x12fc4f,null))[_0xa19f('0x46')](handleError(_0x12fc4f,null));};