c38bcca8f7c8bd1c78b56faef139e35a8be2f027
[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 _0xff32=['set','apply','reject','save','update','destroy','sendStatus','error','name','send','SmsQueueReport','rawAttributes','fieldName','type','model','map','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','then','includeAll','include','findAll','show','params','options','find','create','catch','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','ejs','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','status','end','json','count','offset','limit'];(function(_0x26abd0,_0x372a3b){var _0xfda85b=function(_0x404b1c){while(--_0x404b1c){_0x26abd0['push'](_0x26abd0['shift']());}};_0xfda85b(++_0x372a3b);}(_0xff32,0x156));var _0x2ff3=function(_0x5c03a4,_0x38d38e){_0x5c03a4=_0x5c03a4-0x0;var _0x1b5c9c=_0xff32[_0x5c03a4];return _0x1b5c9c;};'use strict';var pdf=require(_0x2ff3('0x0'));var emlformat=require(_0x2ff3('0x1'));var rimraf=require(_0x2ff3('0x2'));var zipdir=require(_0x2ff3('0x3'));var jsonpatch=require(_0x2ff3('0x4'));var rp=require(_0x2ff3('0x5'));var moment=require(_0x2ff3('0x6'));var BPromise=require(_0x2ff3('0x7'));var Mustache=require(_0x2ff3('0x8'));var util=require(_0x2ff3('0x9'));var path=require(_0x2ff3('0xa'));var sox=require('sox');var csv=require(_0x2ff3('0xb'));var ejs=require(_0x2ff3('0xc'));var fs=require('fs');var _=require('lodash');var squel=require(_0x2ff3('0xd'));var crypto=require(_0x2ff3('0xe'));var jsforce=require(_0x2ff3('0xf'));var deskjs=require(_0x2ff3('0x10'));var toCsv=require(_0x2ff3('0xb'));var querystring=require('querystring');var Papa=require(_0x2ff3('0x11'));var Redis=require(_0x2ff3('0x12'));var authService=require(_0x2ff3('0x13'));var qs=require(_0x2ff3('0x14'));var as=require(_0x2ff3('0x15'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x2ff3('0x16'))(_0x2ff3('0x17'));var utils=require('../../config/utils');var config=require(_0x2ff3('0x18'));var licenseUtil=require(_0x2ff3('0x19'));var db=require(_0x2ff3('0x1a'))['db'];function respondWithStatusCode(_0x1d288d,_0xff4eda){_0xff4eda=_0xff4eda||0xcc;return function(_0x5a89d1){if(_0x5a89d1){return _0x1d288d['sendStatus'](_0xff4eda);}return _0x1d288d[_0x2ff3('0x1b')](_0xff4eda)[_0x2ff3('0x1c')]();};}function respondWithResult(_0x3d6f3e,_0x719aad){_0x719aad=_0x719aad||0xc8;return function(_0x1d6334){if(_0x1d6334){return _0x3d6f3e[_0x2ff3('0x1b')](_0x719aad)[_0x2ff3('0x1d')](_0x1d6334);}};}function respondWithFilteredResult(_0x10a225,_0x558acb){return function(_0x290631){if(_0x290631){var _0x312014=_0x290631[_0x2ff3('0x1e')],_0x46ab8d=_0x558acb[_0x2ff3('0x1f')],_0x345abe=_0x558acb[_0x2ff3('0x1f')]+_0x558acb[_0x2ff3('0x20')],_0x1c8b17;if(_0x345abe>=_0x312014){_0x345abe=_0x312014;_0x1c8b17=0xc8;}else{_0x1c8b17=0xce;}_0x10a225[_0x2ff3('0x1b')](_0x1c8b17);return _0x10a225[_0x2ff3('0x21')]('Content-Range',_0x46ab8d+'-'+_0x345abe+'/'+_0x312014)[_0x2ff3('0x1d')](_0x290631);}return null;};}function patchUpdates(_0x848bdd){return function(_0x639dce){try{jsonpatch[_0x2ff3('0x22')](_0x639dce,_0x848bdd,!![]);}catch(_0x3c6df9){return BPromise[_0x2ff3('0x23')](_0x3c6df9);}return _0x639dce[_0x2ff3('0x24')]();};}function saveUpdates(_0x11b96d,_0x1fa0d8){return function(_0x224d94){if(_0x224d94){return _0x224d94[_0x2ff3('0x25')](_0x11b96d)['then'](function(_0x5aa07c){return _0x5aa07c;});}return null;};}function removeEntity(_0x3f34e6,_0x544f36){return function(_0x31e3d3){if(_0x31e3d3){return _0x31e3d3[_0x2ff3('0x26')]()['then'](function(){_0x3f34e6[_0x2ff3('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x4c9ee7,_0x52ffb1){return function(_0x992771){if(!_0x992771){_0x4c9ee7[_0x2ff3('0x27')](0x194);}return _0x992771;};}function handleError(_0x42d9f5,_0x2def4e){_0x2def4e=_0x2def4e||0x1f4;return function(_0x176bce){logger[_0x2ff3('0x28')](_0x176bce['stack']);if(_0x176bce[_0x2ff3('0x29')]){delete _0x176bce[_0x2ff3('0x29')];}_0x42d9f5[_0x2ff3('0x1b')](_0x2def4e)[_0x2ff3('0x2a')](_0x176bce);};}exports['index']=function(_0x202ec1,_0x5a1d13){var _0x27e360={},_0x1f261a={},_0x3bb403={'count':0x0,'rows':[]};var _0x34a5ec=_['map'](db[_0x2ff3('0x2b')][_0x2ff3('0x2c')],function(_0x180f58){return{'name':_0x180f58[_0x2ff3('0x2d')],'type':_0x180f58[_0x2ff3('0x2e')]['key']};});_0x1f261a[_0x2ff3('0x2f')]=_[_0x2ff3('0x30')](_0x34a5ec,'name');_0x1f261a[_0x2ff3('0x31')]=_[_0x2ff3('0x32')](_0x202ec1[_0x2ff3('0x31')]);_0x1f261a[_0x2ff3('0x33')]=_[_0x2ff3('0x34')](_0x1f261a[_0x2ff3('0x2f')],_0x1f261a[_0x2ff3('0x31')]);_0x27e360[_0x2ff3('0x35')]=_[_0x2ff3('0x34')](_0x1f261a[_0x2ff3('0x2f')],qs[_0x2ff3('0x36')](_0x202ec1[_0x2ff3('0x31')][_0x2ff3('0x36')]));_0x27e360[_0x2ff3('0x35')]=_0x27e360[_0x2ff3('0x35')][_0x2ff3('0x37')]?_0x27e360['attributes']:_0x1f261a[_0x2ff3('0x2f')];if(!_0x202ec1[_0x2ff3('0x31')][_0x2ff3('0x38')]('nolimit')){_0x27e360[_0x2ff3('0x20')]=qs[_0x2ff3('0x20')](_0x202ec1[_0x2ff3('0x31')][_0x2ff3('0x20')]);_0x27e360[_0x2ff3('0x1f')]=qs[_0x2ff3('0x1f')](_0x202ec1[_0x2ff3('0x31')][_0x2ff3('0x1f')]);}_0x27e360[_0x2ff3('0x39')]=qs[_0x2ff3('0x3a')](_0x202ec1['query'][_0x2ff3('0x3a')]);_0x27e360[_0x2ff3('0x3b')]=qs[_0x2ff3('0x33')](_[_0x2ff3('0x3c')](_0x202ec1[_0x2ff3('0x31')],_0x1f261a[_0x2ff3('0x33')]),_0x34a5ec);if(_0x202ec1[_0x2ff3('0x31')][_0x2ff3('0x3d')]){_0x27e360[_0x2ff3('0x3b')]=_[_0x2ff3('0x3e')](_0x27e360[_0x2ff3('0x3b')],{'$or':_[_0x2ff3('0x30')](_0x34a5ec,function(_0x5c1ec4){if(_0x5c1ec4[_0x2ff3('0x2e')]!=='VIRTUAL'){var _0x19e9d7={};_0x19e9d7[_0x5c1ec4['name']]={'$like':'%'+_0x202ec1['query'][_0x2ff3('0x3d')]+'%'};return _0x19e9d7;}})});}_0x27e360=_[_0x2ff3('0x3e')]({},_0x27e360,_0x202ec1['options']);var _0xad3f30={'where':_0x27e360[_0x2ff3('0x3b')]};return db['SmsQueueReport'][_0x2ff3('0x1e')](_0xad3f30)[_0x2ff3('0x3f')](function(_0x34fbea){_0x3bb403[_0x2ff3('0x1e')]=_0x34fbea;if(_0x202ec1[_0x2ff3('0x31')][_0x2ff3('0x40')]){_0x27e360[_0x2ff3('0x41')]=[{'all':!![]}];}return db[_0x2ff3('0x2b')][_0x2ff3('0x42')](_0x27e360);})[_0x2ff3('0x3f')](function(_0x3ec2cb){_0x3bb403['rows']=_0x3ec2cb;return _0x3bb403;})[_0x2ff3('0x3f')](respondWithFilteredResult(_0x5a1d13,_0x27e360))['catch'](handleError(_0x5a1d13,null));};exports[_0x2ff3('0x43')]=function(_0x2a11f7,_0x35aab3){var _0x163910={'raw':!![],'where':{'id':_0x2a11f7[_0x2ff3('0x44')]['id']}},_0x6d662b={};_0x6d662b[_0x2ff3('0x2f')]=_[_0x2ff3('0x32')](db[_0x2ff3('0x2b')][_0x2ff3('0x2c')]);_0x6d662b[_0x2ff3('0x31')]=_[_0x2ff3('0x32')](_0x2a11f7[_0x2ff3('0x31')]);_0x6d662b[_0x2ff3('0x33')]=_[_0x2ff3('0x34')](_0x6d662b[_0x2ff3('0x2f')],_0x6d662b['query']);_0x163910[_0x2ff3('0x35')]=_[_0x2ff3('0x34')](_0x6d662b['model'],qs[_0x2ff3('0x36')](_0x2a11f7[_0x2ff3('0x31')][_0x2ff3('0x36')]));_0x163910[_0x2ff3('0x35')]=_0x163910[_0x2ff3('0x35')][_0x2ff3('0x37')]?_0x163910[_0x2ff3('0x35')]:_0x6d662b[_0x2ff3('0x2f')];if(_0x2a11f7[_0x2ff3('0x31')][_0x2ff3('0x40')]){_0x163910['include']=[{'all':!![]}];}_0x163910=_[_0x2ff3('0x3e')]({},_0x163910,_0x2a11f7[_0x2ff3('0x45')]);return db['SmsQueueReport'][_0x2ff3('0x46')](_0x163910)[_0x2ff3('0x3f')](handleEntityNotFound(_0x35aab3,null))[_0x2ff3('0x3f')](respondWithResult(_0x35aab3,null))['catch'](handleError(_0x35aab3,null));};exports[_0x2ff3('0x47')]=function(_0x26eed7,_0x3387d0){return db[_0x2ff3('0x2b')][_0x2ff3('0x47')](_0x26eed7['body'],{})['then'](respondWithResult(_0x3387d0,0xc9))[_0x2ff3('0x48')](handleError(_0x3387d0,null));};exports['update']=function(_0x7fab1e,_0x23b6d6){if(_0x7fab1e['body']['id']){delete _0x7fab1e[_0x2ff3('0x49')]['id'];}return db[_0x2ff3('0x2b')][_0x2ff3('0x46')]({'where':{'id':_0x7fab1e[_0x2ff3('0x44')]['id']}})[_0x2ff3('0x3f')](handleEntityNotFound(_0x23b6d6,null))['then'](saveUpdates(_0x7fab1e[_0x2ff3('0x49')],null))[_0x2ff3('0x3f')](respondWithResult(_0x23b6d6,null))[_0x2ff3('0x48')](handleError(_0x23b6d6,null));};exports[_0x2ff3('0x26')]=function(_0x2d489f,_0x3b3e9c){return db[_0x2ff3('0x2b')][_0x2ff3('0x46')]({'where':{'id':_0x2d489f[_0x2ff3('0x44')]['id']}})[_0x2ff3('0x3f')](handleEntityNotFound(_0x3b3e9c,null))['then'](removeEntity(_0x3b3e9c,null))['catch'](handleError(_0x3b3e9c,null));};exports[_0x2ff3('0x4a')]=function(_0x23bccc,_0xc866d4){return db[_0x2ff3('0x2b')][_0x2ff3('0x4a')]()['then'](respondWithResult(_0xc866d4,null))[_0x2ff3('0x48')](handleError(_0xc866d4,null));};