Built motion from commit b5413ace.|2.6.9
[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 _0xfef3=['offset','limit','undefined','count','status','set','Content-Range','apply','reject','save','update','destroy','stack','name','send','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','filter','merge','VIRTUAL','options','WhatsappQueueReport','then','includeAll','include','findAll','rows','catch','show','params','fields','create','body','find','describe','eml-format','zip-dir','request-promise','moment','mustache','util','sox','to-csv','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','end','json'];(function(_0x442ede,_0x2c3376){var _0x3b7c68=function(_0x4fd896){while(--_0x4fd896){_0x442ede['push'](_0x442ede['shift']());}};_0x3b7c68(++_0x2c3376);}(_0xfef3,0x118));var _0x3fef=function(_0x2962b4,_0x4b0786){_0x2962b4=_0x2962b4-0x0;var _0x411b7d=_0xfef3[_0x2962b4];return _0x411b7d;};'use strict';var emlformat=require(_0x3fef('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x3fef('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x3fef('0x2'));var moment=require(_0x3fef('0x3'));var BPromise=require('bluebird');var Mustache=require(_0x3fef('0x4'));var util=require(_0x3fef('0x5'));var path=require('path');var sox=require(_0x3fef('0x6'));var csv=require(_0x3fef('0x7'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3fef('0x8'));var _=require(_0x3fef('0x9'));var squel=require(_0x3fef('0xa'));var crypto=require(_0x3fef('0xb'));var jsforce=require(_0x3fef('0xc'));var deskjs=require(_0x3fef('0xd'));var toCsv=require(_0x3fef('0x7'));var querystring=require(_0x3fef('0xe'));var Papa=require(_0x3fef('0xf'));var Redis=require(_0x3fef('0x10'));var authService=require(_0x3fef('0x11'));var qs=require(_0x3fef('0x12'));var as=require(_0x3fef('0x13'));var hardwareService=require(_0x3fef('0x14'));var logger=require('../../config/logger')(_0x3fef('0x15'));var utils=require(_0x3fef('0x16'));var config=require(_0x3fef('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x3fef('0x18'))['db'];function respondWithStatusCode(_0x4c4a47,_0x2c99ff){_0x2c99ff=_0x2c99ff||0xcc;return function(_0x3d2c2d){if(_0x3d2c2d){return _0x4c4a47[_0x3fef('0x19')](_0x2c99ff);}return _0x4c4a47['status'](_0x2c99ff)[_0x3fef('0x1a')]();};}function respondWithResult(_0x4be62f,_0x15b757){_0x15b757=_0x15b757||0xc8;return function(_0x14c053){if(_0x14c053){return _0x4be62f['status'](_0x15b757)[_0x3fef('0x1b')](_0x14c053);}};}function respondWithFilteredResult(_0x177e28,_0x40b479){return function(_0x79b617){if(_0x79b617){var _0x395df0=typeof _0x40b479[_0x3fef('0x1c')]==='undefined'&&typeof _0x40b479[_0x3fef('0x1d')]===_0x3fef('0x1e');var _0x1ec282=_0x79b617[_0x3fef('0x1f')];var _0x1613ad=_0x395df0?0x0:_0x40b479[_0x3fef('0x1c')];var _0x53d993=_0x395df0?_0x79b617[_0x3fef('0x1f')]:_0x40b479[_0x3fef('0x1c')]+_0x40b479['limit'];var _0x2c7f36;if(_0x53d993>=_0x1ec282){_0x53d993=_0x1ec282;_0x2c7f36=0xc8;}else{_0x2c7f36=0xce;}_0x177e28[_0x3fef('0x20')](_0x2c7f36);return _0x177e28[_0x3fef('0x21')](_0x3fef('0x22'),_0x1613ad+'-'+_0x53d993+'/'+_0x1ec282)[_0x3fef('0x1b')](_0x79b617);}return null;};}function patchUpdates(_0x2b5226){return function(_0x451d11){try{jsonpatch[_0x3fef('0x23')](_0x451d11,_0x2b5226,!![]);}catch(_0x124e7c){return BPromise[_0x3fef('0x24')](_0x124e7c);}return _0x451d11[_0x3fef('0x25')]();};}function saveUpdates(_0x3bb110,_0x2eb578){return function(_0x39a8ea){if(_0x39a8ea){return _0x39a8ea[_0x3fef('0x26')](_0x3bb110)['then'](function(_0x5b56de){return _0x5b56de;});}return null;};}function removeEntity(_0x50025f,_0x378b03){return function(_0x3ba38d){if(_0x3ba38d){return _0x3ba38d[_0x3fef('0x27')]()['then'](function(){_0x50025f[_0x3fef('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x45464b,_0x2c0848){return function(_0x64d3e6){if(!_0x64d3e6){_0x45464b[_0x3fef('0x19')](0x194);}return _0x64d3e6;};}function handleError(_0x30e17a,_0x492ea0){_0x492ea0=_0x492ea0||0x1f4;return function(_0x4b4dee){logger['error'](_0x4b4dee[_0x3fef('0x28')]);if(_0x4b4dee[_0x3fef('0x29')]){delete _0x4b4dee['name'];}_0x30e17a[_0x3fef('0x20')](_0x492ea0)[_0x3fef('0x2a')](_0x4b4dee);};}exports['index']=function(_0x30a954,_0x3bdf03){var _0xf892bb={},_0x2b73fb={},_0x3a1a0a={'count':0x0,'rows':[]};var _0x137849=_[_0x3fef('0x2b')](db['WhatsappQueueReport'][_0x3fef('0x2c')],function(_0xc20ce5){return{'name':_0xc20ce5[_0x3fef('0x2d')],'type':_0xc20ce5[_0x3fef('0x2e')]['key']};});_0x2b73fb[_0x3fef('0x2f')]=_['map'](_0x137849,_0x3fef('0x29'));_0x2b73fb[_0x3fef('0x30')]=_[_0x3fef('0x31')](_0x30a954[_0x3fef('0x30')]);_0x2b73fb[_0x3fef('0x32')]=_[_0x3fef('0x33')](_0x2b73fb[_0x3fef('0x2f')],_0x2b73fb[_0x3fef('0x30')]);_0xf892bb[_0x3fef('0x34')]=_[_0x3fef('0x33')](_0x2b73fb['model'],qs['fields'](_0x30a954[_0x3fef('0x30')]['fields']));_0xf892bb[_0x3fef('0x34')]=_0xf892bb[_0x3fef('0x34')][_0x3fef('0x35')]?_0xf892bb[_0x3fef('0x34')]:_0x2b73fb[_0x3fef('0x2f')];if(!_0x30a954[_0x3fef('0x30')][_0x3fef('0x36')](_0x3fef('0x37'))){_0xf892bb[_0x3fef('0x1d')]=qs[_0x3fef('0x1d')](_0x30a954[_0x3fef('0x30')][_0x3fef('0x1d')]);_0xf892bb[_0x3fef('0x1c')]=qs[_0x3fef('0x1c')](_0x30a954['query'][_0x3fef('0x1c')]);}_0xf892bb[_0x3fef('0x38')]=qs[_0x3fef('0x39')](_0x30a954[_0x3fef('0x30')][_0x3fef('0x39')]);_0xf892bb[_0x3fef('0x3a')]=qs['filters'](_['pick'](_0x30a954[_0x3fef('0x30')],_0x2b73fb[_0x3fef('0x32')]),_0x137849);if(_0x30a954[_0x3fef('0x30')][_0x3fef('0x3b')]){_0xf892bb[_0x3fef('0x3a')]=_[_0x3fef('0x3c')](_0xf892bb[_0x3fef('0x3a')],{'$or':_[_0x3fef('0x2b')](_0x137849,function(_0x1fa70f){if(_0x1fa70f[_0x3fef('0x2e')]!==_0x3fef('0x3d')){var _0x560aae={};_0x560aae[_0x1fa70f[_0x3fef('0x29')]]={'$like':'%'+_0x30a954[_0x3fef('0x30')]['filter']+'%'};return _0x560aae;}})});}_0xf892bb=_['merge']({},_0xf892bb,_0x30a954[_0x3fef('0x3e')]);var _0x3dda68={'where':_0xf892bb[_0x3fef('0x3a')]};return db[_0x3fef('0x3f')][_0x3fef('0x1f')](_0x3dda68)[_0x3fef('0x40')](function(_0x17aff8){_0x3a1a0a[_0x3fef('0x1f')]=_0x17aff8;if(_0x30a954['query'][_0x3fef('0x41')]){_0xf892bb[_0x3fef('0x42')]=[{'all':!![]}];}return db[_0x3fef('0x3f')][_0x3fef('0x43')](_0xf892bb);})[_0x3fef('0x40')](function(_0x2143ec){_0x3a1a0a[_0x3fef('0x44')]=_0x2143ec;return _0x3a1a0a;})[_0x3fef('0x40')](respondWithFilteredResult(_0x3bdf03,_0xf892bb))[_0x3fef('0x45')](handleError(_0x3bdf03,null));};exports[_0x3fef('0x46')]=function(_0x12867c,_0x254880){var _0x2e1d7f={'raw':!![],'where':{'id':_0x12867c[_0x3fef('0x47')]['id']}},_0x15d2c7={};_0x15d2c7['model']=_[_0x3fef('0x31')](db[_0x3fef('0x3f')][_0x3fef('0x2c')]);_0x15d2c7[_0x3fef('0x30')]=_[_0x3fef('0x31')](_0x12867c[_0x3fef('0x30')]);_0x15d2c7['filters']=_[_0x3fef('0x33')](_0x15d2c7['model'],_0x15d2c7[_0x3fef('0x30')]);_0x2e1d7f[_0x3fef('0x34')]=_['intersection'](_0x15d2c7[_0x3fef('0x2f')],qs['fields'](_0x12867c[_0x3fef('0x30')][_0x3fef('0x48')]));_0x2e1d7f[_0x3fef('0x34')]=_0x2e1d7f[_0x3fef('0x34')][_0x3fef('0x35')]?_0x2e1d7f[_0x3fef('0x34')]:_0x15d2c7[_0x3fef('0x2f')];if(_0x12867c[_0x3fef('0x30')][_0x3fef('0x41')]){_0x2e1d7f[_0x3fef('0x42')]=[{'all':!![]}];}_0x2e1d7f=_[_0x3fef('0x3c')]({},_0x2e1d7f,_0x12867c[_0x3fef('0x3e')]);return db[_0x3fef('0x3f')]['find'](_0x2e1d7f)[_0x3fef('0x40')](handleEntityNotFound(_0x254880,null))[_0x3fef('0x40')](respondWithResult(_0x254880,null))['catch'](handleError(_0x254880,null));};exports[_0x3fef('0x49')]=function(_0x4210d6,_0x2f00c0){return db['WhatsappQueueReport'][_0x3fef('0x49')](_0x4210d6[_0x3fef('0x4a')],{})['then'](respondWithResult(_0x2f00c0,0xc9))[_0x3fef('0x45')](handleError(_0x2f00c0,null));};exports['update']=function(_0x48322c,_0x15fb2c){if(_0x48322c['body']['id']){delete _0x48322c[_0x3fef('0x4a')]['id'];}return db[_0x3fef('0x3f')]['find']({'where':{'id':_0x48322c[_0x3fef('0x47')]['id']}})[_0x3fef('0x40')](handleEntityNotFound(_0x15fb2c,null))[_0x3fef('0x40')](saveUpdates(_0x48322c['body'],null))[_0x3fef('0x40')](respondWithResult(_0x15fb2c,null))[_0x3fef('0x45')](handleError(_0x15fb2c,null));};exports[_0x3fef('0x27')]=function(_0x5b1acb,_0x324f70){return db[_0x3fef('0x3f')][_0x3fef('0x4b')]({'where':{'id':_0x5b1acb[_0x3fef('0x47')]['id']}})[_0x3fef('0x40')](handleEntityNotFound(_0x324f70,null))['then'](removeEntity(_0x324f70,null))[_0x3fef('0x45')](handleError(_0x324f70,null));};exports[_0x3fef('0x4c')]=function(_0x39a4b1,_0x2b9275){return db[_0x3fef('0x3f')][_0x3fef('0x4c')]()[_0x3fef('0x40')](respondWithResult(_0x2b9275,null))[_0x3fef('0x45')](handleError(_0x2b9275,null));};