Built motion from commit (unavailable).|2.4.20
[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 _0x6c6b=['query','keys','filters','intersection','attributes','model','fields','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','count','includeAll','include','findAll','rows','catch','show','length','create','body','find','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','util','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','status','end','offset','limit','Content-Range','json','reject','save','update','destroy','then','error','name','send','index','map','SmsQueueReport','rawAttributes','type'];(function(_0xf3c843,_0x8ff24e){var _0x3191c6=function(_0x2f1ef7){while(--_0x2f1ef7){_0xf3c843['push'](_0xf3c843['shift']());}};_0x3191c6(++_0x8ff24e);}(_0x6c6b,0x145));var _0xb6c6=function(_0x47aa64,_0xfb8a07){_0x47aa64=_0x47aa64-0x0;var _0x549c7a=_0x6c6b[_0x47aa64];return _0x549c7a;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xb6c6('0x0'));var rimraf=require(_0xb6c6('0x1'));var zipdir=require(_0xb6c6('0x2'));var jsonpatch=require(_0xb6c6('0x3'));var rp=require(_0xb6c6('0x4'));var moment=require('moment');var BPromise=require(_0xb6c6('0x5'));var Mustache=require('mustache');var util=require(_0xb6c6('0x6'));var path=require(_0xb6c6('0x7'));var sox=require('sox');var csv=require(_0xb6c6('0x8'));var ejs=require(_0xb6c6('0x9'));var fs=require('fs');var _=require(_0xb6c6('0xa'));var squel=require(_0xb6c6('0xb'));var crypto=require(_0xb6c6('0xc'));var jsforce=require(_0xb6c6('0xd'));var deskjs=require(_0xb6c6('0xe'));var toCsv=require('to-csv');var querystring=require(_0xb6c6('0xf'));var Papa=require(_0xb6c6('0x10'));var Redis=require(_0xb6c6('0x11'));var authService=require(_0xb6c6('0x12'));var qs=require(_0xb6c6('0x13'));var as=require(_0xb6c6('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xb6c6('0x15'))(_0xb6c6('0x16'));var utils=require(_0xb6c6('0x17'));var config=require(_0xb6c6('0x18'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x53daf9,_0x5ba091){_0x5ba091=_0x5ba091||0xcc;return function(_0x1f7e72){if(_0x1f7e72){return _0x53daf9[_0xb6c6('0x19')](_0x5ba091);}return _0x53daf9[_0xb6c6('0x1a')](_0x5ba091)[_0xb6c6('0x1b')]();};}function respondWithResult(_0x4215c9,_0x20421d){_0x20421d=_0x20421d||0xc8;return function(_0x1f7e79){if(_0x1f7e79){return _0x4215c9[_0xb6c6('0x1a')](_0x20421d)['json'](_0x1f7e79);}};}function respondWithFilteredResult(_0x1b643b,_0x500c88){return function(_0x4e92d9){if(_0x4e92d9){var _0x55b661=_0x4e92d9['count'],_0x262491=_0x500c88[_0xb6c6('0x1c')],_0x532da3=_0x500c88[_0xb6c6('0x1c')]+_0x500c88[_0xb6c6('0x1d')],_0x367d4b;if(_0x532da3>=_0x55b661){_0x532da3=_0x55b661;_0x367d4b=0xc8;}else{_0x367d4b=0xce;}_0x1b643b[_0xb6c6('0x1a')](_0x367d4b);return _0x1b643b['set'](_0xb6c6('0x1e'),_0x262491+'-'+_0x532da3+'/'+_0x55b661)[_0xb6c6('0x1f')](_0x4e92d9);}return null;};}function patchUpdates(_0xefd695){return function(_0x3f3e4b){try{jsonpatch['apply'](_0x3f3e4b,_0xefd695,!![]);}catch(_0x1e9b9b){return BPromise[_0xb6c6('0x20')](_0x1e9b9b);}return _0x3f3e4b[_0xb6c6('0x21')]();};}function saveUpdates(_0x363927,_0x11610e){return function(_0x5caf7a){if(_0x5caf7a){return _0x5caf7a[_0xb6c6('0x22')](_0x363927)['then'](function(_0x139418){return _0x139418;});}return null;};}function removeEntity(_0x18f949,_0x115a8f){return function(_0x35ead7){if(_0x35ead7){return _0x35ead7[_0xb6c6('0x23')]()[_0xb6c6('0x24')](function(){_0x18f949[_0xb6c6('0x1a')](0xcc)[_0xb6c6('0x1b')]();});}};}function handleEntityNotFound(_0x1213cc,_0x337cae){return function(_0x5eab01){if(!_0x5eab01){_0x1213cc[_0xb6c6('0x19')](0x194);}return _0x5eab01;};}function handleError(_0x4dca0e,_0xf0e83d){_0xf0e83d=_0xf0e83d||0x1f4;return function(_0x2c5010){logger[_0xb6c6('0x25')](_0x2c5010['stack']);if(_0x2c5010[_0xb6c6('0x26')]){delete _0x2c5010[_0xb6c6('0x26')];}_0x4dca0e['status'](_0xf0e83d)[_0xb6c6('0x27')](_0x2c5010);};}exports[_0xb6c6('0x28')]=function(_0x1d4e42,_0x59b3f3){var _0x26b73c={},_0x302abd={},_0x34f989={'count':0x0,'rows':[]};var _0x42d356=_[_0xb6c6('0x29')](db[_0xb6c6('0x2a')][_0xb6c6('0x2b')],function(_0x2f3bfe){return{'name':_0x2f3bfe['fieldName'],'type':_0x2f3bfe[_0xb6c6('0x2c')]['key']};});_0x302abd['model']=_[_0xb6c6('0x29')](_0x42d356,'name');_0x302abd[_0xb6c6('0x2d')]=_[_0xb6c6('0x2e')](_0x1d4e42[_0xb6c6('0x2d')]);_0x302abd[_0xb6c6('0x2f')]=_[_0xb6c6('0x30')](_0x302abd['model'],_0x302abd[_0xb6c6('0x2d')]);_0x26b73c[_0xb6c6('0x31')]=_['intersection'](_0x302abd[_0xb6c6('0x32')],qs[_0xb6c6('0x33')](_0x1d4e42[_0xb6c6('0x2d')][_0xb6c6('0x33')]));_0x26b73c['attributes']=_0x26b73c[_0xb6c6('0x31')]['length']?_0x26b73c['attributes']:_0x302abd[_0xb6c6('0x32')];if(!_0x1d4e42[_0xb6c6('0x2d')][_0xb6c6('0x34')](_0xb6c6('0x35'))){_0x26b73c[_0xb6c6('0x1d')]=qs[_0xb6c6('0x1d')](_0x1d4e42['query'][_0xb6c6('0x1d')]);_0x26b73c['offset']=qs['offset'](_0x1d4e42[_0xb6c6('0x2d')][_0xb6c6('0x1c')]);}_0x26b73c[_0xb6c6('0x36')]=qs[_0xb6c6('0x37')](_0x1d4e42[_0xb6c6('0x2d')][_0xb6c6('0x37')]);_0x26b73c[_0xb6c6('0x38')]=qs['filters'](_[_0xb6c6('0x39')](_0x1d4e42[_0xb6c6('0x2d')],_0x302abd[_0xb6c6('0x2f')]));if(_0x1d4e42['query'][_0xb6c6('0x3a')]){_0x26b73c[_0xb6c6('0x38')]=_[_0xb6c6('0x3b')](_0x26b73c['where'],{'$or':_[_0xb6c6('0x29')](_0x42d356,function(_0x2b3b50){if(_0x2b3b50[_0xb6c6('0x2c')]!=='VIRTUAL'){var _0x139415={};_0x139415[_0x2b3b50[_0xb6c6('0x26')]]={'$like':'%'+_0x1d4e42[_0xb6c6('0x2d')][_0xb6c6('0x3a')]+'%'};return _0x139415;}})});}_0x26b73c=_['merge']({},_0x26b73c,_0x1d4e42[_0xb6c6('0x3c')]);var _0x5ee83e={'where':_0x26b73c['where']};return db['SmsQueueReport'][_0xb6c6('0x3d')](_0x5ee83e)[_0xb6c6('0x24')](function(_0x461d1b){_0x34f989['count']=_0x461d1b;if(_0x1d4e42['query'][_0xb6c6('0x3e')]){_0x26b73c[_0xb6c6('0x3f')]=[{'all':!![]}];}return db[_0xb6c6('0x2a')][_0xb6c6('0x40')](_0x26b73c);})[_0xb6c6('0x24')](function(_0x278bea){_0x34f989[_0xb6c6('0x41')]=_0x278bea;return _0x34f989;})['then'](respondWithFilteredResult(_0x59b3f3,_0x26b73c))[_0xb6c6('0x42')](handleError(_0x59b3f3,null));};exports[_0xb6c6('0x43')]=function(_0x3b6475,_0xd0aea2){var _0x4c80ff={'raw':!![],'where':{'id':_0x3b6475['params']['id']}},_0x21a636={};_0x21a636[_0xb6c6('0x32')]=_['keys'](db['SmsQueueReport'][_0xb6c6('0x2b')]);_0x21a636[_0xb6c6('0x2d')]=_[_0xb6c6('0x2e')](_0x3b6475[_0xb6c6('0x2d')]);_0x21a636[_0xb6c6('0x2f')]=_['intersection'](_0x21a636[_0xb6c6('0x32')],_0x21a636[_0xb6c6('0x2d')]);_0x4c80ff[_0xb6c6('0x31')]=_[_0xb6c6('0x30')](_0x21a636[_0xb6c6('0x32')],qs['fields'](_0x3b6475[_0xb6c6('0x2d')][_0xb6c6('0x33')]));_0x4c80ff[_0xb6c6('0x31')]=_0x4c80ff[_0xb6c6('0x31')][_0xb6c6('0x44')]?_0x4c80ff[_0xb6c6('0x31')]:_0x21a636['model'];if(_0x3b6475[_0xb6c6('0x2d')][_0xb6c6('0x3e')]){_0x4c80ff[_0xb6c6('0x3f')]=[{'all':!![]}];}_0x4c80ff=_[_0xb6c6('0x3b')]({},_0x4c80ff,_0x3b6475[_0xb6c6('0x3c')]);return db[_0xb6c6('0x2a')]['find'](_0x4c80ff)['then'](handleEntityNotFound(_0xd0aea2,null))[_0xb6c6('0x24')](respondWithResult(_0xd0aea2,null))[_0xb6c6('0x42')](handleError(_0xd0aea2,null));};exports[_0xb6c6('0x45')]=function(_0x484eb1,_0x3f699d){return db[_0xb6c6('0x2a')]['create'](_0x484eb1[_0xb6c6('0x46')],{})[_0xb6c6('0x24')](respondWithResult(_0x3f699d,0xc9))[_0xb6c6('0x42')](handleError(_0x3f699d,null));};exports[_0xb6c6('0x22')]=function(_0x5aa8b4,_0x4566c0){if(_0x5aa8b4[_0xb6c6('0x46')]['id']){delete _0x5aa8b4['body']['id'];}return db['SmsQueueReport'][_0xb6c6('0x47')]({'where':{'id':_0x5aa8b4[_0xb6c6('0x48')]['id']}})['then'](handleEntityNotFound(_0x4566c0,null))[_0xb6c6('0x24')](saveUpdates(_0x5aa8b4[_0xb6c6('0x46')],null))[_0xb6c6('0x24')](respondWithResult(_0x4566c0,null))[_0xb6c6('0x42')](handleError(_0x4566c0,null));};exports[_0xb6c6('0x23')]=function(_0x2f180f,_0x3c333d){return db[_0xb6c6('0x2a')][_0xb6c6('0x47')]({'where':{'id':_0x2f180f[_0xb6c6('0x48')]['id']}})['then'](handleEntityNotFound(_0x3c333d,null))[_0xb6c6('0x24')](removeEntity(_0x3c333d,null))[_0xb6c6('0x42')](handleError(_0x3c333d,null));};exports[_0xb6c6('0x49')]=function(_0x5b862a,_0xa2720c){return db[_0xb6c6('0x2a')][_0xb6c6('0x49')]()['then'](respondWithResult(_0xa2720c,null))[_0xb6c6('0x42')](handleError(_0xa2720c,null));};