e549748e3dac49d74e0b208508d709603bb8d3ef
[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 _0x6f94=['json','count','offset','limit','set','Content-Range','apply','reject','update','destroy','then','stack','name','send','index','map','SmsQueueReport','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','mustache','sox','to-csv','crypto','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end'];(function(_0x4b4e8f,_0x3ab560){var _0x347232=function(_0xc04d11){while(--_0xc04d11){_0x4b4e8f['push'](_0x4b4e8f['shift']());}};_0x347232(++_0x3ab560);}(_0x6f94,0x198));var _0x46f9=function(_0x1b6186,_0x1ec7f2){_0x1b6186=_0x1b6186-0x0;var _0x186121=_0x6f94[_0x1b6186];return _0x186121;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x46f9('0x0'));var rimraf=require(_0x46f9('0x1'));var zipdir=require(_0x46f9('0x2'));var jsonpatch=require(_0x46f9('0x3'));var rp=require('request-promise');var moment=require(_0x46f9('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x46f9('0x5'));var util=require('util');var path=require('path');var sox=require(_0x46f9('0x6'));var csv=require(_0x46f9('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0x46f9('0x8'));var jsforce=require(_0x46f9('0x9'));var deskjs=require(_0x46f9('0xa'));var toCsv=require(_0x46f9('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x46f9('0xb'));var authService=require(_0x46f9('0xc'));var qs=require(_0x46f9('0xd'));var as=require(_0x46f9('0xe'));var hardwareService=require(_0x46f9('0xf'));var logger=require(_0x46f9('0x10'))(_0x46f9('0x11'));var utils=require(_0x46f9('0x12'));var config=require('../../config/environment');var licenseUtil=require(_0x46f9('0x13'));var db=require(_0x46f9('0x14'))['db'];function respondWithStatusCode(_0x5a5cec,_0x200df8){_0x200df8=_0x200df8||0xcc;return function(_0xe48ef7){if(_0xe48ef7){return _0x5a5cec[_0x46f9('0x15')](_0x200df8);}return _0x5a5cec[_0x46f9('0x16')](_0x200df8)[_0x46f9('0x17')]();};}function respondWithResult(_0x4c02c3,_0x3101c8){_0x3101c8=_0x3101c8||0xc8;return function(_0x4bc594){if(_0x4bc594){return _0x4c02c3[_0x46f9('0x16')](_0x3101c8)[_0x46f9('0x18')](_0x4bc594);}};}function respondWithFilteredResult(_0x45a6e6,_0x595790){return function(_0x241425){if(_0x241425){var _0xba4de7=_0x241425[_0x46f9('0x19')],_0x1552fe=_0x595790[_0x46f9('0x1a')],_0x4b8993=_0x595790[_0x46f9('0x1a')]+_0x595790[_0x46f9('0x1b')],_0x485500;if(_0x4b8993>=_0xba4de7){_0x4b8993=_0xba4de7;_0x485500=0xc8;}else{_0x485500=0xce;}_0x45a6e6[_0x46f9('0x16')](_0x485500);return _0x45a6e6[_0x46f9('0x1c')](_0x46f9('0x1d'),_0x1552fe+'-'+_0x4b8993+'/'+_0xba4de7)[_0x46f9('0x18')](_0x241425);}return null;};}function patchUpdates(_0x420f0d){return function(_0x492906){try{jsonpatch[_0x46f9('0x1e')](_0x492906,_0x420f0d,!![]);}catch(_0x1f1ecf){return BPromise[_0x46f9('0x1f')](_0x1f1ecf);}return _0x492906['save']();};}function saveUpdates(_0x417169,_0xf90a93){return function(_0x220097){if(_0x220097){return _0x220097[_0x46f9('0x20')](_0x417169)['then'](function(_0x569b89){return _0x569b89;});}return null;};}function removeEntity(_0x530ae9,_0x28911f){return function(_0x41af01){if(_0x41af01){return _0x41af01[_0x46f9('0x21')]()[_0x46f9('0x22')](function(){_0x530ae9[_0x46f9('0x16')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3da8be,_0x3a301e){return function(_0x2da87a){if(!_0x2da87a){_0x3da8be[_0x46f9('0x15')](0x194);}return _0x2da87a;};}function handleError(_0x6a535e,_0x430b49){_0x430b49=_0x430b49||0x1f4;return function(_0x3e2190){logger['error'](_0x3e2190[_0x46f9('0x23')]);if(_0x3e2190[_0x46f9('0x24')]){delete _0x3e2190[_0x46f9('0x24')];}_0x6a535e['status'](_0x430b49)[_0x46f9('0x25')](_0x3e2190);};}exports[_0x46f9('0x26')]=function(_0x5631b3,_0x5b4952){var _0x255199={},_0x390b89={},_0x28a635={'count':0x0,'rows':[]};var _0x1ace61=_[_0x46f9('0x27')](db[_0x46f9('0x28')][_0x46f9('0x29')],function(_0x13ff4c){return{'name':_0x13ff4c[_0x46f9('0x2a')],'type':_0x13ff4c[_0x46f9('0x2b')][_0x46f9('0x2c')]};});_0x390b89[_0x46f9('0x2d')]=_['map'](_0x1ace61,_0x46f9('0x24'));_0x390b89[_0x46f9('0x2e')]=_[_0x46f9('0x2f')](_0x5631b3[_0x46f9('0x2e')]);_0x390b89[_0x46f9('0x30')]=_[_0x46f9('0x31')](_0x390b89['model'],_0x390b89['query']);_0x255199[_0x46f9('0x32')]=_[_0x46f9('0x31')](_0x390b89[_0x46f9('0x2d')],qs['fields'](_0x5631b3[_0x46f9('0x2e')][_0x46f9('0x33')]));_0x255199['attributes']=_0x255199[_0x46f9('0x32')][_0x46f9('0x34')]?_0x255199[_0x46f9('0x32')]:_0x390b89[_0x46f9('0x2d')];if(!_0x5631b3['query']['hasOwnProperty'](_0x46f9('0x35'))){_0x255199[_0x46f9('0x1b')]=qs[_0x46f9('0x1b')](_0x5631b3[_0x46f9('0x2e')][_0x46f9('0x1b')]);_0x255199[_0x46f9('0x1a')]=qs[_0x46f9('0x1a')](_0x5631b3['query'][_0x46f9('0x1a')]);}_0x255199[_0x46f9('0x36')]=qs['sort'](_0x5631b3[_0x46f9('0x2e')][_0x46f9('0x37')]);_0x255199['where']=qs[_0x46f9('0x30')](_[_0x46f9('0x38')](_0x5631b3[_0x46f9('0x2e')],_0x390b89[_0x46f9('0x30')]),_0x1ace61);if(_0x5631b3[_0x46f9('0x2e')][_0x46f9('0x39')]){_0x255199[_0x46f9('0x3a')]=_[_0x46f9('0x3b')](_0x255199[_0x46f9('0x3a')],{'$or':_[_0x46f9('0x27')](_0x1ace61,function(_0x5c2d85){if(_0x5c2d85[_0x46f9('0x2b')]!==_0x46f9('0x3c')){var _0x291816={};_0x291816[_0x5c2d85[_0x46f9('0x24')]]={'$like':'%'+_0x5631b3[_0x46f9('0x2e')][_0x46f9('0x39')]+'%'};return _0x291816;}})});}_0x255199=_[_0x46f9('0x3b')]({},_0x255199,_0x5631b3[_0x46f9('0x3d')]);var _0x13e521={'where':_0x255199['where']};return db[_0x46f9('0x28')][_0x46f9('0x19')](_0x13e521)[_0x46f9('0x22')](function(_0xe97461){_0x28a635['count']=_0xe97461;if(_0x5631b3['query'][_0x46f9('0x3e')]){_0x255199[_0x46f9('0x3f')]=[{'all':!![]}];}return db[_0x46f9('0x28')][_0x46f9('0x40')](_0x255199);})[_0x46f9('0x22')](function(_0xc2f36d){_0x28a635['rows']=_0xc2f36d;return _0x28a635;})['then'](respondWithFilteredResult(_0x5b4952,_0x255199))[_0x46f9('0x41')](handleError(_0x5b4952,null));};exports[_0x46f9('0x42')]=function(_0x353739,_0x3b438f){var _0x3af0c7={'raw':!![],'where':{'id':_0x353739[_0x46f9('0x43')]['id']}},_0x4952fd={};_0x4952fd[_0x46f9('0x2d')]=_['keys'](db[_0x46f9('0x28')][_0x46f9('0x29')]);_0x4952fd[_0x46f9('0x2e')]=_[_0x46f9('0x2f')](_0x353739['query']);_0x4952fd[_0x46f9('0x30')]=_['intersection'](_0x4952fd[_0x46f9('0x2d')],_0x4952fd[_0x46f9('0x2e')]);_0x3af0c7[_0x46f9('0x32')]=_['intersection'](_0x4952fd[_0x46f9('0x2d')],qs[_0x46f9('0x33')](_0x353739[_0x46f9('0x2e')]['fields']));_0x3af0c7[_0x46f9('0x32')]=_0x3af0c7[_0x46f9('0x32')][_0x46f9('0x34')]?_0x3af0c7['attributes']:_0x4952fd[_0x46f9('0x2d')];if(_0x353739['query'][_0x46f9('0x3e')]){_0x3af0c7[_0x46f9('0x3f')]=[{'all':!![]}];}_0x3af0c7=_[_0x46f9('0x3b')]({},_0x3af0c7,_0x353739[_0x46f9('0x3d')]);return db[_0x46f9('0x28')][_0x46f9('0x44')](_0x3af0c7)[_0x46f9('0x22')](handleEntityNotFound(_0x3b438f,null))['then'](respondWithResult(_0x3b438f,null))['catch'](handleError(_0x3b438f,null));};exports[_0x46f9('0x45')]=function(_0x28c06e,_0x448b88){return db[_0x46f9('0x28')][_0x46f9('0x45')](_0x28c06e[_0x46f9('0x46')],{})[_0x46f9('0x22')](respondWithResult(_0x448b88,0xc9))[_0x46f9('0x41')](handleError(_0x448b88,null));};exports[_0x46f9('0x20')]=function(_0x2390f7,_0x207ca4){if(_0x2390f7[_0x46f9('0x46')]['id']){delete _0x2390f7[_0x46f9('0x46')]['id'];}return db[_0x46f9('0x28')][_0x46f9('0x44')]({'where':{'id':_0x2390f7[_0x46f9('0x43')]['id']}})[_0x46f9('0x22')](handleEntityNotFound(_0x207ca4,null))['then'](saveUpdates(_0x2390f7[_0x46f9('0x46')],null))[_0x46f9('0x22')](respondWithResult(_0x207ca4,null))[_0x46f9('0x41')](handleError(_0x207ca4,null));};exports[_0x46f9('0x21')]=function(_0x1d38d8,_0x31b5b5){return db['SmsQueueReport'][_0x46f9('0x44')]({'where':{'id':_0x1d38d8[_0x46f9('0x43')]['id']}})[_0x46f9('0x22')](handleEntityNotFound(_0x31b5b5,null))[_0x46f9('0x22')](removeEntity(_0x31b5b5,null))[_0x46f9('0x41')](handleError(_0x31b5b5,null));};exports[_0x46f9('0x47')]=function(_0x147600,_0x2a5149){return db['SmsQueueReport'][_0x46f9('0x47')]()[_0x46f9('0x22')](respondWithResult(_0x2a5149,null))[_0x46f9('0x41')](handleError(_0x2a5149,null));};