2234bac89bbffe38923d25521034aeb12946ff98
[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 _0x82be=['catch','show','fields','includeAll','find','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','count','apply','reject','save','update','then','destroy','stack','send','map','SmsQueueReport','rawAttributes','fieldName','type','key','model','name','query','keys','filters','intersection','attributes','length','hasOwnProperty','limit','sort','where','filter','merge','VIRTUAL','options','include','findAll'];(function(_0x26bbd1,_0xb274f3){var _0x26b1eb=function(_0x4cf794){while(--_0x4cf794){_0x26bbd1['push'](_0x26bbd1['shift']());}};_0x26b1eb(++_0xb274f3);}(_0x82be,0x18f));var _0xe82b=function(_0xaa1316,_0x282b13){_0xaa1316=_0xaa1316-0x0;var _0x28866c=_0x82be[_0xaa1316];return _0x28866c;};'use strict';var emlformat=require(_0xe82b('0x0'));var rimraf=require(_0xe82b('0x1'));var zipdir=require(_0xe82b('0x2'));var jsonpatch=require(_0xe82b('0x3'));var rp=require(_0xe82b('0x4'));var moment=require(_0xe82b('0x5'));var BPromise=require(_0xe82b('0x6'));var Mustache=require(_0xe82b('0x7'));var util=require(_0xe82b('0x8'));var path=require('path');var sox=require(_0xe82b('0x9'));var csv=require('to-csv');var ejs=require(_0xe82b('0xa'));var fs=require('fs');var fs_extra=require(_0xe82b('0xb'));var _=require(_0xe82b('0xc'));var squel=require(_0xe82b('0xd'));var crypto=require(_0xe82b('0xe'));var jsforce=require(_0xe82b('0xf'));var deskjs=require(_0xe82b('0x10'));var toCsv=require(_0xe82b('0x11'));var querystring=require(_0xe82b('0x12'));var Papa=require(_0xe82b('0x13'));var Redis=require(_0xe82b('0x14'));var authService=require(_0xe82b('0x15'));var qs=require(_0xe82b('0x16'));var as=require(_0xe82b('0x17'));var hardwareService=require(_0xe82b('0x18'));var logger=require(_0xe82b('0x19'))(_0xe82b('0x1a'));var utils=require('../../config/utils');var config=require(_0xe82b('0x1b'));var licenseUtil=require(_0xe82b('0x1c'));var db=require(_0xe82b('0x1d'))['db'];function respondWithStatusCode(_0x4dbe45,_0x370765){_0x370765=_0x370765||0xcc;return function(_0x2207b3){if(_0x2207b3){return _0x4dbe45[_0xe82b('0x1e')](_0x370765);}return _0x4dbe45[_0xe82b('0x1f')](_0x370765)[_0xe82b('0x20')]();};}function respondWithResult(_0x2eb676,_0x4c5cc8){_0x4c5cc8=_0x4c5cc8||0xc8;return function(_0x113497){if(_0x113497){return _0x2eb676[_0xe82b('0x1f')](_0x4c5cc8)[_0xe82b('0x21')](_0x113497);}};}function respondWithFilteredResult(_0x4f23eb,_0x7346c8){return function(_0x31b814){if(_0x31b814){var _0x2e5dea=typeof _0x7346c8[_0xe82b('0x22')]===_0xe82b('0x23')&&typeof _0x7346c8['limit']==='undefined';var _0x4ced22=_0x31b814[_0xe82b('0x24')];var _0x37577d=_0x2e5dea?0x0:_0x7346c8[_0xe82b('0x22')];var _0xd8562=_0x2e5dea?_0x31b814['count']:_0x7346c8[_0xe82b('0x22')]+_0x7346c8['limit'];var _0x3fe5fa;if(_0xd8562>=_0x4ced22){_0xd8562=_0x4ced22;_0x3fe5fa=0xc8;}else{_0x3fe5fa=0xce;}_0x4f23eb[_0xe82b('0x1f')](_0x3fe5fa);return _0x4f23eb['set']('Content-Range',_0x37577d+'-'+_0xd8562+'/'+_0x4ced22)[_0xe82b('0x21')](_0x31b814);}return null;};}function patchUpdates(_0x1402cc){return function(_0x2f1abe){try{jsonpatch[_0xe82b('0x25')](_0x2f1abe,_0x1402cc,!![]);}catch(_0x557dbc){return BPromise[_0xe82b('0x26')](_0x557dbc);}return _0x2f1abe[_0xe82b('0x27')]();};}function saveUpdates(_0x48758b,_0x3fdfc5){return function(_0x55df50){if(_0x55df50){return _0x55df50[_0xe82b('0x28')](_0x48758b)[_0xe82b('0x29')](function(_0x45853e){return _0x45853e;});}return null;};}function removeEntity(_0x3e49d4,_0x2acb63){return function(_0x1c04f4){if(_0x1c04f4){return _0x1c04f4[_0xe82b('0x2a')]()[_0xe82b('0x29')](function(){_0x3e49d4[_0xe82b('0x1f')](0xcc)[_0xe82b('0x20')]();});}};}function handleEntityNotFound(_0x5dbada,_0x202903){return function(_0x39e8bf){if(!_0x39e8bf){_0x5dbada[_0xe82b('0x1e')](0x194);}return _0x39e8bf;};}function handleError(_0x27ddda,_0x122d80){_0x122d80=_0x122d80||0x1f4;return function(_0x513cbe){logger['error'](_0x513cbe[_0xe82b('0x2b')]);if(_0x513cbe['name']){delete _0x513cbe['name'];}_0x27ddda[_0xe82b('0x1f')](_0x122d80)[_0xe82b('0x2c')](_0x513cbe);};}exports['index']=function(_0x3a579c,_0x4124f4){var _0x2c5a4a={},_0x1cdf40={},_0x72137a={'count':0x0,'rows':[]};var _0x417f3c=_[_0xe82b('0x2d')](db[_0xe82b('0x2e')][_0xe82b('0x2f')],function(_0x288d8d){return{'name':_0x288d8d[_0xe82b('0x30')],'type':_0x288d8d[_0xe82b('0x31')][_0xe82b('0x32')]};});_0x1cdf40[_0xe82b('0x33')]=_[_0xe82b('0x2d')](_0x417f3c,_0xe82b('0x34'));_0x1cdf40[_0xe82b('0x35')]=_[_0xe82b('0x36')](_0x3a579c['query']);_0x1cdf40[_0xe82b('0x37')]=_[_0xe82b('0x38')](_0x1cdf40[_0xe82b('0x33')],_0x1cdf40['query']);_0x2c5a4a[_0xe82b('0x39')]=_[_0xe82b('0x38')](_0x1cdf40[_0xe82b('0x33')],qs['fields'](_0x3a579c[_0xe82b('0x35')]['fields']));_0x2c5a4a[_0xe82b('0x39')]=_0x2c5a4a[_0xe82b('0x39')][_0xe82b('0x3a')]?_0x2c5a4a['attributes']:_0x1cdf40[_0xe82b('0x33')];if(!_0x3a579c[_0xe82b('0x35')][_0xe82b('0x3b')]('nolimit')){_0x2c5a4a[_0xe82b('0x3c')]=qs[_0xe82b('0x3c')](_0x3a579c[_0xe82b('0x35')][_0xe82b('0x3c')]);_0x2c5a4a[_0xe82b('0x22')]=qs[_0xe82b('0x22')](_0x3a579c[_0xe82b('0x35')][_0xe82b('0x22')]);}_0x2c5a4a['order']=qs[_0xe82b('0x3d')](_0x3a579c[_0xe82b('0x35')]['sort']);_0x2c5a4a[_0xe82b('0x3e')]=qs['filters'](_['pick'](_0x3a579c[_0xe82b('0x35')],_0x1cdf40[_0xe82b('0x37')]),_0x417f3c);if(_0x3a579c[_0xe82b('0x35')][_0xe82b('0x3f')]){_0x2c5a4a[_0xe82b('0x3e')]=_[_0xe82b('0x40')](_0x2c5a4a[_0xe82b('0x3e')],{'$or':_[_0xe82b('0x2d')](_0x417f3c,function(_0x4d8a92){if(_0x4d8a92['type']!==_0xe82b('0x41')){var _0x5b9545={};_0x5b9545[_0x4d8a92[_0xe82b('0x34')]]={'$like':'%'+_0x3a579c[_0xe82b('0x35')][_0xe82b('0x3f')]+'%'};return _0x5b9545;}})});}_0x2c5a4a=_[_0xe82b('0x40')]({},_0x2c5a4a,_0x3a579c[_0xe82b('0x42')]);var _0x3a3c0a={'where':_0x2c5a4a['where']};return db[_0xe82b('0x2e')][_0xe82b('0x24')](_0x3a3c0a)['then'](function(_0x1434cc){_0x72137a[_0xe82b('0x24')]=_0x1434cc;if(_0x3a579c[_0xe82b('0x35')]['includeAll']){_0x2c5a4a[_0xe82b('0x43')]=[{'all':!![]}];}return db[_0xe82b('0x2e')][_0xe82b('0x44')](_0x2c5a4a);})['then'](function(_0xc852f4){_0x72137a['rows']=_0xc852f4;return _0x72137a;})[_0xe82b('0x29')](respondWithFilteredResult(_0x4124f4,_0x2c5a4a))[_0xe82b('0x45')](handleError(_0x4124f4,null));};exports[_0xe82b('0x46')]=function(_0xf8fc10,_0x8b0ea6){var _0x1dddbd={'raw':!![],'where':{'id':_0xf8fc10['params']['id']}},_0x112b12={};_0x112b12[_0xe82b('0x33')]=_[_0xe82b('0x36')](db[_0xe82b('0x2e')][_0xe82b('0x2f')]);_0x112b12[_0xe82b('0x35')]=_[_0xe82b('0x36')](_0xf8fc10['query']);_0x112b12['filters']=_[_0xe82b('0x38')](_0x112b12['model'],_0x112b12[_0xe82b('0x35')]);_0x1dddbd['attributes']=_[_0xe82b('0x38')](_0x112b12[_0xe82b('0x33')],qs[_0xe82b('0x47')](_0xf8fc10[_0xe82b('0x35')][_0xe82b('0x47')]));_0x1dddbd[_0xe82b('0x39')]=_0x1dddbd['attributes'][_0xe82b('0x3a')]?_0x1dddbd[_0xe82b('0x39')]:_0x112b12['model'];if(_0xf8fc10[_0xe82b('0x35')][_0xe82b('0x48')]){_0x1dddbd[_0xe82b('0x43')]=[{'all':!![]}];}_0x1dddbd=_[_0xe82b('0x40')]({},_0x1dddbd,_0xf8fc10['options']);return db[_0xe82b('0x2e')][_0xe82b('0x49')](_0x1dddbd)[_0xe82b('0x29')](handleEntityNotFound(_0x8b0ea6,null))[_0xe82b('0x29')](respondWithResult(_0x8b0ea6,null))[_0xe82b('0x45')](handleError(_0x8b0ea6,null));};exports[_0xe82b('0x4a')]=function(_0xc60a66,_0x19c2c8){return db[_0xe82b('0x2e')]['create'](_0xc60a66[_0xe82b('0x4b')],{})[_0xe82b('0x29')](respondWithResult(_0x19c2c8,0xc9))[_0xe82b('0x45')](handleError(_0x19c2c8,null));};exports[_0xe82b('0x28')]=function(_0xc13415,_0x1b2066){if(_0xc13415['body']['id']){delete _0xc13415[_0xe82b('0x4b')]['id'];}return db[_0xe82b('0x2e')][_0xe82b('0x49')]({'where':{'id':_0xc13415[_0xe82b('0x4c')]['id']}})[_0xe82b('0x29')](handleEntityNotFound(_0x1b2066,null))[_0xe82b('0x29')](saveUpdates(_0xc13415[_0xe82b('0x4b')],null))[_0xe82b('0x29')](respondWithResult(_0x1b2066,null))[_0xe82b('0x45')](handleError(_0x1b2066,null));};exports[_0xe82b('0x2a')]=function(_0x487cd2,_0xcdafef){return db[_0xe82b('0x2e')][_0xe82b('0x49')]({'where':{'id':_0x487cd2['params']['id']}})[_0xe82b('0x29')](handleEntityNotFound(_0xcdafef,null))[_0xe82b('0x29')](removeEntity(_0xcdafef,null))['catch'](handleError(_0xcdafef,null));};exports[_0xe82b('0x4d')]=function(_0x227f6d,_0x26b02e){return db[_0xe82b('0x2e')]['describe']()[_0xe82b('0x29')](respondWithResult(_0x26b02e,null))[_0xe82b('0x45')](handleError(_0x26b02e,null));};