Built motion from commit (unavailable).|2.5.18
[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 _0x9f76=['rawAttributes','fieldName','type','key','model','keys','query','intersection','attributes','fields','hasOwnProperty','nolimit','order','sort','pick','where','filter','options','count','includeAll','include','findAll','rows','filters','length','merge','find','catch','create','body','destroy','params','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','set','Content-Range','apply','reject','save','update','then','end','name','index','map','WhatsappQueueReport'];(function(_0x337da5,_0x23e1e6){var _0x75acdb=function(_0x58f4e1){while(--_0x58f4e1){_0x337da5['push'](_0x337da5['shift']());}};_0x75acdb(++_0x23e1e6);}(_0x9f76,0xbb));var _0x69f7=function(_0x376b45,_0x5964fb){_0x376b45=_0x376b45-0x0;var _0x2341b3=_0x9f76[_0x376b45];return _0x2341b3;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x69f7('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x69f7('0x1'));var jsonpatch=require(_0x69f7('0x2'));var rp=require(_0x69f7('0x3'));var moment=require(_0x69f7('0x4'));var BPromise=require(_0x69f7('0x5'));var Mustache=require(_0x69f7('0x6'));var util=require(_0x69f7('0x7'));var path=require(_0x69f7('0x8'));var sox=require(_0x69f7('0x9'));var csv=require(_0x69f7('0xa'));var ejs=require(_0x69f7('0xb'));var fs=require('fs');var _=require(_0x69f7('0xc'));var squel=require(_0x69f7('0xd'));var crypto=require(_0x69f7('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x69f7('0xf'));var toCsv=require('to-csv');var querystring=require(_0x69f7('0x10'));var Papa=require(_0x69f7('0x11'));var Redis=require('ioredis');var authService=require(_0x69f7('0x12'));var qs=require(_0x69f7('0x13'));var as=require(_0x69f7('0x14'));var hardwareService=require(_0x69f7('0x15'));var logger=require(_0x69f7('0x16'))('api');var utils=require(_0x69f7('0x17'));var config=require(_0x69f7('0x18'));var licenseUtil=require(_0x69f7('0x19'));var db=require(_0x69f7('0x1a'))['db'];function respondWithStatusCode(_0x3c7ea2,_0xbc97f9){_0xbc97f9=_0xbc97f9||0xcc;return function(_0x1a82c5){if(_0x1a82c5){return _0x3c7ea2[_0x69f7('0x1b')](_0xbc97f9);}return _0x3c7ea2[_0x69f7('0x1c')](_0xbc97f9)['end']();};}function respondWithResult(_0x167339,_0x2e1e60){_0x2e1e60=_0x2e1e60||0xc8;return function(_0x48815f){if(_0x48815f){return _0x167339[_0x69f7('0x1c')](_0x2e1e60)[_0x69f7('0x1d')](_0x48815f);}};}function respondWithFilteredResult(_0x48b5c2,_0x4f7466){return function(_0x5b8198){if(_0x5b8198){var _0x14c350=_0x5b8198['count'],_0x44600b=_0x4f7466['offset'],_0x2449b9=_0x4f7466[_0x69f7('0x1e')]+_0x4f7466[_0x69f7('0x1f')],_0x3bb476;if(_0x2449b9>=_0x14c350){_0x2449b9=_0x14c350;_0x3bb476=0xc8;}else{_0x3bb476=0xce;}_0x48b5c2['status'](_0x3bb476);return _0x48b5c2[_0x69f7('0x20')](_0x69f7('0x21'),_0x44600b+'-'+_0x2449b9+'/'+_0x14c350)[_0x69f7('0x1d')](_0x5b8198);}return null;};}function patchUpdates(_0x49ebec){return function(_0x3169f4){try{jsonpatch[_0x69f7('0x22')](_0x3169f4,_0x49ebec,!![]);}catch(_0x3b871e){return BPromise[_0x69f7('0x23')](_0x3b871e);}return _0x3169f4[_0x69f7('0x24')]();};}function saveUpdates(_0x3097a3,_0x3ffecc){return function(_0x3fde9c){if(_0x3fde9c){return _0x3fde9c[_0x69f7('0x25')](_0x3097a3)[_0x69f7('0x26')](function(_0x3e1ca6){return _0x3e1ca6;});}return null;};}function removeEntity(_0x35e64e,_0x581836){return function(_0x434d8d){if(_0x434d8d){return _0x434d8d['destroy']()['then'](function(){_0x35e64e[_0x69f7('0x1c')](0xcc)[_0x69f7('0x27')]();});}};}function handleEntityNotFound(_0x2823a6,_0x4815cf){return function(_0x256ecb){if(!_0x256ecb){_0x2823a6[_0x69f7('0x1b')](0x194);}return _0x256ecb;};}function handleError(_0x309774,_0x2b82c8){_0x2b82c8=_0x2b82c8||0x1f4;return function(_0xf55faf){logger['error'](_0xf55faf['stack']);if(_0xf55faf[_0x69f7('0x28')]){delete _0xf55faf['name'];}_0x309774[_0x69f7('0x1c')](_0x2b82c8)['send'](_0xf55faf);};}exports[_0x69f7('0x29')]=function(_0x4353f5,_0x10150b){var _0x19dd98={},_0x4d0466={},_0x5443f5={'count':0x0,'rows':[]};var _0x2de59e=_[_0x69f7('0x2a')](db[_0x69f7('0x2b')][_0x69f7('0x2c')],function(_0x512ce9){return{'name':_0x512ce9[_0x69f7('0x2d')],'type':_0x512ce9[_0x69f7('0x2e')][_0x69f7('0x2f')]};});_0x4d0466[_0x69f7('0x30')]=_[_0x69f7('0x2a')](_0x2de59e,'name');_0x4d0466['query']=_[_0x69f7('0x31')](_0x4353f5[_0x69f7('0x32')]);_0x4d0466['filters']=_[_0x69f7('0x33')](_0x4d0466[_0x69f7('0x30')],_0x4d0466['query']);_0x19dd98[_0x69f7('0x34')]=_[_0x69f7('0x33')](_0x4d0466[_0x69f7('0x30')],qs['fields'](_0x4353f5[_0x69f7('0x32')][_0x69f7('0x35')]));_0x19dd98[_0x69f7('0x34')]=_0x19dd98[_0x69f7('0x34')]['length']?_0x19dd98[_0x69f7('0x34')]:_0x4d0466['model'];if(!_0x4353f5[_0x69f7('0x32')][_0x69f7('0x36')](_0x69f7('0x37'))){_0x19dd98[_0x69f7('0x1f')]=qs['limit'](_0x4353f5['query']['limit']);_0x19dd98[_0x69f7('0x1e')]=qs[_0x69f7('0x1e')](_0x4353f5[_0x69f7('0x32')]['offset']);}_0x19dd98[_0x69f7('0x38')]=qs[_0x69f7('0x39')](_0x4353f5['query'][_0x69f7('0x39')]);_0x19dd98['where']=qs['filters'](_[_0x69f7('0x3a')](_0x4353f5[_0x69f7('0x32')],_0x4d0466['filters']),_0x2de59e);if(_0x4353f5[_0x69f7('0x32')]['filter']){_0x19dd98[_0x69f7('0x3b')]=_['merge'](_0x19dd98[_0x69f7('0x3b')],{'$or':_[_0x69f7('0x2a')](_0x2de59e,function(_0x3d2e1d){if(_0x3d2e1d[_0x69f7('0x2e')]!=='VIRTUAL'){var _0x34cfbe={};_0x34cfbe[_0x3d2e1d[_0x69f7('0x28')]]={'$like':'%'+_0x4353f5[_0x69f7('0x32')][_0x69f7('0x3c')]+'%'};return _0x34cfbe;}})});}_0x19dd98=_['merge']({},_0x19dd98,_0x4353f5[_0x69f7('0x3d')]);var _0x880b17={'where':_0x19dd98[_0x69f7('0x3b')]};return db[_0x69f7('0x2b')][_0x69f7('0x3e')](_0x880b17)[_0x69f7('0x26')](function(_0x297fa8){_0x5443f5[_0x69f7('0x3e')]=_0x297fa8;if(_0x4353f5[_0x69f7('0x32')][_0x69f7('0x3f')]){_0x19dd98[_0x69f7('0x40')]=[{'all':!![]}];}return db[_0x69f7('0x2b')][_0x69f7('0x41')](_0x19dd98);})[_0x69f7('0x26')](function(_0x5f36b4){_0x5443f5[_0x69f7('0x42')]=_0x5f36b4;return _0x5443f5;})[_0x69f7('0x26')](respondWithFilteredResult(_0x10150b,_0x19dd98))['catch'](handleError(_0x10150b,null));};exports['show']=function(_0x4de4f0,_0x49c3e3){var _0x23269d={'raw':!![],'where':{'id':_0x4de4f0['params']['id']}},_0x5a006b={};_0x5a006b[_0x69f7('0x30')]=_[_0x69f7('0x31')](db['WhatsappQueueReport'][_0x69f7('0x2c')]);_0x5a006b[_0x69f7('0x32')]=_[_0x69f7('0x31')](_0x4de4f0['query']);_0x5a006b[_0x69f7('0x43')]=_['intersection'](_0x5a006b[_0x69f7('0x30')],_0x5a006b[_0x69f7('0x32')]);_0x23269d[_0x69f7('0x34')]=_[_0x69f7('0x33')](_0x5a006b[_0x69f7('0x30')],qs[_0x69f7('0x35')](_0x4de4f0[_0x69f7('0x32')][_0x69f7('0x35')]));_0x23269d[_0x69f7('0x34')]=_0x23269d[_0x69f7('0x34')][_0x69f7('0x44')]?_0x23269d[_0x69f7('0x34')]:_0x5a006b[_0x69f7('0x30')];if(_0x4de4f0[_0x69f7('0x32')][_0x69f7('0x3f')]){_0x23269d[_0x69f7('0x40')]=[{'all':!![]}];}_0x23269d=_[_0x69f7('0x45')]({},_0x23269d,_0x4de4f0['options']);return db[_0x69f7('0x2b')][_0x69f7('0x46')](_0x23269d)[_0x69f7('0x26')](handleEntityNotFound(_0x49c3e3,null))[_0x69f7('0x26')](respondWithResult(_0x49c3e3,null))[_0x69f7('0x47')](handleError(_0x49c3e3,null));};exports[_0x69f7('0x48')]=function(_0xe9226e,_0x5e7686){return db[_0x69f7('0x2b')][_0x69f7('0x48')](_0xe9226e[_0x69f7('0x49')],{})[_0x69f7('0x26')](respondWithResult(_0x5e7686,0xc9))[_0x69f7('0x47')](handleError(_0x5e7686,null));};exports[_0x69f7('0x25')]=function(_0x552f0f,_0x35b342){if(_0x552f0f['body']['id']){delete _0x552f0f[_0x69f7('0x49')]['id'];}return db['WhatsappQueueReport'][_0x69f7('0x46')]({'where':{'id':_0x552f0f['params']['id']}})[_0x69f7('0x26')](handleEntityNotFound(_0x35b342,null))[_0x69f7('0x26')](saveUpdates(_0x552f0f['body'],null))[_0x69f7('0x26')](respondWithResult(_0x35b342,null))[_0x69f7('0x47')](handleError(_0x35b342,null));};exports[_0x69f7('0x4a')]=function(_0x3cf6c6,_0x1a2991){return db[_0x69f7('0x2b')]['find']({'where':{'id':_0x3cf6c6[_0x69f7('0x4b')]['id']}})[_0x69f7('0x26')](handleEntityNotFound(_0x1a2991,null))['then'](removeEntity(_0x1a2991,null))[_0x69f7('0x47')](handleError(_0x1a2991,null));};exports[_0x69f7('0x4c')]=function(_0x56a96d,_0x5f1694){return db[_0x69f7('0x2b')][_0x69f7('0x4c')]()[_0x69f7('0x26')](respondWithResult(_0x5f1694,null))[_0x69f7('0x47')](handleError(_0x5f1694,null));};