95a6d5f9e63f355b009a0092f86ffee8538d2744
[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 _0xb62e=['length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','then','includeAll','findAll','show','find','catch','create','body','update','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','crypto','jsforce','desk.js','to-csv','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','undefined','limit','count','set','Content-Range','reject','save','stack','name','send','index','map','WhatsappQueueReport','rawAttributes','type','key','model','query','keys','filters','attributes','fields'];(function(_0x4565bf,_0x5ad9d6){var _0x5610ba=function(_0x170988){while(--_0x170988){_0x4565bf['push'](_0x4565bf['shift']());}};_0x5610ba(++_0x5ad9d6);}(_0xb62e,0x1de));var _0xeb62=function(_0x160c73,_0x2ee678){_0x160c73=_0x160c73-0x0;var _0xd9302=_0xb62e[_0x160c73];return _0xd9302;};'use strict';var emlformat=require(_0xeb62('0x0'));var rimraf=require(_0xeb62('0x1'));var zipdir=require(_0xeb62('0x2'));var jsonpatch=require(_0xeb62('0x3'));var rp=require('request-promise');var moment=require(_0xeb62('0x4'));var BPromise=require(_0xeb62('0x5'));var Mustache=require(_0xeb62('0x6'));var util=require(_0xeb62('0x7'));var path=require(_0xeb62('0x8'));var sox=require(_0xeb62('0x9'));var csv=require('to-csv');var ejs=require(_0xeb62('0xa'));var fs=require('fs');var fs_extra=require(_0xeb62('0xb'));var _=require(_0xeb62('0xc'));var squel=require('squel');var crypto=require(_0xeb62('0xd'));var jsforce=require(_0xeb62('0xe'));var deskjs=require(_0xeb62('0xf'));var toCsv=require(_0xeb62('0x10'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xeb62('0x11'));var authService=require(_0xeb62('0x12'));var qs=require(_0xeb62('0x13'));var as=require(_0xeb62('0x14'));var hardwareService=require(_0xeb62('0x15'));var logger=require(_0xeb62('0x16'))(_0xeb62('0x17'));var utils=require(_0xeb62('0x18'));var config=require(_0xeb62('0x19'));var licenseUtil=require(_0xeb62('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x422daf,_0xcc11c4){_0xcc11c4=_0xcc11c4||0xcc;return function(_0x27671e){if(_0x27671e){return _0x422daf[_0xeb62('0x1b')](_0xcc11c4);}return _0x422daf['status'](_0xcc11c4)[_0xeb62('0x1c')]();};}function respondWithResult(_0x2fbad2,_0x23fb15){_0x23fb15=_0x23fb15||0xc8;return function(_0x4da178){if(_0x4da178){return _0x2fbad2[_0xeb62('0x1d')](_0x23fb15)[_0xeb62('0x1e')](_0x4da178);}};}function respondWithFilteredResult(_0x2fd4c7,_0x4ce9fa){return function(_0x1f6a1f){if(_0x1f6a1f){var _0x15b3e8=typeof _0x4ce9fa[_0xeb62('0x1f')]===_0xeb62('0x20')&&typeof _0x4ce9fa[_0xeb62('0x21')]===_0xeb62('0x20');var _0x1fb460=_0x1f6a1f[_0xeb62('0x22')];var _0x39b138=_0x15b3e8?0x0:_0x4ce9fa[_0xeb62('0x1f')];var _0x27efc8=_0x15b3e8?_0x1f6a1f[_0xeb62('0x22')]:_0x4ce9fa[_0xeb62('0x1f')]+_0x4ce9fa['limit'];var _0x38c5e4;if(_0x27efc8>=_0x1fb460){_0x27efc8=_0x1fb460;_0x38c5e4=0xc8;}else{_0x38c5e4=0xce;}_0x2fd4c7[_0xeb62('0x1d')](_0x38c5e4);return _0x2fd4c7[_0xeb62('0x23')](_0xeb62('0x24'),_0x39b138+'-'+_0x27efc8+'/'+_0x1fb460)[_0xeb62('0x1e')](_0x1f6a1f);}return null;};}function patchUpdates(_0x24cbf3){return function(_0x2ed96d){try{jsonpatch['apply'](_0x2ed96d,_0x24cbf3,!![]);}catch(_0x599d0b){return BPromise[_0xeb62('0x25')](_0x599d0b);}return _0x2ed96d[_0xeb62('0x26')]();};}function saveUpdates(_0x11ed9c,_0x13243f){return function(_0x122b15){if(_0x122b15){return _0x122b15['update'](_0x11ed9c)['then'](function(_0x4664ce){return _0x4664ce;});}return null;};}function removeEntity(_0x132861,_0x182781){return function(_0x395b70){if(_0x395b70){return _0x395b70['destroy']()['then'](function(){_0x132861[_0xeb62('0x1d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x448327,_0x4b0f46){return function(_0xfe3e16){if(!_0xfe3e16){_0x448327['sendStatus'](0x194);}return _0xfe3e16;};}function handleError(_0x3ac28c,_0x6bfbbc){_0x6bfbbc=_0x6bfbbc||0x1f4;return function(_0x46d1bb){logger['error'](_0x46d1bb[_0xeb62('0x27')]);if(_0x46d1bb[_0xeb62('0x28')]){delete _0x46d1bb[_0xeb62('0x28')];}_0x3ac28c[_0xeb62('0x1d')](_0x6bfbbc)[_0xeb62('0x29')](_0x46d1bb);};}exports[_0xeb62('0x2a')]=function(_0x511202,_0x192517){var _0x1616ee={},_0x57169a={},_0x157474={'count':0x0,'rows':[]};var _0x2b51b2=_[_0xeb62('0x2b')](db[_0xeb62('0x2c')][_0xeb62('0x2d')],function(_0x5195bf){return{'name':_0x5195bf['fieldName'],'type':_0x5195bf[_0xeb62('0x2e')][_0xeb62('0x2f')]};});_0x57169a[_0xeb62('0x30')]=_[_0xeb62('0x2b')](_0x2b51b2,_0xeb62('0x28'));_0x57169a[_0xeb62('0x31')]=_[_0xeb62('0x32')](_0x511202['query']);_0x57169a[_0xeb62('0x33')]=_['intersection'](_0x57169a['model'],_0x57169a[_0xeb62('0x31')]);_0x1616ee[_0xeb62('0x34')]=_['intersection'](_0x57169a[_0xeb62('0x30')],qs['fields'](_0x511202[_0xeb62('0x31')][_0xeb62('0x35')]));_0x1616ee['attributes']=_0x1616ee[_0xeb62('0x34')][_0xeb62('0x36')]?_0x1616ee['attributes']:_0x57169a[_0xeb62('0x30')];if(!_0x511202[_0xeb62('0x31')][_0xeb62('0x37')](_0xeb62('0x38'))){_0x1616ee['limit']=qs[_0xeb62('0x21')](_0x511202[_0xeb62('0x31')]['limit']);_0x1616ee['offset']=qs[_0xeb62('0x1f')](_0x511202[_0xeb62('0x31')]['offset']);}_0x1616ee[_0xeb62('0x39')]=qs[_0xeb62('0x3a')](_0x511202[_0xeb62('0x31')][_0xeb62('0x3a')]);_0x1616ee[_0xeb62('0x3b')]=qs[_0xeb62('0x33')](_[_0xeb62('0x3c')](_0x511202['query'],_0x57169a['filters']),_0x2b51b2);if(_0x511202[_0xeb62('0x31')][_0xeb62('0x3d')]){_0x1616ee[_0xeb62('0x3b')]=_[_0xeb62('0x3e')](_0x1616ee['where'],{'$or':_[_0xeb62('0x2b')](_0x2b51b2,function(_0x510c7d){if(_0x510c7d[_0xeb62('0x2e')]!==_0xeb62('0x3f')){var _0x2dac2f={};_0x2dac2f[_0x510c7d[_0xeb62('0x28')]]={'$like':'%'+_0x511202[_0xeb62('0x31')][_0xeb62('0x3d')]+'%'};return _0x2dac2f;}})});}_0x1616ee=_[_0xeb62('0x3e')]({},_0x1616ee,_0x511202[_0xeb62('0x40')]);var _0x5e8ef8={'where':_0x1616ee[_0xeb62('0x3b')]};return db[_0xeb62('0x2c')][_0xeb62('0x22')](_0x5e8ef8)[_0xeb62('0x41')](function(_0x5dd0e3){_0x157474['count']=_0x5dd0e3;if(_0x511202[_0xeb62('0x31')][_0xeb62('0x42')]){_0x1616ee['include']=[{'all':!![]}];}return db[_0xeb62('0x2c')][_0xeb62('0x43')](_0x1616ee);})['then'](function(_0x25e9f0){_0x157474['rows']=_0x25e9f0;return _0x157474;})[_0xeb62('0x41')](respondWithFilteredResult(_0x192517,_0x1616ee))['catch'](handleError(_0x192517,null));};exports[_0xeb62('0x44')]=function(_0x5dde1d,_0x2bf77f){var _0x609b2d={'raw':!![],'where':{'id':_0x5dde1d['params']['id']}},_0x317f50={};_0x317f50['model']=_[_0xeb62('0x32')](db[_0xeb62('0x2c')][_0xeb62('0x2d')]);_0x317f50[_0xeb62('0x31')]=_[_0xeb62('0x32')](_0x5dde1d['query']);_0x317f50[_0xeb62('0x33')]=_['intersection'](_0x317f50[_0xeb62('0x30')],_0x317f50['query']);_0x609b2d[_0xeb62('0x34')]=_['intersection'](_0x317f50[_0xeb62('0x30')],qs['fields'](_0x5dde1d[_0xeb62('0x31')][_0xeb62('0x35')]));_0x609b2d[_0xeb62('0x34')]=_0x609b2d[_0xeb62('0x34')][_0xeb62('0x36')]?_0x609b2d[_0xeb62('0x34')]:_0x317f50['model'];if(_0x5dde1d[_0xeb62('0x31')][_0xeb62('0x42')]){_0x609b2d['include']=[{'all':!![]}];}_0x609b2d=_['merge']({},_0x609b2d,_0x5dde1d['options']);return db['WhatsappQueueReport'][_0xeb62('0x45')](_0x609b2d)[_0xeb62('0x41')](handleEntityNotFound(_0x2bf77f,null))['then'](respondWithResult(_0x2bf77f,null))[_0xeb62('0x46')](handleError(_0x2bf77f,null));};exports[_0xeb62('0x47')]=function(_0x412e93,_0x16e262){return db[_0xeb62('0x2c')]['create'](_0x412e93[_0xeb62('0x48')],{})['then'](respondWithResult(_0x16e262,0xc9))[_0xeb62('0x46')](handleError(_0x16e262,null));};exports[_0xeb62('0x49')]=function(_0x7fb53f,_0x18c40d){if(_0x7fb53f[_0xeb62('0x48')]['id']){delete _0x7fb53f[_0xeb62('0x48')]['id'];}return db[_0xeb62('0x2c')][_0xeb62('0x45')]({'where':{'id':_0x7fb53f[_0xeb62('0x4a')]['id']}})[_0xeb62('0x41')](handleEntityNotFound(_0x18c40d,null))[_0xeb62('0x41')](saveUpdates(_0x7fb53f[_0xeb62('0x48')],null))['then'](respondWithResult(_0x18c40d,null))[_0xeb62('0x46')](handleError(_0x18c40d,null));};exports['destroy']=function(_0x4edd8c,_0x2dcb2d){return db[_0xeb62('0x2c')]['find']({'where':{'id':_0x4edd8c[_0xeb62('0x4a')]['id']}})[_0xeb62('0x41')](handleEntityNotFound(_0x2dcb2d,null))['then'](removeEntity(_0x2dcb2d,null))[_0xeb62('0x46')](handleError(_0x2dcb2d,null));};exports[_0xeb62('0x4b')]=function(_0x20b73b,_0x60617){return db[_0xeb62('0x2c')][_0xeb62('0x4b')]()[_0xeb62('0x41')](respondWithResult(_0x60617,null))[_0xeb62('0x46')](handleError(_0x60617,null));};