Built motion from commit (unavailable).|2.5.7
[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 _0xc084=['update','then','stack','name','index','map','WhatsappQueueReport','rawAttributes','fieldName','type','key','model','filters','intersection','query','attributes','fields','hasOwnProperty','nolimit','order','where','pick','merge','VIRTUAL','filter','options','count','includeAll','include','rows','catch','show','params','keys','find','create','body','destroy','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','save'];(function(_0x562b56,_0x10e097){var _0x2ce5e1=function(_0x1c4bfa){while(--_0x1c4bfa){_0x562b56['push'](_0x562b56['shift']());}};_0x2ce5e1(++_0x10e097);}(_0xc084,0x199));var _0x4c08=function(_0x1a2510,_0x46a3e9){_0x1a2510=_0x1a2510-0x0;var _0x18339f=_0xc084[_0x1a2510];return _0x18339f;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x4c08('0x0'));var rimraf=require(_0x4c08('0x1'));var zipdir=require(_0x4c08('0x2'));var jsonpatch=require(_0x4c08('0x3'));var rp=require(_0x4c08('0x4'));var moment=require(_0x4c08('0x5'));var BPromise=require(_0x4c08('0x6'));var Mustache=require(_0x4c08('0x7'));var util=require(_0x4c08('0x8'));var path=require('path');var sox=require(_0x4c08('0x9'));var csv=require(_0x4c08('0xa'));var ejs=require(_0x4c08('0xb'));var fs=require('fs');var _=require(_0x4c08('0xc'));var squel=require('squel');var crypto=require(_0x4c08('0xd'));var jsforce=require(_0x4c08('0xe'));var deskjs=require(_0x4c08('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x4c08('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x4c08('0x11'));var as=require(_0x4c08('0x12'));var hardwareService=require(_0x4c08('0x13'));var logger=require(_0x4c08('0x14'))(_0x4c08('0x15'));var utils=require(_0x4c08('0x16'));var config=require(_0x4c08('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0x4c08('0x18'))['db'];function respondWithStatusCode(_0x5eb705,_0x23ab19){_0x23ab19=_0x23ab19||0xcc;return function(_0x32f01f){if(_0x32f01f){return _0x5eb705[_0x4c08('0x19')](_0x23ab19);}return _0x5eb705[_0x4c08('0x1a')](_0x23ab19)[_0x4c08('0x1b')]();};}function respondWithResult(_0x15f5b0,_0x488a77){_0x488a77=_0x488a77||0xc8;return function(_0x111c45){if(_0x111c45){return _0x15f5b0[_0x4c08('0x1a')](_0x488a77)[_0x4c08('0x1c')](_0x111c45);}};}function respondWithFilteredResult(_0x22f9bf,_0x4832fb){return function(_0xb91dd1){if(_0xb91dd1){var _0x30503c=_0xb91dd1['count'],_0x18e74a=_0x4832fb['offset'],_0x1f0e01=_0x4832fb[_0x4c08('0x1d')]+_0x4832fb[_0x4c08('0x1e')],_0x20e413;if(_0x1f0e01>=_0x30503c){_0x1f0e01=_0x30503c;_0x20e413=0xc8;}else{_0x20e413=0xce;}_0x22f9bf[_0x4c08('0x1a')](_0x20e413);return _0x22f9bf[_0x4c08('0x1f')](_0x4c08('0x20'),_0x18e74a+'-'+_0x1f0e01+'/'+_0x30503c)[_0x4c08('0x1c')](_0xb91dd1);}return null;};}function patchUpdates(_0x214e48){return function(_0x2d5bdf){try{jsonpatch[_0x4c08('0x21')](_0x2d5bdf,_0x214e48,!![]);}catch(_0x2b6523){return BPromise['reject'](_0x2b6523);}return _0x2d5bdf[_0x4c08('0x22')]();};}function saveUpdates(_0x4f8d68,_0x2aee85){return function(_0x31b38b){if(_0x31b38b){return _0x31b38b[_0x4c08('0x23')](_0x4f8d68)['then'](function(_0x3c9a36){return _0x3c9a36;});}return null;};}function removeEntity(_0x18bd1a,_0x1d4482){return function(_0x292797){if(_0x292797){return _0x292797['destroy']()[_0x4c08('0x24')](function(){_0x18bd1a[_0x4c08('0x1a')](0xcc)['end']();});}};}function handleEntityNotFound(_0x404ed7,_0x42876e){return function(_0x3746c6){if(!_0x3746c6){_0x404ed7[_0x4c08('0x19')](0x194);}return _0x3746c6;};}function handleError(_0x3087a9,_0x56bdad){_0x56bdad=_0x56bdad||0x1f4;return function(_0xd55019){logger['error'](_0xd55019[_0x4c08('0x25')]);if(_0xd55019[_0x4c08('0x26')]){delete _0xd55019[_0x4c08('0x26')];}_0x3087a9[_0x4c08('0x1a')](_0x56bdad)['send'](_0xd55019);};}exports[_0x4c08('0x27')]=function(_0x16d254,_0x4c8dd9){var _0x40d21f={},_0x1a5eaa={},_0x11399f={'count':0x0,'rows':[]};var _0x361e85=_[_0x4c08('0x28')](db[_0x4c08('0x29')][_0x4c08('0x2a')],function(_0x483a9e){return{'name':_0x483a9e[_0x4c08('0x2b')],'type':_0x483a9e[_0x4c08('0x2c')][_0x4c08('0x2d')]};});_0x1a5eaa[_0x4c08('0x2e')]=_[_0x4c08('0x28')](_0x361e85,_0x4c08('0x26'));_0x1a5eaa['query']=_['keys'](_0x16d254['query']);_0x1a5eaa[_0x4c08('0x2f')]=_[_0x4c08('0x30')](_0x1a5eaa[_0x4c08('0x2e')],_0x1a5eaa[_0x4c08('0x31')]);_0x40d21f[_0x4c08('0x32')]=_[_0x4c08('0x30')](_0x1a5eaa[_0x4c08('0x2e')],qs['fields'](_0x16d254[_0x4c08('0x31')][_0x4c08('0x33')]));_0x40d21f[_0x4c08('0x32')]=_0x40d21f[_0x4c08('0x32')]['length']?_0x40d21f[_0x4c08('0x32')]:_0x1a5eaa[_0x4c08('0x2e')];if(!_0x16d254[_0x4c08('0x31')][_0x4c08('0x34')](_0x4c08('0x35'))){_0x40d21f['limit']=qs[_0x4c08('0x1e')](_0x16d254[_0x4c08('0x31')][_0x4c08('0x1e')]);_0x40d21f[_0x4c08('0x1d')]=qs[_0x4c08('0x1d')](_0x16d254[_0x4c08('0x31')]['offset']);}_0x40d21f[_0x4c08('0x36')]=qs['sort'](_0x16d254['query']['sort']);_0x40d21f[_0x4c08('0x37')]=qs['filters'](_[_0x4c08('0x38')](_0x16d254[_0x4c08('0x31')],_0x1a5eaa[_0x4c08('0x2f')]),_0x361e85);if(_0x16d254[_0x4c08('0x31')]['filter']){_0x40d21f['where']=_[_0x4c08('0x39')](_0x40d21f[_0x4c08('0x37')],{'$or':_[_0x4c08('0x28')](_0x361e85,function(_0x5950f4){if(_0x5950f4[_0x4c08('0x2c')]!==_0x4c08('0x3a')){var _0x5c3142={};_0x5c3142[_0x5950f4[_0x4c08('0x26')]]={'$like':'%'+_0x16d254[_0x4c08('0x31')][_0x4c08('0x3b')]+'%'};return _0x5c3142;}})});}_0x40d21f=_[_0x4c08('0x39')]({},_0x40d21f,_0x16d254[_0x4c08('0x3c')]);var _0x621a97={'where':_0x40d21f['where']};return db['WhatsappQueueReport']['count'](_0x621a97)[_0x4c08('0x24')](function(_0xb32d53){_0x11399f[_0x4c08('0x3d')]=_0xb32d53;if(_0x16d254[_0x4c08('0x31')][_0x4c08('0x3e')]){_0x40d21f[_0x4c08('0x3f')]=[{'all':!![]}];}return db[_0x4c08('0x29')]['findAll'](_0x40d21f);})[_0x4c08('0x24')](function(_0x2b45bc){_0x11399f[_0x4c08('0x40')]=_0x2b45bc;return _0x11399f;})[_0x4c08('0x24')](respondWithFilteredResult(_0x4c8dd9,_0x40d21f))[_0x4c08('0x41')](handleError(_0x4c8dd9,null));};exports[_0x4c08('0x42')]=function(_0x294ab6,_0x43679d){var _0x573594={'raw':!![],'where':{'id':_0x294ab6[_0x4c08('0x43')]['id']}},_0x4f327f={};_0x4f327f[_0x4c08('0x2e')]=_[_0x4c08('0x44')](db[_0x4c08('0x29')][_0x4c08('0x2a')]);_0x4f327f[_0x4c08('0x31')]=_[_0x4c08('0x44')](_0x294ab6[_0x4c08('0x31')]);_0x4f327f['filters']=_[_0x4c08('0x30')](_0x4f327f[_0x4c08('0x2e')],_0x4f327f[_0x4c08('0x31')]);_0x573594[_0x4c08('0x32')]=_['intersection'](_0x4f327f[_0x4c08('0x2e')],qs[_0x4c08('0x33')](_0x294ab6[_0x4c08('0x31')][_0x4c08('0x33')]));_0x573594['attributes']=_0x573594['attributes']['length']?_0x573594['attributes']:_0x4f327f[_0x4c08('0x2e')];if(_0x294ab6[_0x4c08('0x31')][_0x4c08('0x3e')]){_0x573594['include']=[{'all':!![]}];}_0x573594=_[_0x4c08('0x39')]({},_0x573594,_0x294ab6[_0x4c08('0x3c')]);return db[_0x4c08('0x29')][_0x4c08('0x45')](_0x573594)['then'](handleEntityNotFound(_0x43679d,null))['then'](respondWithResult(_0x43679d,null))[_0x4c08('0x41')](handleError(_0x43679d,null));};exports[_0x4c08('0x46')]=function(_0xd6c2da,_0xb484b7){return db[_0x4c08('0x29')][_0x4c08('0x46')](_0xd6c2da['body'],{})['then'](respondWithResult(_0xb484b7,0xc9))[_0x4c08('0x41')](handleError(_0xb484b7,null));};exports['update']=function(_0x2f24ba,_0x401cfe){if(_0x2f24ba[_0x4c08('0x47')]['id']){delete _0x2f24ba[_0x4c08('0x47')]['id'];}return db['WhatsappQueueReport'][_0x4c08('0x45')]({'where':{'id':_0x2f24ba[_0x4c08('0x43')]['id']}})[_0x4c08('0x24')](handleEntityNotFound(_0x401cfe,null))['then'](saveUpdates(_0x2f24ba[_0x4c08('0x47')],null))[_0x4c08('0x24')](respondWithResult(_0x401cfe,null))[_0x4c08('0x41')](handleError(_0x401cfe,null));};exports[_0x4c08('0x48')]=function(_0xb9e842,_0x5646fd){return db['WhatsappQueueReport'][_0x4c08('0x45')]({'where':{'id':_0xb9e842['params']['id']}})['then'](handleEntityNotFound(_0x5646fd,null))['then'](removeEntity(_0x5646fd,null))[_0x4c08('0x41')](handleError(_0x5646fd,null));};exports[_0x4c08('0x49')]=function(_0x3cdd98,_0x14c7d1){return db[_0x4c08('0x29')][_0x4c08('0x49')]()[_0x4c08('0x24')](respondWithResult(_0x14c7d1,null))[_0x4c08('0x41')](handleError(_0x14c7d1,null));};