Built motion from commit (unavailable).|2.5.1
[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 _0xd937=['nolimit','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','params','find','create','body','catch','update','destroy','describe','html-pdf','rimraf','zip-dir','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','count','offset','limit','set','Content-Range','apply','reject','then','end','error','stack','name','send','index','map','WhatsappQueueReport','rawAttributes','fieldName','type','key','model','keys','filters','intersection','query','attributes','fields','length','hasOwnProperty'];(function(_0x4b5813,_0x5769de){var _0x423465=function(_0x18071f){while(--_0x18071f){_0x4b5813['push'](_0x4b5813['shift']());}};_0x423465(++_0x5769de);}(_0xd937,0x137));var _0x7d93=function(_0x441f3a,_0x1e066a){_0x441f3a=_0x441f3a-0x0;var _0x3cb22e=_0xd937[_0x441f3a];return _0x3cb22e;};'use strict';var pdf=require(_0x7d93('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x7d93('0x1'));var zipdir=require(_0x7d93('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x7d93('0x3'));var moment=require('moment');var BPromise=require(_0x7d93('0x4'));var Mustache=require(_0x7d93('0x5'));var util=require(_0x7d93('0x6'));var path=require(_0x7d93('0x7'));var sox=require(_0x7d93('0x8'));var csv=require(_0x7d93('0x9'));var ejs=require(_0x7d93('0xa'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x7d93('0xb'));var deskjs=require(_0x7d93('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x7d93('0xd'));var authService=require(_0x7d93('0xe'));var qs=require(_0x7d93('0xf'));var as=require(_0x7d93('0x10'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x7d93('0x11'))(_0x7d93('0x12'));var utils=require('../../config/utils');var config=require(_0x7d93('0x13'));var licenseUtil=require(_0x7d93('0x14'));var db=require(_0x7d93('0x15'))['db'];function respondWithStatusCode(_0x268437,_0x437b99){_0x437b99=_0x437b99||0xcc;return function(_0x2fa1b7){if(_0x2fa1b7){return _0x268437[_0x7d93('0x16')](_0x437b99);}return _0x268437[_0x7d93('0x17')](_0x437b99)['end']();};}function respondWithResult(_0x2e8c3d,_0x505dad){_0x505dad=_0x505dad||0xc8;return function(_0xf71369){if(_0xf71369){return _0x2e8c3d[_0x7d93('0x17')](_0x505dad)[_0x7d93('0x18')](_0xf71369);}};}function respondWithFilteredResult(_0x2d8f5f,_0x144d84){return function(_0x54e716){if(_0x54e716){var _0x7d73b6=_0x54e716[_0x7d93('0x19')],_0x455a68=_0x144d84[_0x7d93('0x1a')],_0x1be451=_0x144d84[_0x7d93('0x1a')]+_0x144d84[_0x7d93('0x1b')],_0x45cd3f;if(_0x1be451>=_0x7d73b6){_0x1be451=_0x7d73b6;_0x45cd3f=0xc8;}else{_0x45cd3f=0xce;}_0x2d8f5f['status'](_0x45cd3f);return _0x2d8f5f[_0x7d93('0x1c')](_0x7d93('0x1d'),_0x455a68+'-'+_0x1be451+'/'+_0x7d73b6)['json'](_0x54e716);}return null;};}function patchUpdates(_0x29ad5d){return function(_0x3b87cc){try{jsonpatch[_0x7d93('0x1e')](_0x3b87cc,_0x29ad5d,!![]);}catch(_0x5c6bec){return BPromise[_0x7d93('0x1f')](_0x5c6bec);}return _0x3b87cc['save']();};}function saveUpdates(_0x557d55,_0x5dd457){return function(_0x2b659d){if(_0x2b659d){return _0x2b659d['update'](_0x557d55)[_0x7d93('0x20')](function(_0x55a189){return _0x55a189;});}return null;};}function removeEntity(_0x4599a3,_0x39f6d4){return function(_0x537379){if(_0x537379){return _0x537379['destroy']()[_0x7d93('0x20')](function(){_0x4599a3[_0x7d93('0x17')](0xcc)[_0x7d93('0x21')]();});}};}function handleEntityNotFound(_0x39dc2b,_0x1c714c){return function(_0x100a70){if(!_0x100a70){_0x39dc2b[_0x7d93('0x16')](0x194);}return _0x100a70;};}function handleError(_0x31ae91,_0x7dbf5a){_0x7dbf5a=_0x7dbf5a||0x1f4;return function(_0x197076){logger[_0x7d93('0x22')](_0x197076[_0x7d93('0x23')]);if(_0x197076[_0x7d93('0x24')]){delete _0x197076['name'];}_0x31ae91['status'](_0x7dbf5a)[_0x7d93('0x25')](_0x197076);};}exports[_0x7d93('0x26')]=function(_0x2a79e2,_0x42369c){var _0x1ad592={},_0x33725b={},_0x8ef84f={'count':0x0,'rows':[]};var _0x2d4edb=_[_0x7d93('0x27')](db[_0x7d93('0x28')][_0x7d93('0x29')],function(_0x57414e){return{'name':_0x57414e[_0x7d93('0x2a')],'type':_0x57414e[_0x7d93('0x2b')][_0x7d93('0x2c')]};});_0x33725b[_0x7d93('0x2d')]=_['map'](_0x2d4edb,_0x7d93('0x24'));_0x33725b['query']=_[_0x7d93('0x2e')](_0x2a79e2['query']);_0x33725b[_0x7d93('0x2f')]=_[_0x7d93('0x30')](_0x33725b[_0x7d93('0x2d')],_0x33725b[_0x7d93('0x31')]);_0x1ad592[_0x7d93('0x32')]=_[_0x7d93('0x30')](_0x33725b[_0x7d93('0x2d')],qs[_0x7d93('0x33')](_0x2a79e2[_0x7d93('0x31')][_0x7d93('0x33')]));_0x1ad592['attributes']=_0x1ad592['attributes'][_0x7d93('0x34')]?_0x1ad592['attributes']:_0x33725b[_0x7d93('0x2d')];if(!_0x2a79e2[_0x7d93('0x31')][_0x7d93('0x35')](_0x7d93('0x36'))){_0x1ad592[_0x7d93('0x1b')]=qs[_0x7d93('0x1b')](_0x2a79e2[_0x7d93('0x31')][_0x7d93('0x1b')]);_0x1ad592['offset']=qs[_0x7d93('0x1a')](_0x2a79e2['query'][_0x7d93('0x1a')]);}_0x1ad592['order']=qs[_0x7d93('0x37')](_0x2a79e2[_0x7d93('0x31')][_0x7d93('0x37')]);_0x1ad592[_0x7d93('0x38')]=qs['filters'](_[_0x7d93('0x39')](_0x2a79e2['query'],_0x33725b[_0x7d93('0x2f')]),_0x2d4edb);if(_0x2a79e2['query'][_0x7d93('0x3a')]){_0x1ad592[_0x7d93('0x38')]=_[_0x7d93('0x3b')](_0x1ad592[_0x7d93('0x38')],{'$or':_[_0x7d93('0x27')](_0x2d4edb,function(_0x3b8838){if(_0x3b8838[_0x7d93('0x2b')]!==_0x7d93('0x3c')){var _0x48f614={};_0x48f614[_0x3b8838['name']]={'$like':'%'+_0x2a79e2[_0x7d93('0x31')][_0x7d93('0x3a')]+'%'};return _0x48f614;}})});}_0x1ad592=_[_0x7d93('0x3b')]({},_0x1ad592,_0x2a79e2[_0x7d93('0x3d')]);var _0x3dfef1={'where':_0x1ad592[_0x7d93('0x38')]};return db[_0x7d93('0x28')][_0x7d93('0x19')](_0x3dfef1)['then'](function(_0x4624b0){_0x8ef84f['count']=_0x4624b0;if(_0x2a79e2['query'][_0x7d93('0x3e')]){_0x1ad592[_0x7d93('0x3f')]=[{'all':!![]}];}return db[_0x7d93('0x28')][_0x7d93('0x40')](_0x1ad592);})[_0x7d93('0x20')](function(_0x2995b0){_0x8ef84f['rows']=_0x2995b0;return _0x8ef84f;})[_0x7d93('0x20')](respondWithFilteredResult(_0x42369c,_0x1ad592))['catch'](handleError(_0x42369c,null));};exports['show']=function(_0x308b97,_0x285df6){var _0x39bdba={'raw':!![],'where':{'id':_0x308b97[_0x7d93('0x41')]['id']}},_0x379905={};_0x379905[_0x7d93('0x2d')]=_['keys'](db[_0x7d93('0x28')]['rawAttributes']);_0x379905['query']=_[_0x7d93('0x2e')](_0x308b97['query']);_0x379905['filters']=_[_0x7d93('0x30')](_0x379905[_0x7d93('0x2d')],_0x379905[_0x7d93('0x31')]);_0x39bdba['attributes']=_[_0x7d93('0x30')](_0x379905['model'],qs[_0x7d93('0x33')](_0x308b97['query'][_0x7d93('0x33')]));_0x39bdba['attributes']=_0x39bdba[_0x7d93('0x32')][_0x7d93('0x34')]?_0x39bdba[_0x7d93('0x32')]:_0x379905[_0x7d93('0x2d')];if(_0x308b97[_0x7d93('0x31')][_0x7d93('0x3e')]){_0x39bdba['include']=[{'all':!![]}];}_0x39bdba=_[_0x7d93('0x3b')]({},_0x39bdba,_0x308b97['options']);return db['WhatsappQueueReport'][_0x7d93('0x42')](_0x39bdba)[_0x7d93('0x20')](handleEntityNotFound(_0x285df6,null))['then'](respondWithResult(_0x285df6,null))['catch'](handleError(_0x285df6,null));};exports[_0x7d93('0x43')]=function(_0x4d1199,_0x4c6a2c){return db['WhatsappQueueReport'][_0x7d93('0x43')](_0x4d1199[_0x7d93('0x44')],{})[_0x7d93('0x20')](respondWithResult(_0x4c6a2c,0xc9))[_0x7d93('0x45')](handleError(_0x4c6a2c,null));};exports[_0x7d93('0x46')]=function(_0x3b59ab,_0x1c6048){if(_0x3b59ab[_0x7d93('0x44')]['id']){delete _0x3b59ab[_0x7d93('0x44')]['id'];}return db[_0x7d93('0x28')][_0x7d93('0x42')]({'where':{'id':_0x3b59ab[_0x7d93('0x41')]['id']}})[_0x7d93('0x20')](handleEntityNotFound(_0x1c6048,null))[_0x7d93('0x20')](saveUpdates(_0x3b59ab['body'],null))['then'](respondWithResult(_0x1c6048,null))[_0x7d93('0x45')](handleError(_0x1c6048,null));};exports[_0x7d93('0x47')]=function(_0x4d0236,_0x187597){return db[_0x7d93('0x28')][_0x7d93('0x42')]({'where':{'id':_0x4d0236['params']['id']}})[_0x7d93('0x20')](handleEntityNotFound(_0x187597,null))['then'](removeEntity(_0x187597,null))[_0x7d93('0x45')](handleError(_0x187597,null));};exports[_0x7d93('0x48')]=function(_0x54712b,_0x5d2341){return db[_0x7d93('0x28')][_0x7d93('0x48')]()[_0x7d93('0x20')](respondWithResult(_0x5d2341,null))[_0x7d93('0x45')](handleError(_0x5d2341,null));};