Built motion from commit (unavailable).|2.5.4
[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 _0x3f48=['attributes','fields','hasOwnProperty','order','sort','pick','filter','where','merge','type','VIRTUAL','options','includeAll','include','findAll','then','rows','catch','show','params','WhatsappQueueReport','length','find','create','body','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','apply','reject','update','destroy','error','stack','name','send','index','map','rawAttributes','fieldName','query','keys','filters','intersection','model'];(function(_0x15dbca,_0x1d7c3c){var _0x326533=function(_0x507ee2){while(--_0x507ee2){_0x15dbca['push'](_0x15dbca['shift']());}};_0x326533(++_0x1d7c3c);}(_0x3f48,0x17c));var _0x83f4=function(_0x214f60,_0x47cf14){_0x214f60=_0x214f60-0x0;var _0x495b37=_0x3f48[_0x214f60];return _0x495b37;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x83f4('0x0'));var zipdir=require(_0x83f4('0x1'));var jsonpatch=require(_0x83f4('0x2'));var rp=require(_0x83f4('0x3'));var moment=require('moment');var BPromise=require(_0x83f4('0x4'));var Mustache=require(_0x83f4('0x5'));var util=require('util');var path=require(_0x83f4('0x6'));var sox=require('sox');var csv=require(_0x83f4('0x7'));var ejs=require(_0x83f4('0x8'));var fs=require('fs');var _=require(_0x83f4('0x9'));var squel=require(_0x83f4('0xa'));var crypto=require(_0x83f4('0xb'));var jsforce=require(_0x83f4('0xc'));var deskjs=require(_0x83f4('0xd'));var toCsv=require(_0x83f4('0x7'));var querystring=require('querystring');var Papa=require(_0x83f4('0xe'));var Redis=require(_0x83f4('0xf'));var authService=require(_0x83f4('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0x83f4('0x11'))(_0x83f4('0x12'));var utils=require(_0x83f4('0x13'));var config=require('../../config/environment');var db=require(_0x83f4('0x14'))['db'];function respondWithStatusCode(_0x54ec95,_0x51b5b6){_0x51b5b6=_0x51b5b6||0xcc;return function(_0x455e42){if(_0x455e42){return _0x54ec95[_0x83f4('0x15')](_0x51b5b6);}return _0x54ec95[_0x83f4('0x16')](_0x51b5b6)[_0x83f4('0x17')]();};}function respondWithResult(_0xdcfc5e,_0x3aee93){_0x3aee93=_0x3aee93||0xc8;return function(_0xcdaf6c){if(_0xcdaf6c){return _0xdcfc5e['status'](_0x3aee93)[_0x83f4('0x18')](_0xcdaf6c);}};}function respondWithFilteredResult(_0x18c56d,_0x204164){return function(_0x8062f){if(_0x8062f){var _0x38f762=_0x8062f[_0x83f4('0x19')],_0x11dc6d=_0x204164[_0x83f4('0x1a')],_0x4f0f62=_0x204164[_0x83f4('0x1a')]+_0x204164[_0x83f4('0x1b')],_0x1b5626;if(_0x4f0f62>=_0x38f762){_0x4f0f62=_0x38f762;_0x1b5626=0xc8;}else{_0x1b5626=0xce;}_0x18c56d['status'](_0x1b5626);return _0x18c56d[_0x83f4('0x1c')]('Content-Range',_0x11dc6d+'-'+_0x4f0f62+'/'+_0x38f762)[_0x83f4('0x18')](_0x8062f);}return null;};}function patchUpdates(_0x3b08d8){return function(_0x411b03){try{jsonpatch[_0x83f4('0x1d')](_0x411b03,_0x3b08d8,!![]);}catch(_0x30ac1d){return BPromise[_0x83f4('0x1e')](_0x30ac1d);}return _0x411b03['save']();};}function saveUpdates(_0x79c248,_0x14575b){return function(_0x2fa788){if(_0x2fa788){return _0x2fa788[_0x83f4('0x1f')](_0x79c248)['then'](function(_0x596ec8){return _0x596ec8;});}return null;};}function removeEntity(_0x2522da,_0x32e3b0){return function(_0x23b228){if(_0x23b228){return _0x23b228[_0x83f4('0x20')]()['then'](function(){_0x2522da[_0x83f4('0x16')](0xcc)[_0x83f4('0x17')]();});}};}function handleEntityNotFound(_0x4115da,_0x10c3b8){return function(_0x5e4f28){if(!_0x5e4f28){_0x4115da[_0x83f4('0x15')](0x194);}return _0x5e4f28;};}function handleError(_0x570ec3,_0x386530){_0x386530=_0x386530||0x1f4;return function(_0x201b2f){logger[_0x83f4('0x21')](_0x201b2f[_0x83f4('0x22')]);if(_0x201b2f[_0x83f4('0x23')]){delete _0x201b2f[_0x83f4('0x23')];}_0x570ec3[_0x83f4('0x16')](_0x386530)[_0x83f4('0x24')](_0x201b2f);};}exports[_0x83f4('0x25')]=function(_0x22ff3f,_0x3ab54d){var _0x4fa94f={},_0x2530be={},_0x4eeab6={'count':0x0,'rows':[]};var _0x5d260d=_[_0x83f4('0x26')](db['WhatsappQueueReport'][_0x83f4('0x27')],function(_0xbc819e){return{'name':_0xbc819e[_0x83f4('0x28')],'type':_0xbc819e['type']['key']};});_0x2530be['model']=_[_0x83f4('0x26')](_0x5d260d,_0x83f4('0x23'));_0x2530be[_0x83f4('0x29')]=_[_0x83f4('0x2a')](_0x22ff3f['query']);_0x2530be[_0x83f4('0x2b')]=_[_0x83f4('0x2c')](_0x2530be[_0x83f4('0x2d')],_0x2530be[_0x83f4('0x29')]);_0x4fa94f[_0x83f4('0x2e')]=_[_0x83f4('0x2c')](_0x2530be[_0x83f4('0x2d')],qs[_0x83f4('0x2f')](_0x22ff3f['query'][_0x83f4('0x2f')]));_0x4fa94f['attributes']=_0x4fa94f[_0x83f4('0x2e')]['length']?_0x4fa94f[_0x83f4('0x2e')]:_0x2530be['model'];if(!_0x22ff3f[_0x83f4('0x29')][_0x83f4('0x30')]('nolimit')){_0x4fa94f[_0x83f4('0x1b')]=qs['limit'](_0x22ff3f[_0x83f4('0x29')]['limit']);_0x4fa94f[_0x83f4('0x1a')]=qs['offset'](_0x22ff3f[_0x83f4('0x29')][_0x83f4('0x1a')]);}_0x4fa94f[_0x83f4('0x31')]=qs[_0x83f4('0x32')](_0x22ff3f[_0x83f4('0x29')][_0x83f4('0x32')]);_0x4fa94f['where']=qs[_0x83f4('0x2b')](_[_0x83f4('0x33')](_0x22ff3f[_0x83f4('0x29')],_0x2530be[_0x83f4('0x2b')]),_0x5d260d);if(_0x22ff3f[_0x83f4('0x29')][_0x83f4('0x34')]){_0x4fa94f[_0x83f4('0x35')]=_[_0x83f4('0x36')](_0x4fa94f[_0x83f4('0x35')],{'$or':_[_0x83f4('0x26')](_0x5d260d,function(_0x2bd764){if(_0x2bd764[_0x83f4('0x37')]!==_0x83f4('0x38')){var _0x6370fa={};_0x6370fa[_0x2bd764[_0x83f4('0x23')]]={'$like':'%'+_0x22ff3f[_0x83f4('0x29')][_0x83f4('0x34')]+'%'};return _0x6370fa;}})});}_0x4fa94f=_[_0x83f4('0x36')]({},_0x4fa94f,_0x22ff3f[_0x83f4('0x39')]);var _0x437853={'where':_0x4fa94f[_0x83f4('0x35')]};return db['WhatsappQueueReport'][_0x83f4('0x19')](_0x437853)['then'](function(_0x583edd){_0x4eeab6[_0x83f4('0x19')]=_0x583edd;if(_0x22ff3f[_0x83f4('0x29')][_0x83f4('0x3a')]){_0x4fa94f[_0x83f4('0x3b')]=[{'all':!![]}];}return db['WhatsappQueueReport'][_0x83f4('0x3c')](_0x4fa94f);})[_0x83f4('0x3d')](function(_0x357112){_0x4eeab6[_0x83f4('0x3e')]=_0x357112;return _0x4eeab6;})['then'](respondWithFilteredResult(_0x3ab54d,_0x4fa94f))[_0x83f4('0x3f')](handleError(_0x3ab54d,null));};exports[_0x83f4('0x40')]=function(_0x116f62,_0x1f9e8c){var _0x224ec8={'raw':!![],'where':{'id':_0x116f62[_0x83f4('0x41')]['id']}},_0x2ebe5b={};_0x2ebe5b[_0x83f4('0x2d')]=_['keys'](db[_0x83f4('0x42')][_0x83f4('0x27')]);_0x2ebe5b['query']=_['keys'](_0x116f62[_0x83f4('0x29')]);_0x2ebe5b[_0x83f4('0x2b')]=_[_0x83f4('0x2c')](_0x2ebe5b[_0x83f4('0x2d')],_0x2ebe5b[_0x83f4('0x29')]);_0x224ec8[_0x83f4('0x2e')]=_[_0x83f4('0x2c')](_0x2ebe5b[_0x83f4('0x2d')],qs['fields'](_0x116f62[_0x83f4('0x29')]['fields']));_0x224ec8[_0x83f4('0x2e')]=_0x224ec8[_0x83f4('0x2e')][_0x83f4('0x43')]?_0x224ec8[_0x83f4('0x2e')]:_0x2ebe5b[_0x83f4('0x2d')];if(_0x116f62['query']['includeAll']){_0x224ec8[_0x83f4('0x3b')]=[{'all':!![]}];}_0x224ec8=_[_0x83f4('0x36')]({},_0x224ec8,_0x116f62[_0x83f4('0x39')]);return db[_0x83f4('0x42')][_0x83f4('0x44')](_0x224ec8)['then'](handleEntityNotFound(_0x1f9e8c,null))[_0x83f4('0x3d')](respondWithResult(_0x1f9e8c,null))[_0x83f4('0x3f')](handleError(_0x1f9e8c,null));};exports[_0x83f4('0x45')]=function(_0x2668b7,_0xe90704){return db['WhatsappQueueReport'][_0x83f4('0x45')](_0x2668b7[_0x83f4('0x46')],{})[_0x83f4('0x3d')](respondWithResult(_0xe90704,0xc9))['catch'](handleError(_0xe90704,null));};exports[_0x83f4('0x1f')]=function(_0x515ad7,_0x5014f1){if(_0x515ad7['body']['id']){delete _0x515ad7[_0x83f4('0x46')]['id'];}return db[_0x83f4('0x42')][_0x83f4('0x44')]({'where':{'id':_0x515ad7[_0x83f4('0x41')]['id']}})[_0x83f4('0x3d')](handleEntityNotFound(_0x5014f1,null))[_0x83f4('0x3d')](saveUpdates(_0x515ad7[_0x83f4('0x46')],null))[_0x83f4('0x3d')](respondWithResult(_0x5014f1,null))[_0x83f4('0x3f')](handleError(_0x5014f1,null));};exports[_0x83f4('0x20')]=function(_0x2a2e77,_0x4ec4a7){return db['WhatsappQueueReport']['find']({'where':{'id':_0x2a2e77[_0x83f4('0x41')]['id']}})[_0x83f4('0x3d')](handleEntityNotFound(_0x4ec4a7,null))[_0x83f4('0x3d')](removeEntity(_0x4ec4a7,null))[_0x83f4('0x3f')](handleError(_0x4ec4a7,null));};exports['describe']=function(_0x3d5d61,_0x459c26){return db['WhatsappQueueReport']['describe']()[_0x83f4('0x3d')](respondWithResult(_0x459c26,null))[_0x83f4('0x3f')](handleError(_0x459c26,null));};