Built motion from commit 37e1ed56.|2.6.29
[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 _0x962f=['body','find','params','describe','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','jsforce','desk.js','querystring','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','offset','undefined','count','limit','Content-Range','json','apply','reject','save','update','then','destroy','error','stack','name','send','index','map','SmsQueueReport','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','merge','VIRTUAL','filter','findAll','show','includeAll','include','catch','create'];(function(_0x356818,_0x2b6695){var _0x42322a=function(_0xb642fd){while(--_0xb642fd){_0x356818['push'](_0x356818['shift']());}};_0x42322a(++_0x2b6695);}(_0x962f,0x12c));var _0xf962=function(_0x20a584,_0xe384a5){_0x20a584=_0x20a584-0x0;var _0x4b41a8=_0x962f[_0x20a584];return _0x4b41a8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0xf962('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0xf962('0x1'));var rp=require(_0xf962('0x2'));var moment=require('moment');var BPromise=require(_0xf962('0x3'));var Mustache=require(_0xf962('0x4'));var util=require(_0xf962('0x5'));var path=require('path');var sox=require(_0xf962('0x6'));var csv=require(_0xf962('0x7'));var ejs=require(_0xf962('0x8'));var fs=require('fs');var fs_extra=require(_0xf962('0x9'));var _=require(_0xf962('0xa'));var squel=require(_0xf962('0xb'));var crypto=require('crypto');var jsforce=require(_0xf962('0xc'));var deskjs=require(_0xf962('0xd'));var toCsv=require(_0xf962('0x7'));var querystring=require(_0xf962('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf962('0xf'));var logger=require(_0xf962('0x10'))(_0xf962('0x11'));var utils=require('../../config/utils');var config=require(_0xf962('0x12'));var licenseUtil=require(_0xf962('0x13'));var db=require(_0xf962('0x14'))['db'];function respondWithStatusCode(_0x1a25bf,_0x152a05){_0x152a05=_0x152a05||0xcc;return function(_0x4955d6){if(_0x4955d6){return _0x1a25bf[_0xf962('0x15')](_0x152a05);}return _0x1a25bf[_0xf962('0x16')](_0x152a05)[_0xf962('0x17')]();};}function respondWithResult(_0x413eac,_0x7baa85){_0x7baa85=_0x7baa85||0xc8;return function(_0x404178){if(_0x404178){return _0x413eac[_0xf962('0x16')](_0x7baa85)['json'](_0x404178);}};}function respondWithFilteredResult(_0x424167,_0xb66547){return function(_0x528445){if(_0x528445){var _0x5dfa68=typeof _0xb66547[_0xf962('0x18')]===_0xf962('0x19')&&typeof _0xb66547['limit']===_0xf962('0x19');var _0x444d3a=_0x528445[_0xf962('0x1a')];var _0xff2bb2=_0x5dfa68?0x0:_0xb66547[_0xf962('0x18')];var _0x5cbc8f=_0x5dfa68?_0x528445[_0xf962('0x1a')]:_0xb66547[_0xf962('0x18')]+_0xb66547[_0xf962('0x1b')];var _0x5fea81;if(_0x5cbc8f>=_0x444d3a){_0x5cbc8f=_0x444d3a;_0x5fea81=0xc8;}else{_0x5fea81=0xce;}_0x424167[_0xf962('0x16')](_0x5fea81);return _0x424167['set'](_0xf962('0x1c'),_0xff2bb2+'-'+_0x5cbc8f+'/'+_0x444d3a)[_0xf962('0x1d')](_0x528445);}return null;};}function patchUpdates(_0x16bfb5){return function(_0x3ae283){try{jsonpatch[_0xf962('0x1e')](_0x3ae283,_0x16bfb5,!![]);}catch(_0x1cd996){return BPromise[_0xf962('0x1f')](_0x1cd996);}return _0x3ae283[_0xf962('0x20')]();};}function saveUpdates(_0x19f7ef,_0x8c8d12){return function(_0xa91dc){if(_0xa91dc){return _0xa91dc[_0xf962('0x21')](_0x19f7ef)[_0xf962('0x22')](function(_0x4431e8){return _0x4431e8;});}return null;};}function removeEntity(_0x5cee56,_0x183014){return function(_0x386291){if(_0x386291){return _0x386291[_0xf962('0x23')]()['then'](function(){_0x5cee56['status'](0xcc)[_0xf962('0x17')]();});}};}function handleEntityNotFound(_0xd0d745,_0x21beb1){return function(_0x402169){if(!_0x402169){_0xd0d745[_0xf962('0x15')](0x194);}return _0x402169;};}function handleError(_0x5ef9ee,_0x1fc177){_0x1fc177=_0x1fc177||0x1f4;return function(_0x318902){logger[_0xf962('0x24')](_0x318902[_0xf962('0x25')]);if(_0x318902['name']){delete _0x318902[_0xf962('0x26')];}_0x5ef9ee[_0xf962('0x16')](_0x1fc177)[_0xf962('0x27')](_0x318902);};}exports[_0xf962('0x28')]=function(_0x429100,_0x5bba78){var _0x4961de={},_0x45f3a4={},_0x9618fe={'count':0x0,'rows':[]};var _0x1294b5=_[_0xf962('0x29')](db[_0xf962('0x2a')][_0xf962('0x2b')],function(_0x4f4f34){return{'name':_0x4f4f34[_0xf962('0x2c')],'type':_0x4f4f34[_0xf962('0x2d')][_0xf962('0x2e')]};});_0x45f3a4[_0xf962('0x2f')]=_[_0xf962('0x29')](_0x1294b5,'name');_0x45f3a4[_0xf962('0x30')]=_[_0xf962('0x31')](_0x429100[_0xf962('0x30')]);_0x45f3a4['filters']=_[_0xf962('0x32')](_0x45f3a4[_0xf962('0x2f')],_0x45f3a4[_0xf962('0x30')]);_0x4961de[_0xf962('0x33')]=_[_0xf962('0x32')](_0x45f3a4[_0xf962('0x2f')],qs['fields'](_0x429100[_0xf962('0x30')][_0xf962('0x34')]));_0x4961de[_0xf962('0x33')]=_0x4961de[_0xf962('0x33')][_0xf962('0x35')]?_0x4961de[_0xf962('0x33')]:_0x45f3a4['model'];if(!_0x429100[_0xf962('0x30')][_0xf962('0x36')](_0xf962('0x37'))){_0x4961de['limit']=qs['limit'](_0x429100[_0xf962('0x30')]['limit']);_0x4961de['offset']=qs[_0xf962('0x18')](_0x429100[_0xf962('0x30')][_0xf962('0x18')]);}_0x4961de[_0xf962('0x38')]=qs[_0xf962('0x39')](_0x429100[_0xf962('0x30')][_0xf962('0x39')]);_0x4961de[_0xf962('0x3a')]=qs[_0xf962('0x3b')](_[_0xf962('0x3c')](_0x429100[_0xf962('0x30')],_0x45f3a4['filters']),_0x1294b5);if(_0x429100[_0xf962('0x30')]['filter']){_0x4961de[_0xf962('0x3a')]=_[_0xf962('0x3d')](_0x4961de[_0xf962('0x3a')],{'$or':_[_0xf962('0x29')](_0x1294b5,function(_0x13f083){if(_0x13f083[_0xf962('0x2d')]!==_0xf962('0x3e')){var _0xc8f5a7={};_0xc8f5a7[_0x13f083[_0xf962('0x26')]]={'$like':'%'+_0x429100[_0xf962('0x30')][_0xf962('0x3f')]+'%'};return _0xc8f5a7;}})});}_0x4961de=_[_0xf962('0x3d')]({},_0x4961de,_0x429100['options']);var _0x3af549={'where':_0x4961de[_0xf962('0x3a')]};return db[_0xf962('0x2a')][_0xf962('0x1a')](_0x3af549)['then'](function(_0x473143){_0x9618fe[_0xf962('0x1a')]=_0x473143;if(_0x429100['query']['includeAll']){_0x4961de['include']=[{'all':!![]}];}return db['SmsQueueReport'][_0xf962('0x40')](_0x4961de);})[_0xf962('0x22')](function(_0x2d6ad8){_0x9618fe['rows']=_0x2d6ad8;return _0x9618fe;})[_0xf962('0x22')](respondWithFilteredResult(_0x5bba78,_0x4961de))['catch'](handleError(_0x5bba78,null));};exports[_0xf962('0x41')]=function(_0x545815,_0x224963){var _0x2e2a10={'raw':!![],'where':{'id':_0x545815['params']['id']}},_0xd32be1={};_0xd32be1[_0xf962('0x2f')]=_[_0xf962('0x31')](db[_0xf962('0x2a')][_0xf962('0x2b')]);_0xd32be1[_0xf962('0x30')]=_['keys'](_0x545815[_0xf962('0x30')]);_0xd32be1[_0xf962('0x3b')]=_['intersection'](_0xd32be1['model'],_0xd32be1[_0xf962('0x30')]);_0x2e2a10[_0xf962('0x33')]=_[_0xf962('0x32')](_0xd32be1['model'],qs['fields'](_0x545815['query'][_0xf962('0x34')]));_0x2e2a10['attributes']=_0x2e2a10['attributes']['length']?_0x2e2a10['attributes']:_0xd32be1[_0xf962('0x2f')];if(_0x545815[_0xf962('0x30')][_0xf962('0x42')]){_0x2e2a10[_0xf962('0x43')]=[{'all':!![]}];}_0x2e2a10=_['merge']({},_0x2e2a10,_0x545815['options']);return db[_0xf962('0x2a')]['find'](_0x2e2a10)[_0xf962('0x22')](handleEntityNotFound(_0x224963,null))[_0xf962('0x22')](respondWithResult(_0x224963,null))[_0xf962('0x44')](handleError(_0x224963,null));};exports[_0xf962('0x45')]=function(_0x366308,_0x477261){return db[_0xf962('0x2a')][_0xf962('0x45')](_0x366308['body'],{})['then'](respondWithResult(_0x477261,0xc9))[_0xf962('0x44')](handleError(_0x477261,null));};exports['update']=function(_0x535321,_0x14be6d){if(_0x535321[_0xf962('0x46')]['id']){delete _0x535321[_0xf962('0x46')]['id'];}return db[_0xf962('0x2a')][_0xf962('0x47')]({'where':{'id':_0x535321[_0xf962('0x48')]['id']}})[_0xf962('0x22')](handleEntityNotFound(_0x14be6d,null))[_0xf962('0x22')](saveUpdates(_0x535321[_0xf962('0x46')],null))[_0xf962('0x22')](respondWithResult(_0x14be6d,null))['catch'](handleError(_0x14be6d,null));};exports[_0xf962('0x23')]=function(_0x243619,_0xaa730c){return db['SmsQueueReport']['find']({'where':{'id':_0x243619['params']['id']}})[_0xf962('0x22')](handleEntityNotFound(_0xaa730c,null))['then'](removeEntity(_0xaa730c,null))[_0xf962('0x44')](handleError(_0xaa730c,null));};exports['describe']=function(_0x3a99cb,_0x96c959){return db[_0xf962('0x2a')][_0xf962('0x49')]()['then'](respondWithResult(_0x96c959,null))['catch'](handleError(_0x96c959,null));};