Built motion from commit ffdca78c.|2.6.24
[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 _0xf8de=['query','keys','intersection','attributes','fields','length','hasOwnProperty','order','sort','filters','pick','where','filter','merge','SmsQueueReport','catch','show','params','includeAll','find','create','body','destroy','describe','rimraf','zip-dir','fast-json-patch','mustache','util','path','sox','ejs','lodash','crypto','jsforce','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','offset','undefined','limit','count','set','Content-Range','json','apply','reject','save','update','then','stack','name','send','index','map','rawAttributes','type','key','model'];(function(_0x4c2dfc,_0x4814c0){var _0xfd728d=function(_0x5b8d81){while(--_0x5b8d81){_0x4c2dfc['push'](_0x4c2dfc['shift']());}};_0xfd728d(++_0x4814c0);}(_0xf8de,0x134));var _0xef8d=function(_0x1f8c7e,_0x1b52cd){_0x1f8c7e=_0x1f8c7e-0x0;var _0x43bfa1=_0xf8de[_0x1f8c7e];return _0x43bfa1;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xef8d('0x0'));var zipdir=require(_0xef8d('0x1'));var jsonpatch=require(_0xef8d('0x2'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xef8d('0x3'));var util=require(_0xef8d('0x4'));var path=require(_0xef8d('0x5'));var sox=require(_0xef8d('0x6'));var csv=require('to-csv');var ejs=require(_0xef8d('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0xef8d('0x8'));var squel=require('squel');var crypto=require(_0xef8d('0x9'));var jsforce=require(_0xef8d('0xa'));var deskjs=require('desk.js');var toCsv=require(_0xef8d('0xb'));var querystring=require(_0xef8d('0xc'));var Papa=require(_0xef8d('0xd'));var Redis=require(_0xef8d('0xe'));var authService=require(_0xef8d('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xef8d('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xef8d('0x11'))(_0xef8d('0x12'));var utils=require(_0xef8d('0x13'));var config=require(_0xef8d('0x14'));var licenseUtil=require(_0xef8d('0x15'));var db=require(_0xef8d('0x16'))['db'];function respondWithStatusCode(_0x246772,_0x51d272){_0x51d272=_0x51d272||0xcc;return function(_0x1c7ec5){if(_0x1c7ec5){return _0x246772[_0xef8d('0x17')](_0x51d272);}return _0x246772['status'](_0x51d272)[_0xef8d('0x18')]();};}function respondWithResult(_0x1428e1,_0x380de1){_0x380de1=_0x380de1||0xc8;return function(_0x5f7ad9){if(_0x5f7ad9){return _0x1428e1[_0xef8d('0x19')](_0x380de1)['json'](_0x5f7ad9);}};}function respondWithFilteredResult(_0x993310,_0x34b405){return function(_0x4b4145){if(_0x4b4145){var _0x21558d=typeof _0x34b405[_0xef8d('0x1a')]===_0xef8d('0x1b')&&typeof _0x34b405[_0xef8d('0x1c')]===_0xef8d('0x1b');var _0x571604=_0x4b4145[_0xef8d('0x1d')];var _0x402b4b=_0x21558d?0x0:_0x34b405[_0xef8d('0x1a')];var _0x42cc37=_0x21558d?_0x4b4145[_0xef8d('0x1d')]:_0x34b405[_0xef8d('0x1a')]+_0x34b405[_0xef8d('0x1c')];var _0x8d83f7;if(_0x42cc37>=_0x571604){_0x42cc37=_0x571604;_0x8d83f7=0xc8;}else{_0x8d83f7=0xce;}_0x993310[_0xef8d('0x19')](_0x8d83f7);return _0x993310[_0xef8d('0x1e')](_0xef8d('0x1f'),_0x402b4b+'-'+_0x42cc37+'/'+_0x571604)[_0xef8d('0x20')](_0x4b4145);}return null;};}function patchUpdates(_0x254181){return function(_0x4b1c60){try{jsonpatch[_0xef8d('0x21')](_0x4b1c60,_0x254181,!![]);}catch(_0x3d6b3a){return BPromise[_0xef8d('0x22')](_0x3d6b3a);}return _0x4b1c60[_0xef8d('0x23')]();};}function saveUpdates(_0xf00f81,_0x36eab0){return function(_0xa18f57){if(_0xa18f57){return _0xa18f57[_0xef8d('0x24')](_0xf00f81)[_0xef8d('0x25')](function(_0x3b5ff7){return _0x3b5ff7;});}return null;};}function removeEntity(_0x3515fd,_0xc6963d){return function(_0x3a7e3f){if(_0x3a7e3f){return _0x3a7e3f['destroy']()[_0xef8d('0x25')](function(){_0x3515fd[_0xef8d('0x19')](0xcc)[_0xef8d('0x18')]();});}};}function handleEntityNotFound(_0x62ec29,_0x34c62a){return function(_0x72254c){if(!_0x72254c){_0x62ec29[_0xef8d('0x17')](0x194);}return _0x72254c;};}function handleError(_0x29b95c,_0x1d48b5){_0x1d48b5=_0x1d48b5||0x1f4;return function(_0x4c19be){logger['error'](_0x4c19be[_0xef8d('0x26')]);if(_0x4c19be[_0xef8d('0x27')]){delete _0x4c19be[_0xef8d('0x27')];}_0x29b95c[_0xef8d('0x19')](_0x1d48b5)[_0xef8d('0x28')](_0x4c19be);};}exports[_0xef8d('0x29')]=function(_0x54fdb7,_0x4cc636){var _0x3e7e76={},_0x1dc6b1={},_0x203861={'count':0x0,'rows':[]};var _0x593487=_[_0xef8d('0x2a')](db['SmsQueueReport'][_0xef8d('0x2b')],function(_0x5d14d0){return{'name':_0x5d14d0['fieldName'],'type':_0x5d14d0[_0xef8d('0x2c')][_0xef8d('0x2d')]};});_0x1dc6b1[_0xef8d('0x2e')]=_[_0xef8d('0x2a')](_0x593487,'name');_0x1dc6b1[_0xef8d('0x2f')]=_[_0xef8d('0x30')](_0x54fdb7[_0xef8d('0x2f')]);_0x1dc6b1['filters']=_[_0xef8d('0x31')](_0x1dc6b1['model'],_0x1dc6b1[_0xef8d('0x2f')]);_0x3e7e76[_0xef8d('0x32')]=_[_0xef8d('0x31')](_0x1dc6b1[_0xef8d('0x2e')],qs[_0xef8d('0x33')](_0x54fdb7[_0xef8d('0x2f')]['fields']));_0x3e7e76['attributes']=_0x3e7e76[_0xef8d('0x32')][_0xef8d('0x34')]?_0x3e7e76[_0xef8d('0x32')]:_0x1dc6b1[_0xef8d('0x2e')];if(!_0x54fdb7[_0xef8d('0x2f')][_0xef8d('0x35')]('nolimit')){_0x3e7e76[_0xef8d('0x1c')]=qs[_0xef8d('0x1c')](_0x54fdb7['query']['limit']);_0x3e7e76['offset']=qs[_0xef8d('0x1a')](_0x54fdb7[_0xef8d('0x2f')][_0xef8d('0x1a')]);}_0x3e7e76[_0xef8d('0x36')]=qs[_0xef8d('0x37')](_0x54fdb7['query'][_0xef8d('0x37')]);_0x3e7e76['where']=qs[_0xef8d('0x38')](_[_0xef8d('0x39')](_0x54fdb7[_0xef8d('0x2f')],_0x1dc6b1['filters']),_0x593487);if(_0x54fdb7[_0xef8d('0x2f')]['filter']){_0x3e7e76[_0xef8d('0x3a')]=_['merge'](_0x3e7e76['where'],{'$or':_[_0xef8d('0x2a')](_0x593487,function(_0x562317){if(_0x562317['type']!=='VIRTUAL'){var _0x32e626={};_0x32e626[_0x562317[_0xef8d('0x27')]]={'$like':'%'+_0x54fdb7['query'][_0xef8d('0x3b')]+'%'};return _0x32e626;}})});}_0x3e7e76=_[_0xef8d('0x3c')]({},_0x3e7e76,_0x54fdb7['options']);var _0x430d2d={'where':_0x3e7e76[_0xef8d('0x3a')]};return db['SmsQueueReport'][_0xef8d('0x1d')](_0x430d2d)['then'](function(_0x5e2361){_0x203861[_0xef8d('0x1d')]=_0x5e2361;if(_0x54fdb7[_0xef8d('0x2f')]['includeAll']){_0x3e7e76['include']=[{'all':!![]}];}return db[_0xef8d('0x3d')]['findAll'](_0x3e7e76);})['then'](function(_0x2b1164){_0x203861['rows']=_0x2b1164;return _0x203861;})['then'](respondWithFilteredResult(_0x4cc636,_0x3e7e76))[_0xef8d('0x3e')](handleError(_0x4cc636,null));};exports[_0xef8d('0x3f')]=function(_0x2199d9,_0xc51a9a){var _0x5c61cb={'raw':!![],'where':{'id':_0x2199d9[_0xef8d('0x40')]['id']}},_0x3778ac={};_0x3778ac[_0xef8d('0x2e')]=_[_0xef8d('0x30')](db['SmsQueueReport'][_0xef8d('0x2b')]);_0x3778ac[_0xef8d('0x2f')]=_['keys'](_0x2199d9[_0xef8d('0x2f')]);_0x3778ac[_0xef8d('0x38')]=_['intersection'](_0x3778ac[_0xef8d('0x2e')],_0x3778ac[_0xef8d('0x2f')]);_0x5c61cb[_0xef8d('0x32')]=_['intersection'](_0x3778ac[_0xef8d('0x2e')],qs[_0xef8d('0x33')](_0x2199d9[_0xef8d('0x2f')][_0xef8d('0x33')]));_0x5c61cb['attributes']=_0x5c61cb[_0xef8d('0x32')][_0xef8d('0x34')]?_0x5c61cb[_0xef8d('0x32')]:_0x3778ac[_0xef8d('0x2e')];if(_0x2199d9[_0xef8d('0x2f')][_0xef8d('0x41')]){_0x5c61cb['include']=[{'all':!![]}];}_0x5c61cb=_[_0xef8d('0x3c')]({},_0x5c61cb,_0x2199d9['options']);return db[_0xef8d('0x3d')][_0xef8d('0x42')](_0x5c61cb)[_0xef8d('0x25')](handleEntityNotFound(_0xc51a9a,null))['then'](respondWithResult(_0xc51a9a,null))[_0xef8d('0x3e')](handleError(_0xc51a9a,null));};exports[_0xef8d('0x43')]=function(_0x43920a,_0x3f3fb4){return db[_0xef8d('0x3d')][_0xef8d('0x43')](_0x43920a[_0xef8d('0x44')],{})[_0xef8d('0x25')](respondWithResult(_0x3f3fb4,0xc9))['catch'](handleError(_0x3f3fb4,null));};exports[_0xef8d('0x24')]=function(_0x44890a,_0x45e023){if(_0x44890a[_0xef8d('0x44')]['id']){delete _0x44890a[_0xef8d('0x44')]['id'];}return db['SmsQueueReport'][_0xef8d('0x42')]({'where':{'id':_0x44890a[_0xef8d('0x40')]['id']}})[_0xef8d('0x25')](handleEntityNotFound(_0x45e023,null))[_0xef8d('0x25')](saveUpdates(_0x44890a[_0xef8d('0x44')],null))[_0xef8d('0x25')](respondWithResult(_0x45e023,null))[_0xef8d('0x3e')](handleError(_0x45e023,null));};exports[_0xef8d('0x45')]=function(_0x4a79c8,_0x2135a7){return db[_0xef8d('0x3d')][_0xef8d('0x42')]({'where':{'id':_0x4a79c8[_0xef8d('0x40')]['id']}})[_0xef8d('0x25')](handleEntityNotFound(_0x2135a7,null))[_0xef8d('0x25')](removeEntity(_0x2135a7,null))['catch'](handleError(_0x2135a7,null));};exports[_0xef8d('0x46')]=function(_0x3fb9d7,_0x77ea21){return db[_0xef8d('0x3d')][_0xef8d('0x46')]()[_0xef8d('0x25')](respondWithResult(_0x77ea21,null))[_0xef8d('0x3e')](handleError(_0x77ea21,null));};