Built motion from commit (unavailable).|2.5.13
[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 _0x348e=['pick','filter','VIRTUAL','merge','options','includeAll','include','catch','show','find','create','body','destroy','describe','html-pdf','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','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','save','update','then','end','name','send','index','map','WhatsappQueueReport','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where'];(function(_0x1476ba,_0x446421){var _0x5e7bc1=function(_0x4aa99c){while(--_0x4aa99c){_0x1476ba['push'](_0x1476ba['shift']());}};_0x5e7bc1(++_0x446421);}(_0x348e,0xa4));var _0xe348=function(_0x1574a1,_0x16f616){_0x1574a1=_0x1574a1-0x0;var _0x190965=_0x348e[_0x1574a1];return _0x190965;};'use strict';var pdf=require(_0xe348('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xe348('0x1'));var jsonpatch=require(_0xe348('0x2'));var rp=require(_0xe348('0x3'));var moment=require(_0xe348('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xe348('0x5'));var util=require(_0xe348('0x6'));var path=require(_0xe348('0x7'));var sox=require(_0xe348('0x8'));var csv=require(_0xe348('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xe348('0xa'));var squel=require(_0xe348('0xb'));var crypto=require(_0xe348('0xc'));var jsforce=require(_0xe348('0xd'));var deskjs=require(_0xe348('0xe'));var toCsv=require(_0xe348('0x9'));var querystring=require(_0xe348('0xf'));var Papa=require(_0xe348('0x10'));var Redis=require(_0xe348('0x11'));var authService=require(_0xe348('0x12'));var qs=require(_0xe348('0x13'));var as=require(_0xe348('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0xe348('0x15'))(_0xe348('0x16'));var utils=require('../../config/utils');var config=require(_0xe348('0x17'));var licenseUtil=require(_0xe348('0x18'));var db=require(_0xe348('0x19'))['db'];function respondWithStatusCode(_0x118c37,_0xf7ab8e){_0xf7ab8e=_0xf7ab8e||0xcc;return function(_0x195fad){if(_0x195fad){return _0x118c37[_0xe348('0x1a')](_0xf7ab8e);}return _0x118c37[_0xe348('0x1b')](_0xf7ab8e)['end']();};}function respondWithResult(_0x5a2f93,_0x36c51c){_0x36c51c=_0x36c51c||0xc8;return function(_0x535fc1){if(_0x535fc1){return _0x5a2f93[_0xe348('0x1b')](_0x36c51c)[_0xe348('0x1c')](_0x535fc1);}};}function respondWithFilteredResult(_0x1a3726,_0x4afc53){return function(_0x5b4374){if(_0x5b4374){var _0x30ba53=_0x5b4374[_0xe348('0x1d')],_0x4e7528=_0x4afc53[_0xe348('0x1e')],_0x5e0928=_0x4afc53[_0xe348('0x1e')]+_0x4afc53[_0xe348('0x1f')],_0x4ca02d;if(_0x5e0928>=_0x30ba53){_0x5e0928=_0x30ba53;_0x4ca02d=0xc8;}else{_0x4ca02d=0xce;}_0x1a3726['status'](_0x4ca02d);return _0x1a3726[_0xe348('0x20')](_0xe348('0x21'),_0x4e7528+'-'+_0x5e0928+'/'+_0x30ba53)['json'](_0x5b4374);}return null;};}function patchUpdates(_0x5493d8){return function(_0x1486c7){try{jsonpatch[_0xe348('0x22')](_0x1486c7,_0x5493d8,!![]);}catch(_0x2db1c1){return BPromise[_0xe348('0x23')](_0x2db1c1);}return _0x1486c7[_0xe348('0x24')]();};}function saveUpdates(_0x49e45d,_0x2b51f2){return function(_0x56e86c){if(_0x56e86c){return _0x56e86c[_0xe348('0x25')](_0x49e45d)[_0xe348('0x26')](function(_0x35469f){return _0x35469f;});}return null;};}function removeEntity(_0xce933c,_0x446afc){return function(_0x75e798){if(_0x75e798){return _0x75e798['destroy']()[_0xe348('0x26')](function(){_0xce933c[_0xe348('0x1b')](0xcc)[_0xe348('0x27')]();});}};}function handleEntityNotFound(_0x3fa5e5,_0x48a3a8){return function(_0x4e938c){if(!_0x4e938c){_0x3fa5e5[_0xe348('0x1a')](0x194);}return _0x4e938c;};}function handleError(_0x2f07b3,_0x5a8f63){_0x5a8f63=_0x5a8f63||0x1f4;return function(_0x1c323a){logger['error'](_0x1c323a['stack']);if(_0x1c323a[_0xe348('0x28')]){delete _0x1c323a[_0xe348('0x28')];}_0x2f07b3[_0xe348('0x1b')](_0x5a8f63)[_0xe348('0x29')](_0x1c323a);};}exports[_0xe348('0x2a')]=function(_0x4f441d,_0x5f16de){var _0x24f363={},_0x53be8c={},_0x5905a4={'count':0x0,'rows':[]};var _0x3f9d27=_[_0xe348('0x2b')](db[_0xe348('0x2c')][_0xe348('0x2d')],function(_0x47beab){return{'name':_0x47beab[_0xe348('0x2e')],'type':_0x47beab[_0xe348('0x2f')]['key']};});_0x53be8c[_0xe348('0x30')]=_[_0xe348('0x2b')](_0x3f9d27,'name');_0x53be8c[_0xe348('0x31')]=_[_0xe348('0x32')](_0x4f441d['query']);_0x53be8c[_0xe348('0x33')]=_[_0xe348('0x34')](_0x53be8c[_0xe348('0x30')],_0x53be8c[_0xe348('0x31')]);_0x24f363[_0xe348('0x35')]=_[_0xe348('0x34')](_0x53be8c[_0xe348('0x30')],qs[_0xe348('0x36')](_0x4f441d[_0xe348('0x31')]['fields']));_0x24f363[_0xe348('0x35')]=_0x24f363[_0xe348('0x35')][_0xe348('0x37')]?_0x24f363[_0xe348('0x35')]:_0x53be8c[_0xe348('0x30')];if(!_0x4f441d[_0xe348('0x31')][_0xe348('0x38')](_0xe348('0x39'))){_0x24f363['limit']=qs['limit'](_0x4f441d['query'][_0xe348('0x1f')]);_0x24f363[_0xe348('0x1e')]=qs['offset'](_0x4f441d[_0xe348('0x31')]['offset']);}_0x24f363[_0xe348('0x3a')]=qs[_0xe348('0x3b')](_0x4f441d[_0xe348('0x31')][_0xe348('0x3b')]);_0x24f363[_0xe348('0x3c')]=qs['filters'](_[_0xe348('0x3d')](_0x4f441d[_0xe348('0x31')],_0x53be8c[_0xe348('0x33')]),_0x3f9d27);if(_0x4f441d[_0xe348('0x31')][_0xe348('0x3e')]){_0x24f363[_0xe348('0x3c')]=_['merge'](_0x24f363['where'],{'$or':_[_0xe348('0x2b')](_0x3f9d27,function(_0x24654c){if(_0x24654c[_0xe348('0x2f')]!==_0xe348('0x3f')){var _0x1dfde2={};_0x1dfde2[_0x24654c[_0xe348('0x28')]]={'$like':'%'+_0x4f441d[_0xe348('0x31')]['filter']+'%'};return _0x1dfde2;}})});}_0x24f363=_[_0xe348('0x40')]({},_0x24f363,_0x4f441d[_0xe348('0x41')]);var _0x439930={'where':_0x24f363['where']};return db[_0xe348('0x2c')][_0xe348('0x1d')](_0x439930)[_0xe348('0x26')](function(_0x176b0d){_0x5905a4[_0xe348('0x1d')]=_0x176b0d;if(_0x4f441d[_0xe348('0x31')][_0xe348('0x42')]){_0x24f363[_0xe348('0x43')]=[{'all':!![]}];}return db[_0xe348('0x2c')]['findAll'](_0x24f363);})[_0xe348('0x26')](function(_0x35a781){_0x5905a4['rows']=_0x35a781;return _0x5905a4;})[_0xe348('0x26')](respondWithFilteredResult(_0x5f16de,_0x24f363))[_0xe348('0x44')](handleError(_0x5f16de,null));};exports[_0xe348('0x45')]=function(_0x42844d,_0x5dfec8){var _0x90ff3c={'raw':!![],'where':{'id':_0x42844d['params']['id']}},_0x287ddb={};_0x287ddb[_0xe348('0x30')]=_[_0xe348('0x32')](db[_0xe348('0x2c')][_0xe348('0x2d')]);_0x287ddb['query']=_[_0xe348('0x32')](_0x42844d[_0xe348('0x31')]);_0x287ddb[_0xe348('0x33')]=_[_0xe348('0x34')](_0x287ddb[_0xe348('0x30')],_0x287ddb['query']);_0x90ff3c[_0xe348('0x35')]=_[_0xe348('0x34')](_0x287ddb['model'],qs[_0xe348('0x36')](_0x42844d[_0xe348('0x31')][_0xe348('0x36')]));_0x90ff3c[_0xe348('0x35')]=_0x90ff3c[_0xe348('0x35')][_0xe348('0x37')]?_0x90ff3c[_0xe348('0x35')]:_0x287ddb[_0xe348('0x30')];if(_0x42844d['query'][_0xe348('0x42')]){_0x90ff3c[_0xe348('0x43')]=[{'all':!![]}];}_0x90ff3c=_[_0xe348('0x40')]({},_0x90ff3c,_0x42844d['options']);return db['WhatsappQueueReport'][_0xe348('0x46')](_0x90ff3c)[_0xe348('0x26')](handleEntityNotFound(_0x5dfec8,null))['then'](respondWithResult(_0x5dfec8,null))[_0xe348('0x44')](handleError(_0x5dfec8,null));};exports[_0xe348('0x47')]=function(_0x4f4f01,_0x159c5b){return db[_0xe348('0x2c')][_0xe348('0x47')](_0x4f4f01['body'],{})[_0xe348('0x26')](respondWithResult(_0x159c5b,0xc9))['catch'](handleError(_0x159c5b,null));};exports['update']=function(_0x26f658,_0x8f5e6f){if(_0x26f658['body']['id']){delete _0x26f658[_0xe348('0x48')]['id'];}return db[_0xe348('0x2c')][_0xe348('0x46')]({'where':{'id':_0x26f658['params']['id']}})[_0xe348('0x26')](handleEntityNotFound(_0x8f5e6f,null))['then'](saveUpdates(_0x26f658['body'],null))[_0xe348('0x26')](respondWithResult(_0x8f5e6f,null))[_0xe348('0x44')](handleError(_0x8f5e6f,null));};exports[_0xe348('0x49')]=function(_0x558b85,_0x314c8f){return db[_0xe348('0x2c')][_0xe348('0x46')]({'where':{'id':_0x558b85['params']['id']}})[_0xe348('0x26')](handleEntityNotFound(_0x314c8f,null))[_0xe348('0x26')](removeEntity(_0x314c8f,null))['catch'](handleError(_0x314c8f,null));};exports[_0xe348('0x4a')]=function(_0x2a2a34,_0x407bdd){return db[_0xe348('0x2c')][_0xe348('0x4a')]()[_0xe348('0x26')](respondWithResult(_0x407bdd,null))[_0xe348('0x44')](handleError(_0x407bdd,null));};