Built motion from commit 639a1a7f.|2.6.19
[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 _0xaf6c=['sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','reject','update','then','destroy','stack','send','map','SmsQueueReport','fieldName','type','key','model','name','keys','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','rawAttributes','catch','create','body','find','describe','rimraf','zip-dir','fast-json-patch','request-promise','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb'];(function(_0x315ed1,_0x1c0a0c){var _0x188b55=function(_0x376b90){while(--_0x376b90){_0x315ed1['push'](_0x315ed1['shift']());}};_0x188b55(++_0x1c0a0c);}(_0xaf6c,0x156));var _0xcaf6=function(_0x35a5c2,_0x595a75){_0x35a5c2=_0x35a5c2-0x0;var _0xc69a31=_0xaf6c[_0x35a5c2];return _0xc69a31;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xcaf6('0x0'));var zipdir=require(_0xcaf6('0x1'));var jsonpatch=require(_0xcaf6('0x2'));var rp=require(_0xcaf6('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xcaf6('0x4'));var path=require('path');var sox=require(_0xcaf6('0x5'));var csv=require(_0xcaf6('0x6'));var ejs=require(_0xcaf6('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xcaf6('0x8'));var squel=require(_0xcaf6('0x9'));var crypto=require(_0xcaf6('0xa'));var jsforce=require(_0xcaf6('0xb'));var deskjs=require(_0xcaf6('0xc'));var toCsv=require('to-csv');var querystring=require(_0xcaf6('0xd'));var Papa=require(_0xcaf6('0xe'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0xcaf6('0xf'));var hardwareService=require(_0xcaf6('0x10'));var logger=require(_0xcaf6('0x11'))(_0xcaf6('0x12'));var utils=require(_0xcaf6('0x13'));var config=require(_0xcaf6('0x14'));var licenseUtil=require(_0xcaf6('0x15'));var db=require(_0xcaf6('0x16'))['db'];function respondWithStatusCode(_0x2f61d4,_0x27d88e){_0x27d88e=_0x27d88e||0xcc;return function(_0x3eeb1d){if(_0x3eeb1d){return _0x2f61d4[_0xcaf6('0x17')](_0x27d88e);}return _0x2f61d4[_0xcaf6('0x18')](_0x27d88e)[_0xcaf6('0x19')]();};}function respondWithResult(_0x18afd2,_0x1bf724){_0x1bf724=_0x1bf724||0xc8;return function(_0x36afd2){if(_0x36afd2){return _0x18afd2[_0xcaf6('0x18')](_0x1bf724)[_0xcaf6('0x1a')](_0x36afd2);}};}function respondWithFilteredResult(_0x97e40b,_0x520f87){return function(_0x3d109b){if(_0x3d109b){var _0x1cdbe5=typeof _0x520f87[_0xcaf6('0x1b')]===_0xcaf6('0x1c')&&typeof _0x520f87[_0xcaf6('0x1d')]===_0xcaf6('0x1c');var _0x3de33b=_0x3d109b[_0xcaf6('0x1e')];var _0x3bab9b=_0x1cdbe5?0x0:_0x520f87['offset'];var _0x3a41f9=_0x1cdbe5?_0x3d109b[_0xcaf6('0x1e')]:_0x520f87[_0xcaf6('0x1b')]+_0x520f87[_0xcaf6('0x1d')];var _0x4d485e;if(_0x3a41f9>=_0x3de33b){_0x3a41f9=_0x3de33b;_0x4d485e=0xc8;}else{_0x4d485e=0xce;}_0x97e40b['status'](_0x4d485e);return _0x97e40b['set'](_0xcaf6('0x1f'),_0x3bab9b+'-'+_0x3a41f9+'/'+_0x3de33b)[_0xcaf6('0x1a')](_0x3d109b);}return null;};}function patchUpdates(_0xafc0af){return function(_0x20279a){try{jsonpatch['apply'](_0x20279a,_0xafc0af,!![]);}catch(_0x14bfa5){return BPromise[_0xcaf6('0x20')](_0x14bfa5);}return _0x20279a['save']();};}function saveUpdates(_0x46d28b,_0x5e2113){return function(_0x201127){if(_0x201127){return _0x201127[_0xcaf6('0x21')](_0x46d28b)[_0xcaf6('0x22')](function(_0x18aff5){return _0x18aff5;});}return null;};}function removeEntity(_0x5cebd2,_0x256e97){return function(_0x2cd37e){if(_0x2cd37e){return _0x2cd37e[_0xcaf6('0x23')]()[_0xcaf6('0x22')](function(){_0x5cebd2[_0xcaf6('0x18')](0xcc)[_0xcaf6('0x19')]();});}};}function handleEntityNotFound(_0x3a92bc,_0x1e767d){return function(_0x1f6dd7){if(!_0x1f6dd7){_0x3a92bc[_0xcaf6('0x17')](0x194);}return _0x1f6dd7;};}function handleError(_0x26b7af,_0x7410a4){_0x7410a4=_0x7410a4||0x1f4;return function(_0xca6cb0){logger['error'](_0xca6cb0[_0xcaf6('0x24')]);if(_0xca6cb0['name']){delete _0xca6cb0['name'];}_0x26b7af[_0xcaf6('0x18')](_0x7410a4)[_0xcaf6('0x25')](_0xca6cb0);};}exports['index']=function(_0x5309cd,_0xabe2b2){var _0x4e6074={},_0x201b37={},_0x39981e={'count':0x0,'rows':[]};var _0x3d3626=_[_0xcaf6('0x26')](db[_0xcaf6('0x27')]['rawAttributes'],function(_0x555ab1){return{'name':_0x555ab1[_0xcaf6('0x28')],'type':_0x555ab1[_0xcaf6('0x29')][_0xcaf6('0x2a')]};});_0x201b37[_0xcaf6('0x2b')]=_[_0xcaf6('0x26')](_0x3d3626,_0xcaf6('0x2c'));_0x201b37['query']=_[_0xcaf6('0x2d')](_0x5309cd[_0xcaf6('0x2e')]);_0x201b37['filters']=_[_0xcaf6('0x2f')](_0x201b37[_0xcaf6('0x2b')],_0x201b37[_0xcaf6('0x2e')]);_0x4e6074[_0xcaf6('0x30')]=_[_0xcaf6('0x2f')](_0x201b37[_0xcaf6('0x2b')],qs[_0xcaf6('0x31')](_0x5309cd['query'][_0xcaf6('0x31')]));_0x4e6074[_0xcaf6('0x30')]=_0x4e6074[_0xcaf6('0x30')][_0xcaf6('0x32')]?_0x4e6074['attributes']:_0x201b37[_0xcaf6('0x2b')];if(!_0x5309cd[_0xcaf6('0x2e')][_0xcaf6('0x33')](_0xcaf6('0x34'))){_0x4e6074[_0xcaf6('0x1d')]=qs[_0xcaf6('0x1d')](_0x5309cd['query'][_0xcaf6('0x1d')]);_0x4e6074[_0xcaf6('0x1b')]=qs[_0xcaf6('0x1b')](_0x5309cd[_0xcaf6('0x2e')][_0xcaf6('0x1b')]);}_0x4e6074[_0xcaf6('0x35')]=qs[_0xcaf6('0x36')](_0x5309cd['query'][_0xcaf6('0x36')]);_0x4e6074[_0xcaf6('0x37')]=qs[_0xcaf6('0x38')](_[_0xcaf6('0x39')](_0x5309cd['query'],_0x201b37[_0xcaf6('0x38')]),_0x3d3626);if(_0x5309cd[_0xcaf6('0x2e')][_0xcaf6('0x3a')]){_0x4e6074[_0xcaf6('0x37')]=_[_0xcaf6('0x3b')](_0x4e6074['where'],{'$or':_['map'](_0x3d3626,function(_0x5ec5c1){if(_0x5ec5c1[_0xcaf6('0x29')]!==_0xcaf6('0x3c')){var _0x5a00c2={};_0x5a00c2[_0x5ec5c1[_0xcaf6('0x2c')]]={'$like':'%'+_0x5309cd['query'][_0xcaf6('0x3a')]+'%'};return _0x5a00c2;}})});}_0x4e6074=_['merge']({},_0x4e6074,_0x5309cd['options']);var _0x2f7a94={'where':_0x4e6074[_0xcaf6('0x37')]};return db[_0xcaf6('0x27')][_0xcaf6('0x1e')](_0x2f7a94)[_0xcaf6('0x22')](function(_0xc7a86c){_0x39981e['count']=_0xc7a86c;if(_0x5309cd[_0xcaf6('0x2e')][_0xcaf6('0x3d')]){_0x4e6074[_0xcaf6('0x3e')]=[{'all':!![]}];}return db[_0xcaf6('0x27')][_0xcaf6('0x3f')](_0x4e6074);})[_0xcaf6('0x22')](function(_0x14b2a1){_0x39981e[_0xcaf6('0x40')]=_0x14b2a1;return _0x39981e;})['then'](respondWithFilteredResult(_0xabe2b2,_0x4e6074))['catch'](handleError(_0xabe2b2,null));};exports[_0xcaf6('0x41')]=function(_0x30f34c,_0x279a31){var _0xdc3d9c={'raw':!![],'where':{'id':_0x30f34c[_0xcaf6('0x42')]['id']}},_0x50bfbb={};_0x50bfbb['model']=_[_0xcaf6('0x2d')](db[_0xcaf6('0x27')][_0xcaf6('0x43')]);_0x50bfbb[_0xcaf6('0x2e')]=_['keys'](_0x30f34c[_0xcaf6('0x2e')]);_0x50bfbb['filters']=_[_0xcaf6('0x2f')](_0x50bfbb[_0xcaf6('0x2b')],_0x50bfbb[_0xcaf6('0x2e')]);_0xdc3d9c['attributes']=_['intersection'](_0x50bfbb[_0xcaf6('0x2b')],qs['fields'](_0x30f34c[_0xcaf6('0x2e')][_0xcaf6('0x31')]));_0xdc3d9c[_0xcaf6('0x30')]=_0xdc3d9c[_0xcaf6('0x30')][_0xcaf6('0x32')]?_0xdc3d9c[_0xcaf6('0x30')]:_0x50bfbb[_0xcaf6('0x2b')];if(_0x30f34c[_0xcaf6('0x2e')][_0xcaf6('0x3d')]){_0xdc3d9c['include']=[{'all':!![]}];}_0xdc3d9c=_['merge']({},_0xdc3d9c,_0x30f34c['options']);return db[_0xcaf6('0x27')]['find'](_0xdc3d9c)[_0xcaf6('0x22')](handleEntityNotFound(_0x279a31,null))[_0xcaf6('0x22')](respondWithResult(_0x279a31,null))[_0xcaf6('0x44')](handleError(_0x279a31,null));};exports['create']=function(_0x441362,_0x19f5bc){return db['SmsQueueReport'][_0xcaf6('0x45')](_0x441362[_0xcaf6('0x46')],{})[_0xcaf6('0x22')](respondWithResult(_0x19f5bc,0xc9))[_0xcaf6('0x44')](handleError(_0x19f5bc,null));};exports[_0xcaf6('0x21')]=function(_0x1f00ff,_0x1b55d1){if(_0x1f00ff[_0xcaf6('0x46')]['id']){delete _0x1f00ff[_0xcaf6('0x46')]['id'];}return db['SmsQueueReport'][_0xcaf6('0x47')]({'where':{'id':_0x1f00ff[_0xcaf6('0x42')]['id']}})[_0xcaf6('0x22')](handleEntityNotFound(_0x1b55d1,null))['then'](saveUpdates(_0x1f00ff[_0xcaf6('0x46')],null))['then'](respondWithResult(_0x1b55d1,null))[_0xcaf6('0x44')](handleError(_0x1b55d1,null));};exports[_0xcaf6('0x23')]=function(_0x4efd27,_0x5354fe){return db['SmsQueueReport'][_0xcaf6('0x47')]({'where':{'id':_0x4efd27[_0xcaf6('0x42')]['id']}})[_0xcaf6('0x22')](handleEntityNotFound(_0x5354fe,null))[_0xcaf6('0x22')](removeEntity(_0x5354fe,null))['catch'](handleError(_0x5354fe,null));};exports[_0xcaf6('0x48')]=function(_0x582ab4,_0x2e726a){return db[_0xcaf6('0x27')][_0xcaf6('0x48')]()[_0xcaf6('0x22')](respondWithResult(_0x2e726a,null))[_0xcaf6('0x44')](handleError(_0x2e726a,null));};