b8e96b9ccff346e2b37360b967a95a7b2a3bdeeb
[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 _0xf409=['update','then','error','stack','send','index','map','SmsQueueReport','rawAttributes','type','model','name','query','filters','attributes','fields','length','hasOwnProperty','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','keys','intersection','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','reject','save'];(function(_0x4bc4f3,_0xb93bd2){var _0x478fab=function(_0x2404ea){while(--_0x2404ea){_0x4bc4f3['push'](_0x4bc4f3['shift']());}};_0x478fab(++_0xb93bd2);}(_0xf409,0x1cf));var _0x9f40=function(_0x4ae625,_0xf396d0){_0x4ae625=_0x4ae625-0x0;var _0x31accf=_0xf409[_0x4ae625];return _0x31accf;};'use strict';var pdf=require(_0x9f40('0x0'));var emlformat=require(_0x9f40('0x1'));var rimraf=require(_0x9f40('0x2'));var zipdir=require(_0x9f40('0x3'));var jsonpatch=require(_0x9f40('0x4'));var rp=require(_0x9f40('0x5'));var moment=require(_0x9f40('0x6'));var BPromise=require(_0x9f40('0x7'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x9f40('0x8'));var fs=require('fs');var _=require(_0x9f40('0x9'));var squel=require(_0x9f40('0xa'));var crypto=require(_0x9f40('0xb'));var jsforce=require(_0x9f40('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x9f40('0xd'));var Papa=require('papaparse');var Redis=require(_0x9f40('0xe'));var authService=require(_0x9f40('0xf'));var qs=require(_0x9f40('0x10'));var as=require(_0x9f40('0x11'));var hardwareService=require(_0x9f40('0x12'));var logger=require(_0x9f40('0x13'))(_0x9f40('0x14'));var utils=require('../../config/utils');var config=require(_0x9f40('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0x9f40('0x16'))['db'];function respondWithStatusCode(_0x98a905,_0x4db5a2){_0x4db5a2=_0x4db5a2||0xcc;return function(_0x476b59){if(_0x476b59){return _0x98a905[_0x9f40('0x17')](_0x4db5a2);}return _0x98a905[_0x9f40('0x18')](_0x4db5a2)[_0x9f40('0x19')]();};}function respondWithResult(_0x2f6f63,_0x38d419){_0x38d419=_0x38d419||0xc8;return function(_0x52fa66){if(_0x52fa66){return _0x2f6f63[_0x9f40('0x18')](_0x38d419)['json'](_0x52fa66);}};}function respondWithFilteredResult(_0x410a57,_0x5328d8){return function(_0x13641c){if(_0x13641c){var _0x2e176a=_0x13641c[_0x9f40('0x1a')],_0x3b77bf=_0x5328d8[_0x9f40('0x1b')],_0x55a8a5=_0x5328d8[_0x9f40('0x1b')]+_0x5328d8[_0x9f40('0x1c')],_0x49127d;if(_0x55a8a5>=_0x2e176a){_0x55a8a5=_0x2e176a;_0x49127d=0xc8;}else{_0x49127d=0xce;}_0x410a57['status'](_0x49127d);return _0x410a57[_0x9f40('0x1d')](_0x9f40('0x1e'),_0x3b77bf+'-'+_0x55a8a5+'/'+_0x2e176a)[_0x9f40('0x1f')](_0x13641c);}return null;};}function patchUpdates(_0x4afa95){return function(_0x2a1e37){try{jsonpatch['apply'](_0x2a1e37,_0x4afa95,!![]);}catch(_0x2b0866){return BPromise[_0x9f40('0x20')](_0x2b0866);}return _0x2a1e37[_0x9f40('0x21')]();};}function saveUpdates(_0x41b042,_0x4ab98c){return function(_0x4aabdc){if(_0x4aabdc){return _0x4aabdc[_0x9f40('0x22')](_0x41b042)[_0x9f40('0x23')](function(_0x101270){return _0x101270;});}return null;};}function removeEntity(_0x4f66a4,_0x4c5335){return function(_0x10ce0b){if(_0x10ce0b){return _0x10ce0b['destroy']()[_0x9f40('0x23')](function(){_0x4f66a4['status'](0xcc)[_0x9f40('0x19')]();});}};}function handleEntityNotFound(_0x5b1b73,_0x149b52){return function(_0x319ed9){if(!_0x319ed9){_0x5b1b73['sendStatus'](0x194);}return _0x319ed9;};}function handleError(_0xbc5968,_0x4a448e){_0x4a448e=_0x4a448e||0x1f4;return function(_0x2bdad2){logger[_0x9f40('0x24')](_0x2bdad2[_0x9f40('0x25')]);if(_0x2bdad2['name']){delete _0x2bdad2['name'];}_0xbc5968[_0x9f40('0x18')](_0x4a448e)[_0x9f40('0x26')](_0x2bdad2);};}exports[_0x9f40('0x27')]=function(_0x597cca,_0x301255){var _0x2b7a70={},_0x552253={},_0x3a7a61={'count':0x0,'rows':[]};var _0x3907eb=_[_0x9f40('0x28')](db[_0x9f40('0x29')][_0x9f40('0x2a')],function(_0x44f544){return{'name':_0x44f544['fieldName'],'type':_0x44f544[_0x9f40('0x2b')]['key']};});_0x552253[_0x9f40('0x2c')]=_[_0x9f40('0x28')](_0x3907eb,_0x9f40('0x2d'));_0x552253[_0x9f40('0x2e')]=_['keys'](_0x597cca[_0x9f40('0x2e')]);_0x552253[_0x9f40('0x2f')]=_['intersection'](_0x552253[_0x9f40('0x2c')],_0x552253[_0x9f40('0x2e')]);_0x2b7a70[_0x9f40('0x30')]=_['intersection'](_0x552253[_0x9f40('0x2c')],qs[_0x9f40('0x31')](_0x597cca['query'][_0x9f40('0x31')]));_0x2b7a70[_0x9f40('0x30')]=_0x2b7a70[_0x9f40('0x30')][_0x9f40('0x32')]?_0x2b7a70[_0x9f40('0x30')]:_0x552253['model'];if(!_0x597cca[_0x9f40('0x2e')][_0x9f40('0x33')]('nolimit')){_0x2b7a70['limit']=qs[_0x9f40('0x1c')](_0x597cca[_0x9f40('0x2e')][_0x9f40('0x1c')]);_0x2b7a70['offset']=qs[_0x9f40('0x1b')](_0x597cca[_0x9f40('0x2e')][_0x9f40('0x1b')]);}_0x2b7a70['order']=qs[_0x9f40('0x34')](_0x597cca[_0x9f40('0x2e')][_0x9f40('0x34')]);_0x2b7a70[_0x9f40('0x35')]=qs[_0x9f40('0x2f')](_[_0x9f40('0x36')](_0x597cca[_0x9f40('0x2e')],_0x552253[_0x9f40('0x2f')]),_0x3907eb);if(_0x597cca['query'][_0x9f40('0x37')]){_0x2b7a70[_0x9f40('0x35')]=_[_0x9f40('0x38')](_0x2b7a70[_0x9f40('0x35')],{'$or':_[_0x9f40('0x28')](_0x3907eb,function(_0x20ca9e){if(_0x20ca9e[_0x9f40('0x2b')]!==_0x9f40('0x39')){var _0x1ddfcd={};_0x1ddfcd[_0x20ca9e['name']]={'$like':'%'+_0x597cca[_0x9f40('0x2e')][_0x9f40('0x37')]+'%'};return _0x1ddfcd;}})});}_0x2b7a70=_[_0x9f40('0x38')]({},_0x2b7a70,_0x597cca[_0x9f40('0x3a')]);var _0x3e0b7f={'where':_0x2b7a70[_0x9f40('0x35')]};return db[_0x9f40('0x29')]['count'](_0x3e0b7f)[_0x9f40('0x23')](function(_0x2b0532){_0x3a7a61[_0x9f40('0x1a')]=_0x2b0532;if(_0x597cca[_0x9f40('0x2e')][_0x9f40('0x3b')]){_0x2b7a70[_0x9f40('0x3c')]=[{'all':!![]}];}return db[_0x9f40('0x29')][_0x9f40('0x3d')](_0x2b7a70);})['then'](function(_0x3e509b){_0x3a7a61['rows']=_0x3e509b;return _0x3a7a61;})[_0x9f40('0x23')](respondWithFilteredResult(_0x301255,_0x2b7a70))[_0x9f40('0x3e')](handleError(_0x301255,null));};exports[_0x9f40('0x3f')]=function(_0x559c40,_0x3b9ca7){var _0x5bb143={'raw':!![],'where':{'id':_0x559c40[_0x9f40('0x40')]['id']}},_0x2821dc={};_0x2821dc['model']=_[_0x9f40('0x41')](db[_0x9f40('0x29')][_0x9f40('0x2a')]);_0x2821dc['query']=_['keys'](_0x559c40[_0x9f40('0x2e')]);_0x2821dc[_0x9f40('0x2f')]=_[_0x9f40('0x42')](_0x2821dc[_0x9f40('0x2c')],_0x2821dc[_0x9f40('0x2e')]);_0x5bb143['attributes']=_['intersection'](_0x2821dc['model'],qs[_0x9f40('0x31')](_0x559c40[_0x9f40('0x2e')][_0x9f40('0x31')]));_0x5bb143['attributes']=_0x5bb143[_0x9f40('0x30')][_0x9f40('0x32')]?_0x5bb143[_0x9f40('0x30')]:_0x2821dc['model'];if(_0x559c40[_0x9f40('0x2e')][_0x9f40('0x3b')]){_0x5bb143[_0x9f40('0x3c')]=[{'all':!![]}];}_0x5bb143=_[_0x9f40('0x38')]({},_0x5bb143,_0x559c40[_0x9f40('0x3a')]);return db[_0x9f40('0x29')][_0x9f40('0x43')](_0x5bb143)[_0x9f40('0x23')](handleEntityNotFound(_0x3b9ca7,null))[_0x9f40('0x23')](respondWithResult(_0x3b9ca7,null))[_0x9f40('0x3e')](handleError(_0x3b9ca7,null));};exports['create']=function(_0x3a31d6,_0x22dde0){return db['SmsQueueReport'][_0x9f40('0x44')](_0x3a31d6['body'],{})[_0x9f40('0x23')](respondWithResult(_0x22dde0,0xc9))[_0x9f40('0x3e')](handleError(_0x22dde0,null));};exports[_0x9f40('0x22')]=function(_0x300d07,_0x2b452b){if(_0x300d07['body']['id']){delete _0x300d07[_0x9f40('0x45')]['id'];}return db[_0x9f40('0x29')]['find']({'where':{'id':_0x300d07['params']['id']}})[_0x9f40('0x23')](handleEntityNotFound(_0x2b452b,null))[_0x9f40('0x23')](saveUpdates(_0x300d07[_0x9f40('0x45')],null))[_0x9f40('0x23')](respondWithResult(_0x2b452b,null))[_0x9f40('0x3e')](handleError(_0x2b452b,null));};exports['destroy']=function(_0x33bbb9,_0x2b972a){return db[_0x9f40('0x29')]['find']({'where':{'id':_0x33bbb9[_0x9f40('0x40')]['id']}})[_0x9f40('0x23')](handleEntityNotFound(_0x2b972a,null))[_0x9f40('0x23')](removeEntity(_0x2b972a,null))['catch'](handleError(_0x2b972a,null));};exports[_0x9f40('0x46')]=function(_0x5a4d48,_0x2f0b21){return db[_0x9f40('0x29')][_0x9f40('0x46')]()['then'](respondWithResult(_0x2f0b21,null))['catch'](handleError(_0x2f0b21,null));};