10776ec70af9f75b8bf430462b94849ac59d91f3
[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 _0xab70=['keys','intersection','length','find','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','path','sox','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','ioredis','../../components/auth/service','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','save','update','then','end','error','name','send','index','SmsQueueReport','rawAttributes','type','model','query','filters','attributes','fields','hasOwnProperty','nolimit','order','sort','filter','where','merge','map','options','includeAll','include','findAll','rows','catch','show'];(function(_0x23c7c3,_0x5b5f85){var _0x5bce35=function(_0x57930a){while(--_0x57930a){_0x23c7c3['push'](_0x23c7c3['shift']());}};_0x5bce35(++_0x5b5f85);}(_0xab70,0x96));var _0x0ab7=function(_0x5d6c89,_0x5307d7){_0x5d6c89=_0x5d6c89-0x0;var _0x5c19bf=_0xab70[_0x5d6c89];return _0x5c19bf;};'use strict';var emlformat=require(_0x0ab7('0x0'));var rimraf=require(_0x0ab7('0x1'));var zipdir=require(_0x0ab7('0x2'));var jsonpatch=require(_0x0ab7('0x3'));var rp=require(_0x0ab7('0x4'));var moment=require('moment');var BPromise=require(_0x0ab7('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x0ab7('0x6'));var sox=require(_0x0ab7('0x7'));var csv=require('to-csv');var ejs=require(_0x0ab7('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x0ab7('0x9'));var squel=require(_0x0ab7('0xa'));var crypto=require(_0x0ab7('0xb'));var jsforce=require(_0x0ab7('0xc'));var deskjs=require(_0x0ab7('0xd'));var toCsv=require(_0x0ab7('0xe'));var querystring=require(_0x0ab7('0xf'));var Papa=require('papaparse');var Redis=require(_0x0ab7('0x10'));var authService=require(_0x0ab7('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x0ab7('0x12'));var utils=require(_0x0ab7('0x13'));var config=require('../../config/environment');var licenseUtil=require(_0x0ab7('0x14'));var db=require(_0x0ab7('0x15'))['db'];function respondWithStatusCode(_0x4e9f4f,_0x18f6fe){_0x18f6fe=_0x18f6fe||0xcc;return function(_0x56352b){if(_0x56352b){return _0x4e9f4f[_0x0ab7('0x16')](_0x18f6fe);}return _0x4e9f4f[_0x0ab7('0x17')](_0x18f6fe)['end']();};}function respondWithResult(_0x2cdb2b,_0x16961a){_0x16961a=_0x16961a||0xc8;return function(_0x238236){if(_0x238236){return _0x2cdb2b[_0x0ab7('0x17')](_0x16961a)[_0x0ab7('0x18')](_0x238236);}};}function respondWithFilteredResult(_0x2accaf,_0x5d35d1){return function(_0xffbe9f){if(_0xffbe9f){var _0x503b0c=typeof _0x5d35d1[_0x0ab7('0x19')]===_0x0ab7('0x1a')&&typeof _0x5d35d1[_0x0ab7('0x1b')]===_0x0ab7('0x1a');var _0x268d3d=_0xffbe9f[_0x0ab7('0x1c')];var _0x31edf0=_0x503b0c?0x0:_0x5d35d1[_0x0ab7('0x19')];var _0x479aa9=_0x503b0c?_0xffbe9f[_0x0ab7('0x1c')]:_0x5d35d1[_0x0ab7('0x19')]+_0x5d35d1['limit'];var _0xda2268;if(_0x479aa9>=_0x268d3d){_0x479aa9=_0x268d3d;_0xda2268=0xc8;}else{_0xda2268=0xce;}_0x2accaf[_0x0ab7('0x17')](_0xda2268);return _0x2accaf[_0x0ab7('0x1d')](_0x0ab7('0x1e'),_0x31edf0+'-'+_0x479aa9+'/'+_0x268d3d)[_0x0ab7('0x18')](_0xffbe9f);}return null;};}function patchUpdates(_0x492245){return function(_0x1a1f4d){try{jsonpatch[_0x0ab7('0x1f')](_0x1a1f4d,_0x492245,!![]);}catch(_0x3c444c){return BPromise['reject'](_0x3c444c);}return _0x1a1f4d[_0x0ab7('0x20')]();};}function saveUpdates(_0x491edb,_0x5b800a){return function(_0x25680b){if(_0x25680b){return _0x25680b[_0x0ab7('0x21')](_0x491edb)[_0x0ab7('0x22')](function(_0x40072e){return _0x40072e;});}return null;};}function removeEntity(_0x4a2aa0,_0x315e2e){return function(_0x29ca2f){if(_0x29ca2f){return _0x29ca2f['destroy']()[_0x0ab7('0x22')](function(){_0x4a2aa0[_0x0ab7('0x17')](0xcc)[_0x0ab7('0x23')]();});}};}function handleEntityNotFound(_0x3081f1,_0x4c3eab){return function(_0x274763){if(!_0x274763){_0x3081f1[_0x0ab7('0x16')](0x194);}return _0x274763;};}function handleError(_0x14fa0a,_0x731ab2){_0x731ab2=_0x731ab2||0x1f4;return function(_0x10e801){logger[_0x0ab7('0x24')](_0x10e801['stack']);if(_0x10e801[_0x0ab7('0x25')]){delete _0x10e801['name'];}_0x14fa0a[_0x0ab7('0x17')](_0x731ab2)[_0x0ab7('0x26')](_0x10e801);};}exports[_0x0ab7('0x27')]=function(_0x31b29c,_0x3687b4){var _0x13747d={},_0x35f0ec={},_0x2c27a6={'count':0x0,'rows':[]};var _0x362cb3=_['map'](db[_0x0ab7('0x28')][_0x0ab7('0x29')],function(_0x5ce220){return{'name':_0x5ce220['fieldName'],'type':_0x5ce220[_0x0ab7('0x2a')]['key']};});_0x35f0ec[_0x0ab7('0x2b')]=_['map'](_0x362cb3,_0x0ab7('0x25'));_0x35f0ec[_0x0ab7('0x2c')]=_['keys'](_0x31b29c[_0x0ab7('0x2c')]);_0x35f0ec[_0x0ab7('0x2d')]=_['intersection'](_0x35f0ec[_0x0ab7('0x2b')],_0x35f0ec[_0x0ab7('0x2c')]);_0x13747d[_0x0ab7('0x2e')]=_['intersection'](_0x35f0ec[_0x0ab7('0x2b')],qs[_0x0ab7('0x2f')](_0x31b29c[_0x0ab7('0x2c')]['fields']));_0x13747d['attributes']=_0x13747d[_0x0ab7('0x2e')]['length']?_0x13747d[_0x0ab7('0x2e')]:_0x35f0ec['model'];if(!_0x31b29c['query'][_0x0ab7('0x30')](_0x0ab7('0x31'))){_0x13747d['limit']=qs[_0x0ab7('0x1b')](_0x31b29c[_0x0ab7('0x2c')][_0x0ab7('0x1b')]);_0x13747d[_0x0ab7('0x19')]=qs[_0x0ab7('0x19')](_0x31b29c[_0x0ab7('0x2c')][_0x0ab7('0x19')]);}_0x13747d[_0x0ab7('0x32')]=qs[_0x0ab7('0x33')](_0x31b29c[_0x0ab7('0x2c')][_0x0ab7('0x33')]);_0x13747d['where']=qs[_0x0ab7('0x2d')](_['pick'](_0x31b29c[_0x0ab7('0x2c')],_0x35f0ec['filters']),_0x362cb3);if(_0x31b29c['query'][_0x0ab7('0x34')]){_0x13747d[_0x0ab7('0x35')]=_[_0x0ab7('0x36')](_0x13747d[_0x0ab7('0x35')],{'$or':_[_0x0ab7('0x37')](_0x362cb3,function(_0x54c06b){if(_0x54c06b[_0x0ab7('0x2a')]!=='VIRTUAL'){var _0x363124={};_0x363124[_0x54c06b['name']]={'$like':'%'+_0x31b29c[_0x0ab7('0x2c')][_0x0ab7('0x34')]+'%'};return _0x363124;}})});}_0x13747d=_[_0x0ab7('0x36')]({},_0x13747d,_0x31b29c[_0x0ab7('0x38')]);var _0x5daf3f={'where':_0x13747d[_0x0ab7('0x35')]};return db[_0x0ab7('0x28')][_0x0ab7('0x1c')](_0x5daf3f)[_0x0ab7('0x22')](function(_0x3c3eaa){_0x2c27a6[_0x0ab7('0x1c')]=_0x3c3eaa;if(_0x31b29c[_0x0ab7('0x2c')][_0x0ab7('0x39')]){_0x13747d[_0x0ab7('0x3a')]=[{'all':!![]}];}return db['SmsQueueReport'][_0x0ab7('0x3b')](_0x13747d);})[_0x0ab7('0x22')](function(_0x5e3a11){_0x2c27a6[_0x0ab7('0x3c')]=_0x5e3a11;return _0x2c27a6;})[_0x0ab7('0x22')](respondWithFilteredResult(_0x3687b4,_0x13747d))[_0x0ab7('0x3d')](handleError(_0x3687b4,null));};exports[_0x0ab7('0x3e')]=function(_0xf1e058,_0x5b61b8){var _0x4d4cf5={'raw':!![],'where':{'id':_0xf1e058['params']['id']}},_0x49daea={};_0x49daea[_0x0ab7('0x2b')]=_[_0x0ab7('0x3f')](db[_0x0ab7('0x28')][_0x0ab7('0x29')]);_0x49daea[_0x0ab7('0x2c')]=_[_0x0ab7('0x3f')](_0xf1e058['query']);_0x49daea[_0x0ab7('0x2d')]=_[_0x0ab7('0x40')](_0x49daea[_0x0ab7('0x2b')],_0x49daea[_0x0ab7('0x2c')]);_0x4d4cf5[_0x0ab7('0x2e')]=_['intersection'](_0x49daea['model'],qs['fields'](_0xf1e058[_0x0ab7('0x2c')][_0x0ab7('0x2f')]));_0x4d4cf5[_0x0ab7('0x2e')]=_0x4d4cf5[_0x0ab7('0x2e')][_0x0ab7('0x41')]?_0x4d4cf5['attributes']:_0x49daea[_0x0ab7('0x2b')];if(_0xf1e058['query']['includeAll']){_0x4d4cf5[_0x0ab7('0x3a')]=[{'all':!![]}];}_0x4d4cf5=_[_0x0ab7('0x36')]({},_0x4d4cf5,_0xf1e058[_0x0ab7('0x38')]);return db[_0x0ab7('0x28')][_0x0ab7('0x42')](_0x4d4cf5)[_0x0ab7('0x22')](handleEntityNotFound(_0x5b61b8,null))[_0x0ab7('0x22')](respondWithResult(_0x5b61b8,null))[_0x0ab7('0x3d')](handleError(_0x5b61b8,null));};exports['create']=function(_0x378139,_0x411f45){return db[_0x0ab7('0x28')][_0x0ab7('0x43')](_0x378139[_0x0ab7('0x44')],{})[_0x0ab7('0x22')](respondWithResult(_0x411f45,0xc9))[_0x0ab7('0x3d')](handleError(_0x411f45,null));};exports[_0x0ab7('0x21')]=function(_0x5650db,_0x313b1d){if(_0x5650db['body']['id']){delete _0x5650db[_0x0ab7('0x44')]['id'];}return db[_0x0ab7('0x28')]['find']({'where':{'id':_0x5650db[_0x0ab7('0x45')]['id']}})['then'](handleEntityNotFound(_0x313b1d,null))[_0x0ab7('0x22')](saveUpdates(_0x5650db[_0x0ab7('0x44')],null))[_0x0ab7('0x22')](respondWithResult(_0x313b1d,null))[_0x0ab7('0x3d')](handleError(_0x313b1d,null));};exports['destroy']=function(_0x38315b,_0x327221){return db[_0x0ab7('0x28')][_0x0ab7('0x42')]({'where':{'id':_0x38315b[_0x0ab7('0x45')]['id']}})[_0x0ab7('0x22')](handleEntityNotFound(_0x327221,null))[_0x0ab7('0x22')](removeEntity(_0x327221,null))[_0x0ab7('0x3d')](handleError(_0x327221,null));};exports[_0x0ab7('0x46')]=function(_0x582a55,_0x12b4ea){return db['SmsQueueReport'][_0x0ab7('0x46')]()[_0x0ab7('0x22')](respondWithResult(_0x12b4ea,null))['catch'](handleError(_0x12b4ea,null));};