8240101992aacf6c968659bb43eea50df3587214
[motion2.git] / server / api / mailQueueReport / mailQueueReport.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 _0x3bc7=['contact','message','agent','account','index','MailQueueReport','rawAttributes','fieldName','key','model','map','keys','filters','query','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','pick','filter','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','merge','create','body','destroy','find','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','update','then','end','error','name','send'];(function(_0x2c4702,_0x3857ed){var _0x54d0a3=function(_0x903ba8){while(--_0x903ba8){_0x2c4702['push'](_0x2c4702['shift']());}};_0x54d0a3(++_0x3857ed);}(_0x3bc7,0xd2));var _0x73bc=function(_0x1bfac9,_0x28eb7d){_0x1bfac9=_0x1bfac9-0x0;var _0x3fca98=_0x3bc7[_0x1bfac9];return _0x3fca98;};'use strict';var emlformat=require(_0x73bc('0x0'));var rimraf=require(_0x73bc('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x73bc('0x2'));var rp=require(_0x73bc('0x3'));var moment=require(_0x73bc('0x4'));var BPromise=require(_0x73bc('0x5'));var Mustache=require(_0x73bc('0x6'));var util=require(_0x73bc('0x7'));var path=require(_0x73bc('0x8'));var sox=require(_0x73bc('0x9'));var csv=require('to-csv');var ejs=require(_0x73bc('0xa'));var fs=require('fs');var fs_extra=require(_0x73bc('0xb'));var _=require(_0x73bc('0xc'));var squel=require(_0x73bc('0xd'));var crypto=require('crypto');var jsforce=require(_0x73bc('0xe'));var deskjs=require(_0x73bc('0xf'));var toCsv=require(_0x73bc('0x10'));var querystring=require(_0x73bc('0x11'));var Papa=require(_0x73bc('0x12'));var Redis=require(_0x73bc('0x13'));var authService=require(_0x73bc('0x14'));var qs=require(_0x73bc('0x15'));var as=require(_0x73bc('0x16'));var hardwareService=require(_0x73bc('0x17'));var logger=require(_0x73bc('0x18'))(_0x73bc('0x19'));var utils=require(_0x73bc('0x1a'));var config=require(_0x73bc('0x1b'));var licenseUtil=require(_0x73bc('0x1c'));var db=require(_0x73bc('0x1d'))['db'];function respondWithStatusCode(_0x19034b,_0x570c9e){_0x570c9e=_0x570c9e||0xcc;return function(_0x199a0a){if(_0x199a0a){return _0x19034b[_0x73bc('0x1e')](_0x570c9e);}return _0x19034b['status'](_0x570c9e)['end']();};}function respondWithResult(_0x250deb,_0xa8649a){_0xa8649a=_0xa8649a||0xc8;return function(_0x2d950c){if(_0x2d950c){return _0x250deb[_0x73bc('0x1f')](_0xa8649a)[_0x73bc('0x20')](_0x2d950c);}};}function respondWithFilteredResult(_0x503bb2,_0x2e5a60){return function(_0x266cbc){if(_0x266cbc){var _0x594d35=typeof _0x2e5a60[_0x73bc('0x21')]==='undefined'&&typeof _0x2e5a60[_0x73bc('0x22')]===_0x73bc('0x23');var _0x3ab735=_0x266cbc[_0x73bc('0x24')];var _0x20028d=_0x594d35?0x0:_0x2e5a60[_0x73bc('0x21')];var _0x170e33=_0x594d35?_0x266cbc['count']:_0x2e5a60['offset']+_0x2e5a60[_0x73bc('0x22')];var _0x24e5a0;if(_0x170e33>=_0x3ab735){_0x170e33=_0x3ab735;_0x24e5a0=0xc8;}else{_0x24e5a0=0xce;}_0x503bb2[_0x73bc('0x1f')](_0x24e5a0);return _0x503bb2[_0x73bc('0x25')](_0x73bc('0x26'),_0x20028d+'-'+_0x170e33+'/'+_0x3ab735)['json'](_0x266cbc);}return null;};}function patchUpdates(_0x519545){return function(_0x4d5108){try{jsonpatch['apply'](_0x4d5108,_0x519545,!![]);}catch(_0x3f2075){return BPromise['reject'](_0x3f2075);}return _0x4d5108['save']();};}function saveUpdates(_0x4fec8f,_0x5b5cb3){return function(_0x658ff0){if(_0x658ff0){return _0x658ff0[_0x73bc('0x27')](_0x4fec8f)['then'](function(_0x17f717){return _0x17f717;});}return null;};}function removeEntity(_0x59d8cc,_0x5f0dc8){return function(_0x1ffccb){if(_0x1ffccb){return _0x1ffccb['destroy']()[_0x73bc('0x28')](function(){_0x59d8cc['status'](0xcc)[_0x73bc('0x29')]();});}};}function handleEntityNotFound(_0x5ae534,_0x3b4df1){return function(_0x34358e){if(!_0x34358e){_0x5ae534['sendStatus'](0x194);}return _0x34358e;};}function handleError(_0x1ad9ca,_0x333c43){_0x333c43=_0x333c43||0x1f4;return function(_0x10c41e){logger[_0x73bc('0x2a')](_0x10c41e['stack']);if(_0x10c41e[_0x73bc('0x2b')]){delete _0x10c41e[_0x73bc('0x2b')];}_0x1ad9ca[_0x73bc('0x1f')](_0x333c43)[_0x73bc('0x2c')](_0x10c41e);};}function getMustacheRender(_0x55d36b,_0x14dd07){return Mustache['render'](_0x55d36b,_['merge'](_0x14dd07['body'],{'contact':_0x14dd07[_0x73bc('0x2d')],'message':_0x14dd07[_0x73bc('0x2e')],'agent':_0x14dd07[_0x73bc('0x2f')],'interaction':_0x14dd07['interaction'],'account':_0x14dd07[_0x73bc('0x30')]}))||'';}exports[_0x73bc('0x31')]=function(_0x4e3216,_0x4a372b){var _0x576569={},_0x171e4b={},_0x4d2959={'count':0x0,'rows':[]};var _0x3197ba=_['map'](db[_0x73bc('0x32')][_0x73bc('0x33')],function(_0x312617){return{'name':_0x312617[_0x73bc('0x34')],'type':_0x312617['type'][_0x73bc('0x35')]};});_0x171e4b[_0x73bc('0x36')]=_[_0x73bc('0x37')](_0x3197ba,_0x73bc('0x2b'));_0x171e4b['query']=_[_0x73bc('0x38')](_0x4e3216['query']);_0x171e4b[_0x73bc('0x39')]=_['intersection'](_0x171e4b[_0x73bc('0x36')],_0x171e4b[_0x73bc('0x3a')]);_0x576569[_0x73bc('0x3b')]=_[_0x73bc('0x3c')](_0x171e4b[_0x73bc('0x36')],qs[_0x73bc('0x3d')](_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x3d')]));_0x576569['attributes']=_0x576569[_0x73bc('0x3b')][_0x73bc('0x3e')]?_0x576569['attributes']:_0x171e4b['model'];if(!_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x3f')]('nolimit')){_0x576569['limit']=qs['limit'](_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x22')]);_0x576569[_0x73bc('0x21')]=qs[_0x73bc('0x21')](_0x4e3216['query'][_0x73bc('0x21')]);}_0x576569[_0x73bc('0x40')]=qs[_0x73bc('0x41')](_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x41')]);_0x576569[_0x73bc('0x42')]=qs[_0x73bc('0x39')](_[_0x73bc('0x43')](_0x4e3216[_0x73bc('0x3a')],_0x171e4b[_0x73bc('0x39')]),_0x3197ba);if(_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x44')]){_0x576569[_0x73bc('0x42')]=_['merge'](_0x576569['where'],{'$or':_[_0x73bc('0x37')](_0x3197ba,function(_0x42648e){if(_0x42648e[_0x73bc('0x45')]!==_0x73bc('0x46')){var _0x5eddb3={};_0x5eddb3[_0x42648e[_0x73bc('0x2b')]]={'$like':'%'+_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x44')]+'%'};return _0x5eddb3;}})});}_0x576569=_['merge']({},_0x576569,_0x4e3216[_0x73bc('0x47')]);var _0x2e907b={'where':_0x576569[_0x73bc('0x42')]};return db[_0x73bc('0x32')][_0x73bc('0x24')](_0x2e907b)[_0x73bc('0x28')](function(_0x384611){_0x4d2959[_0x73bc('0x24')]=_0x384611;if(_0x4e3216[_0x73bc('0x3a')][_0x73bc('0x48')]){_0x576569[_0x73bc('0x49')]=[{'all':!![]}];}return db[_0x73bc('0x32')][_0x73bc('0x4a')](_0x576569);})['then'](function(_0xb759de){_0x4d2959[_0x73bc('0x4b')]=_0xb759de;return _0x4d2959;})[_0x73bc('0x28')](respondWithFilteredResult(_0x4a372b,_0x576569))[_0x73bc('0x4c')](handleError(_0x4a372b,null));};exports[_0x73bc('0x4d')]=function(_0x5452a9,_0x337f60){var _0x3bb707={'raw':!![],'where':{'id':_0x5452a9[_0x73bc('0x4e')]['id']}},_0x30e9a4={};_0x30e9a4[_0x73bc('0x36')]=_[_0x73bc('0x38')](db[_0x73bc('0x32')]['rawAttributes']);_0x30e9a4['query']=_[_0x73bc('0x38')](_0x5452a9[_0x73bc('0x3a')]);_0x30e9a4[_0x73bc('0x39')]=_[_0x73bc('0x3c')](_0x30e9a4['model'],_0x30e9a4['query']);_0x3bb707[_0x73bc('0x3b')]=_[_0x73bc('0x3c')](_0x30e9a4[_0x73bc('0x36')],qs['fields'](_0x5452a9[_0x73bc('0x3a')][_0x73bc('0x3d')]));_0x3bb707['attributes']=_0x3bb707['attributes'][_0x73bc('0x3e')]?_0x3bb707[_0x73bc('0x3b')]:_0x30e9a4[_0x73bc('0x36')];if(_0x5452a9[_0x73bc('0x3a')][_0x73bc('0x48')]){_0x3bb707[_0x73bc('0x49')]=[{'all':!![]}];}_0x3bb707=_[_0x73bc('0x4f')]({},_0x3bb707,_0x5452a9[_0x73bc('0x47')]);return db[_0x73bc('0x32')]['find'](_0x3bb707)[_0x73bc('0x28')](handleEntityNotFound(_0x337f60,null))[_0x73bc('0x28')](respondWithResult(_0x337f60,null))[_0x73bc('0x4c')](handleError(_0x337f60,null));};exports['create']=function(_0x6ffcf9,_0x3766cc){return db[_0x73bc('0x32')][_0x73bc('0x50')](_0x6ffcf9[_0x73bc('0x51')],{})[_0x73bc('0x28')](respondWithResult(_0x3766cc,0xc9))[_0x73bc('0x4c')](handleError(_0x3766cc,null));};exports['update']=function(_0x338eff,_0x13c578){if(_0x338eff[_0x73bc('0x51')]['id']){delete _0x338eff[_0x73bc('0x51')]['id'];}return db['MailQueueReport']['find']({'where':{'id':_0x338eff[_0x73bc('0x4e')]['id']}})['then'](handleEntityNotFound(_0x13c578,null))['then'](saveUpdates(_0x338eff[_0x73bc('0x51')],null))[_0x73bc('0x28')](respondWithResult(_0x13c578,null))[_0x73bc('0x4c')](handleError(_0x13c578,null));};exports[_0x73bc('0x52')]=function(_0x250fcb,_0x39458f){return db['MailQueueReport'][_0x73bc('0x53')]({'where':{'id':_0x250fcb[_0x73bc('0x4e')]['id']}})[_0x73bc('0x28')](handleEntityNotFound(_0x39458f,null))[_0x73bc('0x28')](removeEntity(_0x39458f,null))[_0x73bc('0x4c')](handleError(_0x39458f,null));};exports[_0x73bc('0x54')]=function(_0x3fc5ff,_0x32e9bd){return db[_0x73bc('0x32')][_0x73bc('0x54')]()[_0x73bc('0x28')](respondWithResult(_0x32e9bd,null))[_0x73bc('0x4c')](handleError(_0x32e9bd,null));};