Built motion from commit (unavailable).|2.3.10
[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 _0x2b98=['../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','apply','reject','save','update','then','error','stack','name','send','SmsQueueReport','model','keys','filters','intersection','query','attributes','fields','length','nolimit','order','sort','where','filter','merge','map','type','field','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','find','create','body','destroy','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','to-csv','squel','crypto','jsforce','querystring','papaparse','../../config/license/hardware','ioredis','../../components/parsers/qs','../../config/logger','api','../../config/environment'];(function(_0x3c23a1,_0x2c037d){var _0x30b445=function(_0x162f06){while(--_0x162f06){_0x3c23a1['push'](_0x3c23a1['shift']());}};_0x30b445(++_0x2c037d);}(_0x2b98,0x10a));var _0x82b9=function(_0x2763f2,_0x416af8){_0x2763f2=_0x2763f2-0x0;var _0x3ef471=_0x2b98[_0x2763f2];return _0x3ef471;};'use strict';var pdf=require(_0x82b9('0x0'));var emlformat=require(_0x82b9('0x1'));var rimraf=require(_0x82b9('0x2'));var zipdir=require(_0x82b9('0x3'));var jsonpatch=require(_0x82b9('0x4'));var rp=require(_0x82b9('0x5'));var moment=require('moment');var BPromise=require(_0x82b9('0x6'));var Mustache=require(_0x82b9('0x7'));var util=require('util');var path=require(_0x82b9('0x8'));var sox=require(_0x82b9('0x9'));var csv=require(_0x82b9('0xa'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x82b9('0xb'));var crypto=require(_0x82b9('0xc'));var jsforce=require(_0x82b9('0xd'));var deskjs=require('desk.js');var toCsv=require(_0x82b9('0xa'));var querystring=require(_0x82b9('0xe'));var Papa=require(_0x82b9('0xf'));var authService=require('../../components/auth/service');var hardwareService=require(_0x82b9('0x10'));var Redis=require(_0x82b9('0x11'));var qs=require(_0x82b9('0x12'));var logger=require(_0x82b9('0x13'))(_0x82b9('0x14'));var utils=require('../../config/utils');var config=require(_0x82b9('0x15'));var db=require(_0x82b9('0x16'))['db'];function respondWithStatusCode(_0x44eda9,_0xa24422){_0xa24422=_0xa24422||0xcc;return function(_0x4b9e0b){if(_0x4b9e0b){return _0x44eda9[_0x82b9('0x17')](_0xa24422);}return _0x44eda9[_0x82b9('0x18')](_0xa24422)[_0x82b9('0x19')]();};}function respondWithResult(_0xa65182,_0x44af90){_0x44af90=_0x44af90||0xc8;return function(_0x498597){if(_0x498597){return _0xa65182[_0x82b9('0x18')](_0x44af90)[_0x82b9('0x1a')](_0x498597);}};}function respondWithFilteredResult(_0x23d89e,_0x5a46a8){return function(_0x5c682d){if(_0x5c682d){var _0x17e916=_0x5c682d[_0x82b9('0x1b')],_0x5616dc=_0x5a46a8[_0x82b9('0x1c')],_0x49ec2d=_0x5a46a8['offset']+_0x5a46a8[_0x82b9('0x1d')],_0x1f8bc4;if(_0x49ec2d>=_0x17e916){_0x49ec2d=_0x17e916;_0x1f8bc4=0xc8;}else{_0x1f8bc4=0xce;}_0x23d89e[_0x82b9('0x18')](_0x1f8bc4);return _0x23d89e[_0x82b9('0x1e')]('Content-Range',_0x5616dc+'-'+_0x49ec2d+'/'+_0x17e916)[_0x82b9('0x1a')](_0x5c682d);}return null;};}function patchUpdates(_0x36ed16){return function(_0x27fd96){try{jsonpatch[_0x82b9('0x1f')](_0x27fd96,_0x36ed16,!![]);}catch(_0x4e6e85){return BPromise[_0x82b9('0x20')](_0x4e6e85);}return _0x27fd96[_0x82b9('0x21')]();};}function saveUpdates(_0x10ada4,_0x1faa1b){return function(_0x594e04){if(_0x594e04){return _0x594e04[_0x82b9('0x22')](_0x10ada4)[_0x82b9('0x23')](function(_0x37cf70){return _0x37cf70;});}return null;};}function removeEntity(_0x175c92,_0x51d119){return function(_0x3f74ed){if(_0x3f74ed){return _0x3f74ed['destroy']()[_0x82b9('0x23')](function(){_0x175c92[_0x82b9('0x18')](0xcc)[_0x82b9('0x19')]();});}};}function handleEntityNotFound(_0x29aed8,_0x27893d){return function(_0x4e522a){if(!_0x4e522a){_0x29aed8[_0x82b9('0x17')](0x194);}return _0x4e522a;};}function handleError(_0x5924a6,_0x2287c6){_0x2287c6=_0x2287c6||0x1f4;return function(_0x5612c9){logger[_0x82b9('0x24')](_0x5612c9[_0x82b9('0x25')]);if(_0x5612c9[_0x82b9('0x26')]){delete _0x5612c9['name'];}_0x5924a6['status'](_0x2287c6)[_0x82b9('0x27')](_0x5612c9);};}exports['index']=function(_0xf668c7,_0x3d8cb7){var _0x1ab994={},_0x304b37={},_0x25f6c3={'count':0x0,'rows':[]};var _0x3ca728=db[_0x82b9('0x28')]['rawAttributes'];_0x304b37[_0x82b9('0x29')]=_['keys'](_0x3ca728);_0x304b37['query']=_[_0x82b9('0x2a')](_0xf668c7['query']);_0x304b37[_0x82b9('0x2b')]=_[_0x82b9('0x2c')](_0x304b37['model'],_0x304b37[_0x82b9('0x2d')]);_0x1ab994[_0x82b9('0x2e')]=_[_0x82b9('0x2c')](_0x304b37[_0x82b9('0x29')],qs[_0x82b9('0x2f')](_0xf668c7['query'][_0x82b9('0x2f')]));_0x1ab994['attributes']=_0x1ab994['attributes'][_0x82b9('0x30')]?_0x1ab994['attributes']:_0x304b37[_0x82b9('0x29')];if(!_0xf668c7[_0x82b9('0x2d')]['hasOwnProperty'](_0x82b9('0x31'))){_0x1ab994['limit']=qs[_0x82b9('0x1d')](_0xf668c7['query']['limit']);_0x1ab994[_0x82b9('0x1c')]=qs[_0x82b9('0x1c')](_0xf668c7[_0x82b9('0x2d')]['offset']);}_0x1ab994[_0x82b9('0x32')]=qs[_0x82b9('0x33')](_0xf668c7[_0x82b9('0x2d')][_0x82b9('0x33')]);_0x1ab994[_0x82b9('0x34')]=qs['filters'](_['pick'](_0xf668c7[_0x82b9('0x2d')],_0x304b37[_0x82b9('0x2b')]));if(_0xf668c7[_0x82b9('0x2d')][_0x82b9('0x35')]){_0x1ab994[_0x82b9('0x34')]=_[_0x82b9('0x36')](_0x1ab994['where'],{'$or':_[_0x82b9('0x37')](_0x3ca728,function(_0x8f3bb2){if(_0x8f3bb2[_0x82b9('0x38')]['key']!=='VIRTUAL'){var _0x3eb3ae={};_0x3eb3ae[_0x8f3bb2[_0x82b9('0x39')]]={'$like':'%'+_0xf668c7[_0x82b9('0x2d')][_0x82b9('0x35')]+'%'};return _0x3eb3ae;}})});}_0x1ab994=_['merge']({},_0x1ab994,_0xf668c7[_0x82b9('0x3a')]);var _0x16ceb7={'where':_0x1ab994[_0x82b9('0x34')]};return db['SmsQueueReport']['count'](_0x16ceb7)[_0x82b9('0x23')](function(_0x35f7d8){_0x25f6c3['count']=_0x35f7d8;if(_0xf668c7[_0x82b9('0x2d')][_0x82b9('0x3b')]){_0x1ab994[_0x82b9('0x3c')]=[{'all':!![]}];}return db[_0x82b9('0x28')][_0x82b9('0x3d')](_0x1ab994);})[_0x82b9('0x23')](function(_0x127477){_0x25f6c3[_0x82b9('0x3e')]=_0x127477;return _0x25f6c3;})['then'](respondWithFilteredResult(_0x3d8cb7,_0x1ab994))[_0x82b9('0x3f')](handleError(_0x3d8cb7,null));};exports[_0x82b9('0x40')]=function(_0x5de1cf,_0x2b1384){var _0x4801ae={'raw':!![],'where':{'id':_0x5de1cf[_0x82b9('0x41')]['id']}},_0x2119ac={};_0x2119ac['model']=_[_0x82b9('0x2a')](db[_0x82b9('0x28')][_0x82b9('0x42')]);_0x2119ac['query']=_[_0x82b9('0x2a')](_0x5de1cf[_0x82b9('0x2d')]);_0x2119ac[_0x82b9('0x2b')]=_['intersection'](_0x2119ac[_0x82b9('0x29')],_0x2119ac[_0x82b9('0x2d')]);_0x4801ae[_0x82b9('0x2e')]=_['intersection'](_0x2119ac[_0x82b9('0x29')],qs[_0x82b9('0x2f')](_0x5de1cf[_0x82b9('0x2d')][_0x82b9('0x2f')]));_0x4801ae[_0x82b9('0x2e')]=_0x4801ae[_0x82b9('0x2e')][_0x82b9('0x30')]?_0x4801ae['attributes']:_0x2119ac[_0x82b9('0x29')];if(_0x5de1cf[_0x82b9('0x2d')][_0x82b9('0x3b')]){_0x4801ae['include']=[{'all':!![]}];}_0x4801ae=_[_0x82b9('0x36')]({},_0x4801ae,_0x5de1cf[_0x82b9('0x3a')]);return db[_0x82b9('0x28')][_0x82b9('0x43')](_0x4801ae)[_0x82b9('0x23')](handleEntityNotFound(_0x2b1384,null))[_0x82b9('0x23')](respondWithResult(_0x2b1384,null))['catch'](handleError(_0x2b1384,null));};exports[_0x82b9('0x44')]=function(_0x555f04,_0x1e799e){return db[_0x82b9('0x28')][_0x82b9('0x44')](_0x555f04['body'],{})[_0x82b9('0x23')](respondWithResult(_0x1e799e,0xc9))[_0x82b9('0x3f')](handleError(_0x1e799e,null));};exports['update']=function(_0x44bd2f,_0x52873c){if(_0x44bd2f['body']['id']){delete _0x44bd2f['body']['id'];}return db[_0x82b9('0x28')][_0x82b9('0x43')]({'where':{'id':_0x44bd2f[_0x82b9('0x41')]['id']}})['then'](handleEntityNotFound(_0x52873c,null))[_0x82b9('0x23')](saveUpdates(_0x44bd2f[_0x82b9('0x45')],null))[_0x82b9('0x23')](respondWithResult(_0x52873c,null))['catch'](handleError(_0x52873c,null));};exports[_0x82b9('0x46')]=function(_0x19e79a,_0x423ec4){return db[_0x82b9('0x28')]['find']({'where':{'id':_0x19e79a[_0x82b9('0x41')]['id']}})[_0x82b9('0x23')](handleEntityNotFound(_0x423ec4,null))[_0x82b9('0x23')](removeEntity(_0x423ec4,null))['catch'](handleError(_0x423ec4,null));};exports[_0x82b9('0x47')]=function(_0x598009,_0x51de5d){return db[_0x82b9('0x28')][_0x82b9('0x47')]()[_0x82b9('0x23')](respondWithResult(_0x51de5d,null))[_0x82b9('0x3f')](handleError(_0x51de5d,null));};