8e596a3966366fd1a6b3d75d177a39e4fa21c818
[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 _0x7ff3=['util','sox','ejs','fs-extra','crypto','jsforce','desk.js','to-csv','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','json','offset','limit','undefined','count','set','Content-Range','apply','reject','save','destroy','then','end','error','stack','name','index','map','MailQueueReport','rawAttributes','fieldName','key','model','keys','filters','query','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','VIRTUAL','options','includeAll','findAll','rows','catch','params','intersection','include','find','create','body','update','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment'];(function(_0x361fc6,_0xf9ce96){var _0x22e450=function(_0x4c992d){while(--_0x4c992d){_0x361fc6['push'](_0x361fc6['shift']());}};_0x22e450(++_0xf9ce96);}(_0x7ff3,0x127));var _0x37ff=function(_0x13342f,_0x3d6303){_0x13342f=_0x13342f-0x0;var _0x2fc1fc=_0x7ff3[_0x13342f];return _0x2fc1fc;};'use strict';var emlformat=require(_0x37ff('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x37ff('0x1'));var jsonpatch=require(_0x37ff('0x2'));var rp=require(_0x37ff('0x3'));var moment=require(_0x37ff('0x4'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x37ff('0x5'));var path=require('path');var sox=require(_0x37ff('0x6'));var csv=require('to-csv');var ejs=require(_0x37ff('0x7'));var fs=require('fs');var fs_extra=require(_0x37ff('0x8'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x37ff('0x9'));var jsforce=require(_0x37ff('0xa'));var deskjs=require(_0x37ff('0xb'));var toCsv=require(_0x37ff('0xc'));var querystring=require(_0x37ff('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x37ff('0xe'));var qs=require(_0x37ff('0xf'));var as=require(_0x37ff('0x10'));var hardwareService=require(_0x37ff('0x11'));var logger=require('../../config/logger')(_0x37ff('0x12'));var utils=require('../../config/utils');var config=require(_0x37ff('0x13'));var licenseUtil=require(_0x37ff('0x14'));var db=require(_0x37ff('0x15'))['db'];function respondWithStatusCode(_0x974667,_0x41966e){_0x41966e=_0x41966e||0xcc;return function(_0x15b223){if(_0x15b223){return _0x974667[_0x37ff('0x16')](_0x41966e);}return _0x974667['status'](_0x41966e)['end']();};}function respondWithResult(_0x5ec5f2,_0x8c235a){_0x8c235a=_0x8c235a||0xc8;return function(_0x19ad23){if(_0x19ad23){return _0x5ec5f2[_0x37ff('0x17')](_0x8c235a)[_0x37ff('0x18')](_0x19ad23);}};}function respondWithFilteredResult(_0x7aca18,_0x1119ed){return function(_0x312146){if(_0x312146){var _0xca46c4=typeof _0x1119ed[_0x37ff('0x19')]==='undefined'&&typeof _0x1119ed[_0x37ff('0x1a')]===_0x37ff('0x1b');var _0x4c2801=_0x312146[_0x37ff('0x1c')];var _0x1a7483=_0xca46c4?0x0:_0x1119ed['offset'];var _0x5e627e=_0xca46c4?_0x312146['count']:_0x1119ed['offset']+_0x1119ed[_0x37ff('0x1a')];var _0x25bf5b;if(_0x5e627e>=_0x4c2801){_0x5e627e=_0x4c2801;_0x25bf5b=0xc8;}else{_0x25bf5b=0xce;}_0x7aca18[_0x37ff('0x17')](_0x25bf5b);return _0x7aca18[_0x37ff('0x1d')](_0x37ff('0x1e'),_0x1a7483+'-'+_0x5e627e+'/'+_0x4c2801)[_0x37ff('0x18')](_0x312146);}return null;};}function patchUpdates(_0x55076a){return function(_0x40805c){try{jsonpatch[_0x37ff('0x1f')](_0x40805c,_0x55076a,!![]);}catch(_0x59ce14){return BPromise[_0x37ff('0x20')](_0x59ce14);}return _0x40805c[_0x37ff('0x21')]();};}function saveUpdates(_0x55d682,_0x3a0987){return function(_0xa9c60d){if(_0xa9c60d){return _0xa9c60d['update'](_0x55d682)['then'](function(_0x589a42){return _0x589a42;});}return null;};}function removeEntity(_0x3dd6ce,_0x42fcb7){return function(_0x27eea0){if(_0x27eea0){return _0x27eea0[_0x37ff('0x22')]()[_0x37ff('0x23')](function(){_0x3dd6ce['status'](0xcc)[_0x37ff('0x24')]();});}};}function handleEntityNotFound(_0x575083,_0x184f4e){return function(_0x58e57d){if(!_0x58e57d){_0x575083[_0x37ff('0x16')](0x194);}return _0x58e57d;};}function handleError(_0x9b1f2a,_0x3cd9c5){_0x3cd9c5=_0x3cd9c5||0x1f4;return function(_0x53b9ab){logger[_0x37ff('0x25')](_0x53b9ab[_0x37ff('0x26')]);if(_0x53b9ab[_0x37ff('0x27')]){delete _0x53b9ab[_0x37ff('0x27')];}_0x9b1f2a['status'](_0x3cd9c5)['send'](_0x53b9ab);};}exports[_0x37ff('0x28')]=function(_0x30c948,_0x41de6e){var _0x1732f1={},_0x2b6f2d={},_0x48a013={'count':0x0,'rows':[]};var _0x3e3cc0=_[_0x37ff('0x29')](db[_0x37ff('0x2a')][_0x37ff('0x2b')],function(_0x56c274){return{'name':_0x56c274[_0x37ff('0x2c')],'type':_0x56c274['type'][_0x37ff('0x2d')]};});_0x2b6f2d[_0x37ff('0x2e')]=_[_0x37ff('0x29')](_0x3e3cc0,'name');_0x2b6f2d['query']=_[_0x37ff('0x2f')](_0x30c948['query']);_0x2b6f2d[_0x37ff('0x30')]=_['intersection'](_0x2b6f2d[_0x37ff('0x2e')],_0x2b6f2d[_0x37ff('0x31')]);_0x1732f1[_0x37ff('0x32')]=_['intersection'](_0x2b6f2d['model'],qs[_0x37ff('0x33')](_0x30c948[_0x37ff('0x31')][_0x37ff('0x33')]));_0x1732f1[_0x37ff('0x32')]=_0x1732f1[_0x37ff('0x32')][_0x37ff('0x34')]?_0x1732f1['attributes']:_0x2b6f2d[_0x37ff('0x2e')];if(!_0x30c948[_0x37ff('0x31')][_0x37ff('0x35')](_0x37ff('0x36'))){_0x1732f1[_0x37ff('0x1a')]=qs[_0x37ff('0x1a')](_0x30c948['query']['limit']);_0x1732f1[_0x37ff('0x19')]=qs[_0x37ff('0x19')](_0x30c948[_0x37ff('0x31')][_0x37ff('0x19')]);}_0x1732f1[_0x37ff('0x37')]=qs[_0x37ff('0x38')](_0x30c948[_0x37ff('0x31')][_0x37ff('0x38')]);_0x1732f1[_0x37ff('0x39')]=qs['filters'](_[_0x37ff('0x3a')](_0x30c948[_0x37ff('0x31')],_0x2b6f2d[_0x37ff('0x30')]),_0x3e3cc0);if(_0x30c948['query']['filter']){_0x1732f1['where']=_[_0x37ff('0x3b')](_0x1732f1[_0x37ff('0x39')],{'$or':_[_0x37ff('0x29')](_0x3e3cc0,function(_0x6dbafd){if(_0x6dbafd[_0x37ff('0x3c')]!==_0x37ff('0x3d')){var _0x370c8f={};_0x370c8f[_0x6dbafd[_0x37ff('0x27')]]={'$like':'%'+_0x30c948[_0x37ff('0x31')]['filter']+'%'};return _0x370c8f;}})});}_0x1732f1=_[_0x37ff('0x3b')]({},_0x1732f1,_0x30c948[_0x37ff('0x3e')]);var _0x44bf1e={'where':_0x1732f1[_0x37ff('0x39')]};return db[_0x37ff('0x2a')][_0x37ff('0x1c')](_0x44bf1e)[_0x37ff('0x23')](function(_0x1a1a0a){_0x48a013['count']=_0x1a1a0a;if(_0x30c948['query'][_0x37ff('0x3f')]){_0x1732f1['include']=[{'all':!![]}];}return db['MailQueueReport'][_0x37ff('0x40')](_0x1732f1);})[_0x37ff('0x23')](function(_0x1b95ef){_0x48a013[_0x37ff('0x41')]=_0x1b95ef;return _0x48a013;})[_0x37ff('0x23')](respondWithFilteredResult(_0x41de6e,_0x1732f1))[_0x37ff('0x42')](handleError(_0x41de6e,null));};exports['show']=function(_0x44b3d4,_0x180f32){var _0xdc9b4={'raw':!![],'where':{'id':_0x44b3d4[_0x37ff('0x43')]['id']}},_0x4eeefe={};_0x4eeefe['model']=_[_0x37ff('0x2f')](db[_0x37ff('0x2a')]['rawAttributes']);_0x4eeefe[_0x37ff('0x31')]=_['keys'](_0x44b3d4['query']);_0x4eeefe[_0x37ff('0x30')]=_[_0x37ff('0x44')](_0x4eeefe[_0x37ff('0x2e')],_0x4eeefe['query']);_0xdc9b4[_0x37ff('0x32')]=_['intersection'](_0x4eeefe[_0x37ff('0x2e')],qs[_0x37ff('0x33')](_0x44b3d4[_0x37ff('0x31')][_0x37ff('0x33')]));_0xdc9b4[_0x37ff('0x32')]=_0xdc9b4[_0x37ff('0x32')]['length']?_0xdc9b4[_0x37ff('0x32')]:_0x4eeefe['model'];if(_0x44b3d4[_0x37ff('0x31')][_0x37ff('0x3f')]){_0xdc9b4[_0x37ff('0x45')]=[{'all':!![]}];}_0xdc9b4=_[_0x37ff('0x3b')]({},_0xdc9b4,_0x44b3d4[_0x37ff('0x3e')]);return db[_0x37ff('0x2a')][_0x37ff('0x46')](_0xdc9b4)[_0x37ff('0x23')](handleEntityNotFound(_0x180f32,null))[_0x37ff('0x23')](respondWithResult(_0x180f32,null))['catch'](handleError(_0x180f32,null));};exports['create']=function(_0x3c18da,_0x34550e){return db[_0x37ff('0x2a')][_0x37ff('0x47')](_0x3c18da[_0x37ff('0x48')],{})[_0x37ff('0x23')](respondWithResult(_0x34550e,0xc9))[_0x37ff('0x42')](handleError(_0x34550e,null));};exports[_0x37ff('0x49')]=function(_0x1b7e02,_0x4741be){if(_0x1b7e02[_0x37ff('0x48')]['id']){delete _0x1b7e02['body']['id'];}return db['MailQueueReport'][_0x37ff('0x46')]({'where':{'id':_0x1b7e02[_0x37ff('0x43')]['id']}})[_0x37ff('0x23')](handleEntityNotFound(_0x4741be,null))[_0x37ff('0x23')](saveUpdates(_0x1b7e02[_0x37ff('0x48')],null))[_0x37ff('0x23')](respondWithResult(_0x4741be,null))[_0x37ff('0x42')](handleError(_0x4741be,null));};exports[_0x37ff('0x22')]=function(_0x47a585,_0x101ede){return db['MailQueueReport'][_0x37ff('0x46')]({'where':{'id':_0x47a585[_0x37ff('0x43')]['id']}})[_0x37ff('0x23')](handleEntityNotFound(_0x101ede,null))[_0x37ff('0x23')](removeEntity(_0x101ede,null))[_0x37ff('0x42')](handleError(_0x101ede,null));};exports['describe']=function(_0x4b7509,_0x43e738){return db[_0x37ff('0x2a')][_0x37ff('0x4a')]()[_0x37ff('0x23')](respondWithResult(_0x43e738,null))[_0x37ff('0x42')](handleError(_0x43e738,null));};