Built motion from commit (unavailable).|2.5.14
[motion2.git] / server / api / whatsappQueueReport / whatsappQueueReport.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 _0x0f48=['findAll','rows','catch','show','params','length','includeAll','find','create','body','destroy','describe','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','ejs','lodash','squel','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','WhatsappQueueReport','rawAttributes','type','key','model','query','keys','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','filters','filter','merge','where','VIRTUAL','options','include'];(function(_0x40aa31,_0x175b59){var _0x393c74=function(_0x119817){while(--_0x119817){_0x40aa31['push'](_0x40aa31['shift']());}};_0x393c74(++_0x175b59);}(_0x0f48,0xe4));var _0x80f4=function(_0x13ca25,_0x4c40dc){_0x13ca25=_0x13ca25-0x0;var _0x50730c=_0x0f48[_0x13ca25];return _0x50730c;};'use strict';var pdf=require(_0x80f4('0x0'));var emlformat=require(_0x80f4('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x80f4('0x2'));var jsonpatch=require(_0x80f4('0x3'));var rp=require(_0x80f4('0x4'));var moment=require(_0x80f4('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x80f4('0x6'));var util=require('util');var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x80f4('0x7'));var fs=require('fs');var _=require(_0x80f4('0x8'));var squel=require(_0x80f4('0x9'));var crypto=require('crypto');var jsforce=require(_0x80f4('0xa'));var deskjs=require(_0x80f4('0xb'));var toCsv=require('to-csv');var querystring=require(_0x80f4('0xc'));var Papa=require(_0x80f4('0xd'));var Redis=require(_0x80f4('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x80f4('0xf'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x80f4('0x10'));var utils=require(_0x80f4('0x11'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x80f4('0x12'))['db'];function respondWithStatusCode(_0x144e37,_0x1eae35){_0x1eae35=_0x1eae35||0xcc;return function(_0x39d4ed){if(_0x39d4ed){return _0x144e37[_0x80f4('0x13')](_0x1eae35);}return _0x144e37[_0x80f4('0x14')](_0x1eae35)[_0x80f4('0x15')]();};}function respondWithResult(_0x46dafa,_0x417153){_0x417153=_0x417153||0xc8;return function(_0x52cbdc){if(_0x52cbdc){return _0x46dafa[_0x80f4('0x14')](_0x417153)[_0x80f4('0x16')](_0x52cbdc);}};}function respondWithFilteredResult(_0x2b1650,_0x43527b){return function(_0x532df9){if(_0x532df9){var _0x5504dd=_0x532df9[_0x80f4('0x17')],_0x17535a=_0x43527b[_0x80f4('0x18')],_0x17f844=_0x43527b[_0x80f4('0x18')]+_0x43527b[_0x80f4('0x19')],_0x3fa909;if(_0x17f844>=_0x5504dd){_0x17f844=_0x5504dd;_0x3fa909=0xc8;}else{_0x3fa909=0xce;}_0x2b1650[_0x80f4('0x14')](_0x3fa909);return _0x2b1650[_0x80f4('0x1a')](_0x80f4('0x1b'),_0x17535a+'-'+_0x17f844+'/'+_0x5504dd)['json'](_0x532df9);}return null;};}function patchUpdates(_0x9d047e){return function(_0x2a633e){try{jsonpatch[_0x80f4('0x1c')](_0x2a633e,_0x9d047e,!![]);}catch(_0x351233){return BPromise[_0x80f4('0x1d')](_0x351233);}return _0x2a633e[_0x80f4('0x1e')]();};}function saveUpdates(_0x51b501,_0x31af03){return function(_0x15689f){if(_0x15689f){return _0x15689f[_0x80f4('0x1f')](_0x51b501)[_0x80f4('0x20')](function(_0x495739){return _0x495739;});}return null;};}function removeEntity(_0x375f37,_0x57e907){return function(_0x3416d1){if(_0x3416d1){return _0x3416d1['destroy']()['then'](function(){_0x375f37['status'](0xcc)[_0x80f4('0x15')]();});}};}function handleEntityNotFound(_0x36b84b,_0x21b261){return function(_0x47abab){if(!_0x47abab){_0x36b84b[_0x80f4('0x13')](0x194);}return _0x47abab;};}function handleError(_0x51c4e6,_0x306f7d){_0x306f7d=_0x306f7d||0x1f4;return function(_0x202f69){logger[_0x80f4('0x21')](_0x202f69[_0x80f4('0x22')]);if(_0x202f69['name']){delete _0x202f69[_0x80f4('0x23')];}_0x51c4e6[_0x80f4('0x14')](_0x306f7d)[_0x80f4('0x24')](_0x202f69);};}exports[_0x80f4('0x25')]=function(_0x51104f,_0x2211b9){var _0x1e9721={},_0x1ac2bb={},_0x501452={'count':0x0,'rows':[]};var _0x2d7594=_[_0x80f4('0x26')](db[_0x80f4('0x27')][_0x80f4('0x28')],function(_0x20d3ed){return{'name':_0x20d3ed['fieldName'],'type':_0x20d3ed[_0x80f4('0x29')][_0x80f4('0x2a')]};});_0x1ac2bb[_0x80f4('0x2b')]=_['map'](_0x2d7594,_0x80f4('0x23'));_0x1ac2bb[_0x80f4('0x2c')]=_[_0x80f4('0x2d')](_0x51104f['query']);_0x1ac2bb['filters']=_[_0x80f4('0x2e')](_0x1ac2bb[_0x80f4('0x2b')],_0x1ac2bb[_0x80f4('0x2c')]);_0x1e9721[_0x80f4('0x2f')]=_[_0x80f4('0x2e')](_0x1ac2bb[_0x80f4('0x2b')],qs['fields'](_0x51104f['query'][_0x80f4('0x30')]));_0x1e9721[_0x80f4('0x2f')]=_0x1e9721[_0x80f4('0x2f')]['length']?_0x1e9721[_0x80f4('0x2f')]:_0x1ac2bb[_0x80f4('0x2b')];if(!_0x51104f[_0x80f4('0x2c')][_0x80f4('0x31')](_0x80f4('0x32'))){_0x1e9721[_0x80f4('0x19')]=qs[_0x80f4('0x19')](_0x51104f[_0x80f4('0x2c')]['limit']);_0x1e9721[_0x80f4('0x18')]=qs[_0x80f4('0x18')](_0x51104f[_0x80f4('0x2c')][_0x80f4('0x18')]);}_0x1e9721[_0x80f4('0x33')]=qs['sort'](_0x51104f[_0x80f4('0x2c')][_0x80f4('0x34')]);_0x1e9721['where']=qs[_0x80f4('0x35')](_['pick'](_0x51104f[_0x80f4('0x2c')],_0x1ac2bb[_0x80f4('0x35')]),_0x2d7594);if(_0x51104f['query'][_0x80f4('0x36')]){_0x1e9721['where']=_[_0x80f4('0x37')](_0x1e9721[_0x80f4('0x38')],{'$or':_[_0x80f4('0x26')](_0x2d7594,function(_0x3d2f4f){if(_0x3d2f4f[_0x80f4('0x29')]!==_0x80f4('0x39')){var _0x189674={};_0x189674[_0x3d2f4f['name']]={'$like':'%'+_0x51104f[_0x80f4('0x2c')][_0x80f4('0x36')]+'%'};return _0x189674;}})});}_0x1e9721=_['merge']({},_0x1e9721,_0x51104f[_0x80f4('0x3a')]);var _0x2410ae={'where':_0x1e9721[_0x80f4('0x38')]};return db[_0x80f4('0x27')][_0x80f4('0x17')](_0x2410ae)[_0x80f4('0x20')](function(_0x578677){_0x501452['count']=_0x578677;if(_0x51104f[_0x80f4('0x2c')]['includeAll']){_0x1e9721[_0x80f4('0x3b')]=[{'all':!![]}];}return db[_0x80f4('0x27')][_0x80f4('0x3c')](_0x1e9721);})[_0x80f4('0x20')](function(_0x53e753){_0x501452[_0x80f4('0x3d')]=_0x53e753;return _0x501452;})[_0x80f4('0x20')](respondWithFilteredResult(_0x2211b9,_0x1e9721))[_0x80f4('0x3e')](handleError(_0x2211b9,null));};exports[_0x80f4('0x3f')]=function(_0x2bbf56,_0x570b7f){var _0x4ff68a={'raw':!![],'where':{'id':_0x2bbf56[_0x80f4('0x40')]['id']}},_0x38d3a6={};_0x38d3a6[_0x80f4('0x2b')]=_['keys'](db[_0x80f4('0x27')][_0x80f4('0x28')]);_0x38d3a6['query']=_['keys'](_0x2bbf56[_0x80f4('0x2c')]);_0x38d3a6[_0x80f4('0x35')]=_['intersection'](_0x38d3a6[_0x80f4('0x2b')],_0x38d3a6[_0x80f4('0x2c')]);_0x4ff68a['attributes']=_[_0x80f4('0x2e')](_0x38d3a6[_0x80f4('0x2b')],qs[_0x80f4('0x30')](_0x2bbf56[_0x80f4('0x2c')]['fields']));_0x4ff68a['attributes']=_0x4ff68a[_0x80f4('0x2f')][_0x80f4('0x41')]?_0x4ff68a[_0x80f4('0x2f')]:_0x38d3a6[_0x80f4('0x2b')];if(_0x2bbf56[_0x80f4('0x2c')][_0x80f4('0x42')]){_0x4ff68a[_0x80f4('0x3b')]=[{'all':!![]}];}_0x4ff68a=_['merge']({},_0x4ff68a,_0x2bbf56[_0x80f4('0x3a')]);return db[_0x80f4('0x27')][_0x80f4('0x43')](_0x4ff68a)['then'](handleEntityNotFound(_0x570b7f,null))[_0x80f4('0x20')](respondWithResult(_0x570b7f,null))[_0x80f4('0x3e')](handleError(_0x570b7f,null));};exports[_0x80f4('0x44')]=function(_0x93e150,_0x2e3927){return db[_0x80f4('0x27')][_0x80f4('0x44')](_0x93e150['body'],{})['then'](respondWithResult(_0x2e3927,0xc9))['catch'](handleError(_0x2e3927,null));};exports[_0x80f4('0x1f')]=function(_0x465b4a,_0x2ea3ba){if(_0x465b4a['body']['id']){delete _0x465b4a[_0x80f4('0x45')]['id'];}return db['WhatsappQueueReport'][_0x80f4('0x43')]({'where':{'id':_0x465b4a[_0x80f4('0x40')]['id']}})['then'](handleEntityNotFound(_0x2ea3ba,null))[_0x80f4('0x20')](saveUpdates(_0x465b4a[_0x80f4('0x45')],null))[_0x80f4('0x20')](respondWithResult(_0x2ea3ba,null))['catch'](handleError(_0x2ea3ba,null));};exports[_0x80f4('0x46')]=function(_0x5a56ec,_0x2f7e7d){return db['WhatsappQueueReport'][_0x80f4('0x43')]({'where':{'id':_0x5a56ec['params']['id']}})[_0x80f4('0x20')](handleEntityNotFound(_0x2f7e7d,null))[_0x80f4('0x20')](removeEntity(_0x2f7e7d,null))[_0x80f4('0x3e')](handleError(_0x2f7e7d,null));};exports['describe']=function(_0x579456,_0x20f2eb){return db[_0x80f4('0x27')][_0x80f4('0x47')]()[_0x80f4('0x20')](respondWithResult(_0x20f2eb,null))[_0x80f4('0x3e')](handleError(_0x20f2eb,null));};