Built motion from commit (unavailable).|2.5.23
[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 _0x4f1b=['../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','status','end','offset','limit','Content-Range','json','reject','save','destroy','sendStatus','error','stack','name','send','index','WhatsappQueueReport','rawAttributes','fieldName','type','model','map','keys','filters','intersection','query','fields','attributes','length','hasOwnProperty','nolimit','sort','where','pick','filter','options','then','include','findAll','rows','show','params','includeAll','merge','find','catch','create','body','update','describe','html-pdf','rimraf','zip-dir','request-promise','moment','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware'];(function(_0x21ce42,_0x554562){var _0x4683be=function(_0x40a5a7){while(--_0x40a5a7){_0x21ce42['push'](_0x21ce42['shift']());}};_0x4683be(++_0x554562);}(_0x4f1b,0x162));var _0xb4f1=function(_0x220d3e,_0xfd204){_0x220d3e=_0x220d3e-0x0;var _0x52a325=_0x4f1b[_0x220d3e];return _0x52a325;};'use strict';var pdf=require(_0xb4f1('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xb4f1('0x1'));var zipdir=require(_0xb4f1('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xb4f1('0x3'));var moment=require(_0xb4f1('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0xb4f1('0x5'));var path=require(_0xb4f1('0x6'));var sox=require(_0xb4f1('0x7'));var csv=require(_0xb4f1('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xb4f1('0x9'));var squel=require(_0xb4f1('0xa'));var crypto=require(_0xb4f1('0xb'));var jsforce=require(_0xb4f1('0xc'));var deskjs=require(_0xb4f1('0xd'));var toCsv=require(_0xb4f1('0x8'));var querystring=require(_0xb4f1('0xe'));var Papa=require(_0xb4f1('0xf'));var Redis=require(_0xb4f1('0x10'));var authService=require(_0xb4f1('0x11'));var qs=require(_0xb4f1('0x12'));var as=require(_0xb4f1('0x13'));var hardwareService=require(_0xb4f1('0x14'));var logger=require(_0xb4f1('0x15'))(_0xb4f1('0x16'));var utils=require(_0xb4f1('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0xb4f1('0x18'));var db=require(_0xb4f1('0x19'))['db'];function respondWithStatusCode(_0x519e48,_0x50d2cf){_0x50d2cf=_0x50d2cf||0xcc;return function(_0x3a4001){if(_0x3a4001){return _0x519e48['sendStatus'](_0x50d2cf);}return _0x519e48[_0xb4f1('0x1a')](_0x50d2cf)[_0xb4f1('0x1b')]();};}function respondWithResult(_0x570405,_0x50b825){_0x50b825=_0x50b825||0xc8;return function(_0x5107b3){if(_0x5107b3){return _0x570405[_0xb4f1('0x1a')](_0x50b825)['json'](_0x5107b3);}};}function respondWithFilteredResult(_0x399d36,_0x25662b){return function(_0x522fdf){if(_0x522fdf){var _0x1ddab4=_0x522fdf['count'],_0x11a768=_0x25662b[_0xb4f1('0x1c')],_0x3f8701=_0x25662b[_0xb4f1('0x1c')]+_0x25662b[_0xb4f1('0x1d')],_0x152f69;if(_0x3f8701>=_0x1ddab4){_0x3f8701=_0x1ddab4;_0x152f69=0xc8;}else{_0x152f69=0xce;}_0x399d36[_0xb4f1('0x1a')](_0x152f69);return _0x399d36['set'](_0xb4f1('0x1e'),_0x11a768+'-'+_0x3f8701+'/'+_0x1ddab4)[_0xb4f1('0x1f')](_0x522fdf);}return null;};}function patchUpdates(_0x9dbab5){return function(_0x3fa90d){try{jsonpatch['apply'](_0x3fa90d,_0x9dbab5,!![]);}catch(_0x29bef2){return BPromise[_0xb4f1('0x20')](_0x29bef2);}return _0x3fa90d[_0xb4f1('0x21')]();};}function saveUpdates(_0x37e826,_0x4b98d5){return function(_0x4e9121){if(_0x4e9121){return _0x4e9121['update'](_0x37e826)['then'](function(_0x5accec){return _0x5accec;});}return null;};}function removeEntity(_0x2e508a,_0x19bb57){return function(_0x4c6591){if(_0x4c6591){return _0x4c6591[_0xb4f1('0x22')]()['then'](function(){_0x2e508a[_0xb4f1('0x1a')](0xcc)[_0xb4f1('0x1b')]();});}};}function handleEntityNotFound(_0x4fa170,_0x40de74){return function(_0x32db3b){if(!_0x32db3b){_0x4fa170[_0xb4f1('0x23')](0x194);}return _0x32db3b;};}function handleError(_0x315266,_0x5d5033){_0x5d5033=_0x5d5033||0x1f4;return function(_0xf9fcae){logger[_0xb4f1('0x24')](_0xf9fcae[_0xb4f1('0x25')]);if(_0xf9fcae[_0xb4f1('0x26')]){delete _0xf9fcae[_0xb4f1('0x26')];}_0x315266[_0xb4f1('0x1a')](_0x5d5033)[_0xb4f1('0x27')](_0xf9fcae);};}exports[_0xb4f1('0x28')]=function(_0x809d36,_0x389f90){var _0x31cea3={},_0x3dece3={},_0x353eba={'count':0x0,'rows':[]};var _0x5e5aa0=_['map'](db[_0xb4f1('0x29')][_0xb4f1('0x2a')],function(_0x149f71){return{'name':_0x149f71[_0xb4f1('0x2b')],'type':_0x149f71[_0xb4f1('0x2c')]['key']};});_0x3dece3[_0xb4f1('0x2d')]=_[_0xb4f1('0x2e')](_0x5e5aa0,_0xb4f1('0x26'));_0x3dece3['query']=_[_0xb4f1('0x2f')](_0x809d36['query']);_0x3dece3[_0xb4f1('0x30')]=_[_0xb4f1('0x31')](_0x3dece3[_0xb4f1('0x2d')],_0x3dece3[_0xb4f1('0x32')]);_0x31cea3['attributes']=_[_0xb4f1('0x31')](_0x3dece3[_0xb4f1('0x2d')],qs[_0xb4f1('0x33')](_0x809d36[_0xb4f1('0x32')][_0xb4f1('0x33')]));_0x31cea3[_0xb4f1('0x34')]=_0x31cea3[_0xb4f1('0x34')][_0xb4f1('0x35')]?_0x31cea3[_0xb4f1('0x34')]:_0x3dece3['model'];if(!_0x809d36[_0xb4f1('0x32')][_0xb4f1('0x36')](_0xb4f1('0x37'))){_0x31cea3[_0xb4f1('0x1d')]=qs[_0xb4f1('0x1d')](_0x809d36[_0xb4f1('0x32')]['limit']);_0x31cea3['offset']=qs[_0xb4f1('0x1c')](_0x809d36[_0xb4f1('0x32')][_0xb4f1('0x1c')]);}_0x31cea3['order']=qs[_0xb4f1('0x38')](_0x809d36[_0xb4f1('0x32')][_0xb4f1('0x38')]);_0x31cea3[_0xb4f1('0x39')]=qs['filters'](_[_0xb4f1('0x3a')](_0x809d36[_0xb4f1('0x32')],_0x3dece3[_0xb4f1('0x30')]),_0x5e5aa0);if(_0x809d36['query'][_0xb4f1('0x3b')]){_0x31cea3['where']=_['merge'](_0x31cea3[_0xb4f1('0x39')],{'$or':_[_0xb4f1('0x2e')](_0x5e5aa0,function(_0x46c31d){if(_0x46c31d[_0xb4f1('0x2c')]!=='VIRTUAL'){var _0x358b75={};_0x358b75[_0x46c31d[_0xb4f1('0x26')]]={'$like':'%'+_0x809d36[_0xb4f1('0x32')][_0xb4f1('0x3b')]+'%'};return _0x358b75;}})});}_0x31cea3=_['merge']({},_0x31cea3,_0x809d36[_0xb4f1('0x3c')]);var _0x5519fe={'where':_0x31cea3[_0xb4f1('0x39')]};return db['WhatsappQueueReport']['count'](_0x5519fe)[_0xb4f1('0x3d')](function(_0x5d5e36){_0x353eba['count']=_0x5d5e36;if(_0x809d36['query']['includeAll']){_0x31cea3[_0xb4f1('0x3e')]=[{'all':!![]}];}return db[_0xb4f1('0x29')][_0xb4f1('0x3f')](_0x31cea3);})[_0xb4f1('0x3d')](function(_0x3b14a3){_0x353eba[_0xb4f1('0x40')]=_0x3b14a3;return _0x353eba;})[_0xb4f1('0x3d')](respondWithFilteredResult(_0x389f90,_0x31cea3))['catch'](handleError(_0x389f90,null));};exports[_0xb4f1('0x41')]=function(_0x2c901c,_0xf0e8ec){var _0x36f9af={'raw':!![],'where':{'id':_0x2c901c[_0xb4f1('0x42')]['id']}},_0x49488c={};_0x49488c[_0xb4f1('0x2d')]=_['keys'](db[_0xb4f1('0x29')]['rawAttributes']);_0x49488c['query']=_[_0xb4f1('0x2f')](_0x2c901c[_0xb4f1('0x32')]);_0x49488c[_0xb4f1('0x30')]=_[_0xb4f1('0x31')](_0x49488c[_0xb4f1('0x2d')],_0x49488c[_0xb4f1('0x32')]);_0x36f9af[_0xb4f1('0x34')]=_[_0xb4f1('0x31')](_0x49488c[_0xb4f1('0x2d')],qs[_0xb4f1('0x33')](_0x2c901c[_0xb4f1('0x32')]['fields']));_0x36f9af[_0xb4f1('0x34')]=_0x36f9af['attributes']['length']?_0x36f9af[_0xb4f1('0x34')]:_0x49488c['model'];if(_0x2c901c[_0xb4f1('0x32')][_0xb4f1('0x43')]){_0x36f9af[_0xb4f1('0x3e')]=[{'all':!![]}];}_0x36f9af=_[_0xb4f1('0x44')]({},_0x36f9af,_0x2c901c['options']);return db[_0xb4f1('0x29')][_0xb4f1('0x45')](_0x36f9af)[_0xb4f1('0x3d')](handleEntityNotFound(_0xf0e8ec,null))[_0xb4f1('0x3d')](respondWithResult(_0xf0e8ec,null))[_0xb4f1('0x46')](handleError(_0xf0e8ec,null));};exports[_0xb4f1('0x47')]=function(_0x27601b,_0x502fbe){return db[_0xb4f1('0x29')][_0xb4f1('0x47')](_0x27601b[_0xb4f1('0x48')],{})[_0xb4f1('0x3d')](respondWithResult(_0x502fbe,0xc9))['catch'](handleError(_0x502fbe,null));};exports[_0xb4f1('0x49')]=function(_0x569497,_0x42ad01){if(_0x569497[_0xb4f1('0x48')]['id']){delete _0x569497[_0xb4f1('0x48')]['id'];}return db[_0xb4f1('0x29')]['find']({'where':{'id':_0x569497[_0xb4f1('0x42')]['id']}})['then'](handleEntityNotFound(_0x42ad01,null))[_0xb4f1('0x3d')](saveUpdates(_0x569497[_0xb4f1('0x48')],null))[_0xb4f1('0x3d')](respondWithResult(_0x42ad01,null))['catch'](handleError(_0x42ad01,null));};exports[_0xb4f1('0x22')]=function(_0x4bea34,_0x4bb906){return db['WhatsappQueueReport']['find']({'where':{'id':_0x4bea34['params']['id']}})[_0xb4f1('0x3d')](handleEntityNotFound(_0x4bb906,null))[_0xb4f1('0x3d')](removeEntity(_0x4bb906,null))[_0xb4f1('0x46')](handleError(_0x4bb906,null));};exports['describe']=function(_0x3be2cc,_0xce5f27){return db[_0xb4f1('0x29')][_0xb4f1('0x4a')]()[_0xb4f1('0x3d')](respondWithResult(_0xce5f27,null))[_0xb4f1('0x46')](handleError(_0xce5f27,null));};