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 _0x0b41=['findAll','rows','catch','params','includeAll','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','WhatsappQueueReport','rawAttributes','fieldName','key','map','query','keys','filters','intersection','model','attributes','fields','length','nolimit','order','sort','where','pick','merge','VIRTUAL','filter','options','include'];(function(_0x441f45,_0x16130c){var _0x2bc267=function(_0x44f8a4){while(--_0x44f8a4){_0x441f45['push'](_0x441f45['shift']());}};_0x2bc267(++_0x16130c);}(_0x0b41,0xf3));var _0x10b4=function(_0x446c10,_0x36313f){_0x446c10=_0x446c10-0x0;var _0x49d86c=_0x0b41[_0x446c10];return _0x49d86c;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x10b4('0x0'));var rimraf=require(_0x10b4('0x1'));var zipdir=require(_0x10b4('0x2'));var jsonpatch=require(_0x10b4('0x3'));var rp=require(_0x10b4('0x4'));var moment=require(_0x10b4('0x5'));var BPromise=require(_0x10b4('0x6'));var Mustache=require(_0x10b4('0x7'));var util=require(_0x10b4('0x8'));var path=require(_0x10b4('0x9'));var sox=require(_0x10b4('0xa'));var csv=require(_0x10b4('0xb'));var ejs=require(_0x10b4('0xc'));var fs=require('fs');var _=require(_0x10b4('0xd'));var squel=require(_0x10b4('0xe'));var crypto=require(_0x10b4('0xf'));var jsforce=require(_0x10b4('0x10'));var deskjs=require('desk.js');var toCsv=require(_0x10b4('0xb'));var querystring=require(_0x10b4('0x11'));var Papa=require('papaparse');var Redis=require(_0x10b4('0x12'));var authService=require(_0x10b4('0x13'));var qs=require(_0x10b4('0x14'));var as=require(_0x10b4('0x15'));var hardwareService=require(_0x10b4('0x16'));var logger=require(_0x10b4('0x17'))(_0x10b4('0x18'));var utils=require(_0x10b4('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x10b4('0x1a'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x44d230,_0x192c52){_0x192c52=_0x192c52||0xcc;return function(_0x2ddcae){if(_0x2ddcae){return _0x44d230[_0x10b4('0x1b')](_0x192c52);}return _0x44d230[_0x10b4('0x1c')](_0x192c52)[_0x10b4('0x1d')]();};}function respondWithResult(_0x423b2f,_0x1041d1){_0x1041d1=_0x1041d1||0xc8;return function(_0x5dd623){if(_0x5dd623){return _0x423b2f['status'](_0x1041d1)[_0x10b4('0x1e')](_0x5dd623);}};}function respondWithFilteredResult(_0x3b1b22,_0x53d134){return function(_0x36fb27){if(_0x36fb27){var _0x114180=_0x36fb27[_0x10b4('0x1f')],_0x57ec98=_0x53d134[_0x10b4('0x20')],_0x12abc4=_0x53d134[_0x10b4('0x20')]+_0x53d134[_0x10b4('0x21')],_0x24ac7d;if(_0x12abc4>=_0x114180){_0x12abc4=_0x114180;_0x24ac7d=0xc8;}else{_0x24ac7d=0xce;}_0x3b1b22[_0x10b4('0x1c')](_0x24ac7d);return _0x3b1b22[_0x10b4('0x22')](_0x10b4('0x23'),_0x57ec98+'-'+_0x12abc4+'/'+_0x114180)[_0x10b4('0x1e')](_0x36fb27);}return null;};}function patchUpdates(_0x1822e0){return function(_0x4d9353){try{jsonpatch[_0x10b4('0x24')](_0x4d9353,_0x1822e0,!![]);}catch(_0x1af2c9){return BPromise[_0x10b4('0x25')](_0x1af2c9);}return _0x4d9353[_0x10b4('0x26')]();};}function saveUpdates(_0x16d3d3,_0x4734de){return function(_0x89d4e5){if(_0x89d4e5){return _0x89d4e5[_0x10b4('0x27')](_0x16d3d3)[_0x10b4('0x28')](function(_0x23a534){return _0x23a534;});}return null;};}function removeEntity(_0x45136e,_0x1043be){return function(_0x26d551){if(_0x26d551){return _0x26d551[_0x10b4('0x29')]()['then'](function(){_0x45136e[_0x10b4('0x1c')](0xcc)[_0x10b4('0x1d')]();});}};}function handleEntityNotFound(_0x1e9e12,_0x10a161){return function(_0x264b49){if(!_0x264b49){_0x1e9e12[_0x10b4('0x1b')](0x194);}return _0x264b49;};}function handleError(_0x206315,_0x2bd3f6){_0x2bd3f6=_0x2bd3f6||0x1f4;return function(_0x17b047){logger[_0x10b4('0x2a')](_0x17b047['stack']);if(_0x17b047[_0x10b4('0x2b')]){delete _0x17b047['name'];}_0x206315[_0x10b4('0x1c')](_0x2bd3f6)[_0x10b4('0x2c')](_0x17b047);};}exports[_0x10b4('0x2d')]=function(_0x396625,_0x3118c6){var _0x4e4c06={},_0x513154={},_0xfad3c7={'count':0x0,'rows':[]};var _0x2b5dc6=_['map'](db[_0x10b4('0x2e')][_0x10b4('0x2f')],function(_0x3359c5){return{'name':_0x3359c5[_0x10b4('0x30')],'type':_0x3359c5['type'][_0x10b4('0x31')]};});_0x513154['model']=_[_0x10b4('0x32')](_0x2b5dc6,_0x10b4('0x2b'));_0x513154[_0x10b4('0x33')]=_[_0x10b4('0x34')](_0x396625[_0x10b4('0x33')]);_0x513154[_0x10b4('0x35')]=_[_0x10b4('0x36')](_0x513154[_0x10b4('0x37')],_0x513154[_0x10b4('0x33')]);_0x4e4c06[_0x10b4('0x38')]=_[_0x10b4('0x36')](_0x513154['model'],qs[_0x10b4('0x39')](_0x396625[_0x10b4('0x33')][_0x10b4('0x39')]));_0x4e4c06['attributes']=_0x4e4c06[_0x10b4('0x38')][_0x10b4('0x3a')]?_0x4e4c06[_0x10b4('0x38')]:_0x513154[_0x10b4('0x37')];if(!_0x396625[_0x10b4('0x33')]['hasOwnProperty'](_0x10b4('0x3b'))){_0x4e4c06['limit']=qs[_0x10b4('0x21')](_0x396625[_0x10b4('0x33')][_0x10b4('0x21')]);_0x4e4c06[_0x10b4('0x20')]=qs[_0x10b4('0x20')](_0x396625[_0x10b4('0x33')][_0x10b4('0x20')]);}_0x4e4c06[_0x10b4('0x3c')]=qs['sort'](_0x396625[_0x10b4('0x33')][_0x10b4('0x3d')]);_0x4e4c06[_0x10b4('0x3e')]=qs[_0x10b4('0x35')](_[_0x10b4('0x3f')](_0x396625[_0x10b4('0x33')],_0x513154[_0x10b4('0x35')]),_0x2b5dc6);if(_0x396625[_0x10b4('0x33')]['filter']){_0x4e4c06[_0x10b4('0x3e')]=_[_0x10b4('0x40')](_0x4e4c06['where'],{'$or':_[_0x10b4('0x32')](_0x2b5dc6,function(_0x24b5fe){if(_0x24b5fe['type']!==_0x10b4('0x41')){var _0x3e3fe0={};_0x3e3fe0[_0x24b5fe[_0x10b4('0x2b')]]={'$like':'%'+_0x396625[_0x10b4('0x33')][_0x10b4('0x42')]+'%'};return _0x3e3fe0;}})});}_0x4e4c06=_[_0x10b4('0x40')]({},_0x4e4c06,_0x396625[_0x10b4('0x43')]);var _0x556994={'where':_0x4e4c06[_0x10b4('0x3e')]};return db[_0x10b4('0x2e')][_0x10b4('0x1f')](_0x556994)['then'](function(_0xc6c8fb){_0xfad3c7[_0x10b4('0x1f')]=_0xc6c8fb;if(_0x396625['query']['includeAll']){_0x4e4c06[_0x10b4('0x44')]=[{'all':!![]}];}return db[_0x10b4('0x2e')][_0x10b4('0x45')](_0x4e4c06);})[_0x10b4('0x28')](function(_0x16e89f){_0xfad3c7[_0x10b4('0x46')]=_0x16e89f;return _0xfad3c7;})['then'](respondWithFilteredResult(_0x3118c6,_0x4e4c06))[_0x10b4('0x47')](handleError(_0x3118c6,null));};exports['show']=function(_0x2945e7,_0x3def6b){var _0x504a21={'raw':!![],'where':{'id':_0x2945e7[_0x10b4('0x48')]['id']}},_0x2a275b={};_0x2a275b[_0x10b4('0x37')]=_[_0x10b4('0x34')](db[_0x10b4('0x2e')][_0x10b4('0x2f')]);_0x2a275b['query']=_[_0x10b4('0x34')](_0x2945e7['query']);_0x2a275b[_0x10b4('0x35')]=_[_0x10b4('0x36')](_0x2a275b[_0x10b4('0x37')],_0x2a275b['query']);_0x504a21[_0x10b4('0x38')]=_[_0x10b4('0x36')](_0x2a275b[_0x10b4('0x37')],qs[_0x10b4('0x39')](_0x2945e7[_0x10b4('0x33')][_0x10b4('0x39')]));_0x504a21[_0x10b4('0x38')]=_0x504a21[_0x10b4('0x38')][_0x10b4('0x3a')]?_0x504a21['attributes']:_0x2a275b[_0x10b4('0x37')];if(_0x2945e7[_0x10b4('0x33')][_0x10b4('0x49')]){_0x504a21[_0x10b4('0x44')]=[{'all':!![]}];}_0x504a21=_[_0x10b4('0x40')]({},_0x504a21,_0x2945e7[_0x10b4('0x43')]);return db[_0x10b4('0x2e')][_0x10b4('0x4a')](_0x504a21)['then'](handleEntityNotFound(_0x3def6b,null))[_0x10b4('0x28')](respondWithResult(_0x3def6b,null))[_0x10b4('0x47')](handleError(_0x3def6b,null));};exports[_0x10b4('0x4b')]=function(_0x403ef2,_0x560bda){return db[_0x10b4('0x2e')][_0x10b4('0x4b')](_0x403ef2[_0x10b4('0x4c')],{})[_0x10b4('0x28')](respondWithResult(_0x560bda,0xc9))[_0x10b4('0x47')](handleError(_0x560bda,null));};exports[_0x10b4('0x27')]=function(_0x4c7974,_0x149145){if(_0x4c7974[_0x10b4('0x4c')]['id']){delete _0x4c7974[_0x10b4('0x4c')]['id'];}return db['WhatsappQueueReport'][_0x10b4('0x4a')]({'where':{'id':_0x4c7974[_0x10b4('0x48')]['id']}})[_0x10b4('0x28')](handleEntityNotFound(_0x149145,null))['then'](saveUpdates(_0x4c7974[_0x10b4('0x4c')],null))['then'](respondWithResult(_0x149145,null))[_0x10b4('0x47')](handleError(_0x149145,null));};exports[_0x10b4('0x29')]=function(_0x104169,_0x11ae73){return db[_0x10b4('0x2e')][_0x10b4('0x4a')]({'where':{'id':_0x104169[_0x10b4('0x48')]['id']}})[_0x10b4('0x28')](handleEntityNotFound(_0x11ae73,null))[_0x10b4('0x28')](removeEntity(_0x11ae73,null))[_0x10b4('0x47')](handleError(_0x11ae73,null));};exports[_0x10b4('0x4d')]=function(_0x1c6687,_0x1b77f8){return db[_0x10b4('0x2e')]['describe']()[_0x10b4('0x28')](respondWithResult(_0x1b77f8,null))[_0x10b4('0x47')](handleError(_0x1b77f8,null));};