c9f1292264a50600829076ccf868d01e2e12359a
[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 _0x66fc=['order','sort','where','filter','merge','VIRTUAL','options','count','includeAll','include','findAll','rows','catch','params','keys','find','create','body','html-pdf','zip-dir','request-promise','bluebird','mustache','path','sox','to-csv','ejs','lodash','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','offset','limit','Content-Range','apply','reject','save','update','then','destroy','error','name','send','index','map','MailQueueReport','rawAttributes','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit'];(function(_0x3908bc,_0x1f3657){var _0x5a9eee=function(_0x5f4686){while(--_0x5f4686){_0x3908bc['push'](_0x3908bc['shift']());}};_0x5a9eee(++_0x1f3657);}(_0x66fc,0xf3));var _0xc66f=function(_0x4efea0,_0x3d32d8){_0x4efea0=_0x4efea0-0x0;var _0x5c80cc=_0x66fc[_0x4efea0];return _0x5c80cc;};'use strict';var pdf=require(_0xc66f('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xc66f('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0xc66f('0x2'));var moment=require('moment');var BPromise=require(_0xc66f('0x3'));var Mustache=require(_0xc66f('0x4'));var util=require('util');var path=require(_0xc66f('0x5'));var sox=require(_0xc66f('0x6'));var csv=require(_0xc66f('0x7'));var ejs=require(_0xc66f('0x8'));var fs=require('fs');var _=require(_0xc66f('0x9'));var squel=require('squel');var crypto=require(_0xc66f('0xa'));var jsforce=require(_0xc66f('0xb'));var deskjs=require(_0xc66f('0xc'));var toCsv=require(_0xc66f('0x7'));var querystring=require(_0xc66f('0xd'));var Papa=require(_0xc66f('0xe'));var Redis=require(_0xc66f('0xf'));var authService=require(_0xc66f('0x10'));var qs=require(_0xc66f('0x11'));var as=require(_0xc66f('0x12'));var hardwareService=require(_0xc66f('0x13'));var logger=require(_0xc66f('0x14'))(_0xc66f('0x15'));var utils=require(_0xc66f('0x16'));var config=require(_0xc66f('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xc66f('0x18'))['db'];function respondWithStatusCode(_0x575923,_0x347687){_0x347687=_0x347687||0xcc;return function(_0x47b378){if(_0x47b378){return _0x575923[_0xc66f('0x19')](_0x347687);}return _0x575923[_0xc66f('0x1a')](_0x347687)[_0xc66f('0x1b')]();};}function respondWithResult(_0x53aa27,_0x1dbffb){_0x1dbffb=_0x1dbffb||0xc8;return function(_0x36e362){if(_0x36e362){return _0x53aa27[_0xc66f('0x1a')](_0x1dbffb)[_0xc66f('0x1c')](_0x36e362);}};}function respondWithFilteredResult(_0x325f76,_0x2beb2a){return function(_0x1ab79e){if(_0x1ab79e){var _0x26fcc1=_0x1ab79e['count'],_0x3ea53c=_0x2beb2a['offset'],_0x3c02c1=_0x2beb2a[_0xc66f('0x1d')]+_0x2beb2a[_0xc66f('0x1e')],_0x4c15da;if(_0x3c02c1>=_0x26fcc1){_0x3c02c1=_0x26fcc1;_0x4c15da=0xc8;}else{_0x4c15da=0xce;}_0x325f76[_0xc66f('0x1a')](_0x4c15da);return _0x325f76['set'](_0xc66f('0x1f'),_0x3ea53c+'-'+_0x3c02c1+'/'+_0x26fcc1)[_0xc66f('0x1c')](_0x1ab79e);}return null;};}function patchUpdates(_0x1283e3){return function(_0x1c60e3){try{jsonpatch[_0xc66f('0x20')](_0x1c60e3,_0x1283e3,!![]);}catch(_0x2445ee){return BPromise[_0xc66f('0x21')](_0x2445ee);}return _0x1c60e3[_0xc66f('0x22')]();};}function saveUpdates(_0xf2671e,_0x5f1915){return function(_0x20a4f4){if(_0x20a4f4){return _0x20a4f4[_0xc66f('0x23')](_0xf2671e)[_0xc66f('0x24')](function(_0x5b5706){return _0x5b5706;});}return null;};}function removeEntity(_0x41c305,_0x513c43){return function(_0x583338){if(_0x583338){return _0x583338[_0xc66f('0x25')]()[_0xc66f('0x24')](function(){_0x41c305['status'](0xcc)[_0xc66f('0x1b')]();});}};}function handleEntityNotFound(_0x31f59b,_0x1ded16){return function(_0x1c1e77){if(!_0x1c1e77){_0x31f59b[_0xc66f('0x19')](0x194);}return _0x1c1e77;};}function handleError(_0x32d2a7,_0x4540e1){_0x4540e1=_0x4540e1||0x1f4;return function(_0x5b4625){logger[_0xc66f('0x26')](_0x5b4625['stack']);if(_0x5b4625[_0xc66f('0x27')]){delete _0x5b4625[_0xc66f('0x27')];}_0x32d2a7['status'](_0x4540e1)[_0xc66f('0x28')](_0x5b4625);};}exports[_0xc66f('0x29')]=function(_0x3315d5,_0x5dd812){var _0x10f745={},_0x494478={},_0x6a2a21={'count':0x0,'rows':[]};var _0x3f5cd4=_[_0xc66f('0x2a')](db[_0xc66f('0x2b')][_0xc66f('0x2c')],function(_0x5e12c7){return{'name':_0x5e12c7[_0xc66f('0x2d')],'type':_0x5e12c7[_0xc66f('0x2e')][_0xc66f('0x2f')]};});_0x494478[_0xc66f('0x30')]=_[_0xc66f('0x2a')](_0x3f5cd4,_0xc66f('0x27'));_0x494478[_0xc66f('0x31')]=_['keys'](_0x3315d5[_0xc66f('0x31')]);_0x494478[_0xc66f('0x32')]=_[_0xc66f('0x33')](_0x494478[_0xc66f('0x30')],_0x494478['query']);_0x10f745[_0xc66f('0x34')]=_[_0xc66f('0x33')](_0x494478[_0xc66f('0x30')],qs[_0xc66f('0x35')](_0x3315d5['query'][_0xc66f('0x35')]));_0x10f745[_0xc66f('0x34')]=_0x10f745[_0xc66f('0x34')][_0xc66f('0x36')]?_0x10f745[_0xc66f('0x34')]:_0x494478[_0xc66f('0x30')];if(!_0x3315d5[_0xc66f('0x31')][_0xc66f('0x37')](_0xc66f('0x38'))){_0x10f745[_0xc66f('0x1e')]=qs['limit'](_0x3315d5[_0xc66f('0x31')][_0xc66f('0x1e')]);_0x10f745[_0xc66f('0x1d')]=qs[_0xc66f('0x1d')](_0x3315d5['query'][_0xc66f('0x1d')]);}_0x10f745[_0xc66f('0x39')]=qs[_0xc66f('0x3a')](_0x3315d5[_0xc66f('0x31')][_0xc66f('0x3a')]);_0x10f745[_0xc66f('0x3b')]=qs['filters'](_['pick'](_0x3315d5[_0xc66f('0x31')],_0x494478[_0xc66f('0x32')]),_0x3f5cd4);if(_0x3315d5[_0xc66f('0x31')][_0xc66f('0x3c')]){_0x10f745[_0xc66f('0x3b')]=_[_0xc66f('0x3d')](_0x10f745[_0xc66f('0x3b')],{'$or':_['map'](_0x3f5cd4,function(_0x315895){if(_0x315895['type']!==_0xc66f('0x3e')){var _0x3f858a={};_0x3f858a[_0x315895[_0xc66f('0x27')]]={'$like':'%'+_0x3315d5['query']['filter']+'%'};return _0x3f858a;}})});}_0x10f745=_[_0xc66f('0x3d')]({},_0x10f745,_0x3315d5[_0xc66f('0x3f')]);var _0x41e3e9={'where':_0x10f745['where']};return db[_0xc66f('0x2b')][_0xc66f('0x40')](_0x41e3e9)[_0xc66f('0x24')](function(_0x5cdf99){_0x6a2a21['count']=_0x5cdf99;if(_0x3315d5[_0xc66f('0x31')][_0xc66f('0x41')]){_0x10f745[_0xc66f('0x42')]=[{'all':!![]}];}return db[_0xc66f('0x2b')][_0xc66f('0x43')](_0x10f745);})[_0xc66f('0x24')](function(_0x5dd7b2){_0x6a2a21[_0xc66f('0x44')]=_0x5dd7b2;return _0x6a2a21;})[_0xc66f('0x24')](respondWithFilteredResult(_0x5dd812,_0x10f745))[_0xc66f('0x45')](handleError(_0x5dd812,null));};exports['show']=function(_0x556f9c,_0x43035b){var _0x2ff007={'raw':!![],'where':{'id':_0x556f9c[_0xc66f('0x46')]['id']}},_0x87ec16={};_0x87ec16[_0xc66f('0x30')]=_[_0xc66f('0x47')](db[_0xc66f('0x2b')][_0xc66f('0x2c')]);_0x87ec16[_0xc66f('0x31')]=_['keys'](_0x556f9c[_0xc66f('0x31')]);_0x87ec16['filters']=_[_0xc66f('0x33')](_0x87ec16[_0xc66f('0x30')],_0x87ec16[_0xc66f('0x31')]);_0x2ff007[_0xc66f('0x34')]=_['intersection'](_0x87ec16['model'],qs[_0xc66f('0x35')](_0x556f9c[_0xc66f('0x31')][_0xc66f('0x35')]));_0x2ff007[_0xc66f('0x34')]=_0x2ff007['attributes'][_0xc66f('0x36')]?_0x2ff007[_0xc66f('0x34')]:_0x87ec16[_0xc66f('0x30')];if(_0x556f9c[_0xc66f('0x31')][_0xc66f('0x41')]){_0x2ff007[_0xc66f('0x42')]=[{'all':!![]}];}_0x2ff007=_['merge']({},_0x2ff007,_0x556f9c[_0xc66f('0x3f')]);return db['MailQueueReport'][_0xc66f('0x48')](_0x2ff007)['then'](handleEntityNotFound(_0x43035b,null))[_0xc66f('0x24')](respondWithResult(_0x43035b,null))['catch'](handleError(_0x43035b,null));};exports['create']=function(_0x2f20a1,_0x466b9a){return db[_0xc66f('0x2b')][_0xc66f('0x49')](_0x2f20a1[_0xc66f('0x4a')],{})[_0xc66f('0x24')](respondWithResult(_0x466b9a,0xc9))[_0xc66f('0x45')](handleError(_0x466b9a,null));};exports['update']=function(_0x45d3e0,_0x115250){if(_0x45d3e0[_0xc66f('0x4a')]['id']){delete _0x45d3e0[_0xc66f('0x4a')]['id'];}return db['MailQueueReport'][_0xc66f('0x48')]({'where':{'id':_0x45d3e0[_0xc66f('0x46')]['id']}})[_0xc66f('0x24')](handleEntityNotFound(_0x115250,null))[_0xc66f('0x24')](saveUpdates(_0x45d3e0[_0xc66f('0x4a')],null))[_0xc66f('0x24')](respondWithResult(_0x115250,null))['catch'](handleError(_0x115250,null));};exports[_0xc66f('0x25')]=function(_0x3234a3,_0x2b2ce6){return db[_0xc66f('0x2b')][_0xc66f('0x48')]({'where':{'id':_0x3234a3['params']['id']}})[_0xc66f('0x24')](handleEntityNotFound(_0x2b2ce6,null))[_0xc66f('0x24')](removeEntity(_0x2b2ce6,null))[_0xc66f('0x45')](handleError(_0x2b2ce6,null));};exports['describe']=function(_0x2933b9,_0x28bf59){return db[_0xc66f('0x2b')]['describe']()['then'](respondWithResult(_0x28bf59,null))[_0xc66f('0x45')](handleError(_0x28bf59,null));};