ff40a34421846fc9edb102446d1b4405bc959408
[motion2.git] / server / api / mailTransferReport / mailTransferReport.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 _0xb9f2=['undefined','limit','count','set','Content-Range','json','reject','save','destroy','then','error','stack','name','send','index','map','rawAttributes','fieldName','type','model','query','keys','filters','intersection','attributes','fields','nolimit','order','sort','where','merge','VIRTUAL','filter','options','MailTransferReport','includeAll','include','findAll','rows','params','length','find','catch','create','body','update','describe','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','fs-extra','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','end','status','offset'];(function(_0x1c82a4,_0x49811a){var _0x41fcea=function(_0x19074e){while(--_0x19074e){_0x1c82a4['push'](_0x1c82a4['shift']());}};_0x41fcea(++_0x49811a);}(_0xb9f2,0x1b0));var _0x2b9f=function(_0x3b5713,_0x302e72){_0x3b5713=_0x3b5713-0x0;var _0x3cc459=_0xb9f2[_0x3b5713];return _0x3cc459;};'use strict';var emlformat=require(_0x2b9f('0x0'));var rimraf=require(_0x2b9f('0x1'));var zipdir=require('zip-dir');var jsonpatch=require(_0x2b9f('0x2'));var rp=require(_0x2b9f('0x3'));var moment=require(_0x2b9f('0x4'));var BPromise=require(_0x2b9f('0x5'));var Mustache=require('mustache');var util=require(_0x2b9f('0x6'));var path=require(_0x2b9f('0x7'));var sox=require(_0x2b9f('0x8'));var csv=require(_0x2b9f('0x9'));var ejs=require(_0x2b9f('0xa'));var fs=require('fs');var fs_extra=require(_0x2b9f('0xb'));var _=require('lodash');var squel=require('squel');var crypto=require(_0x2b9f('0xc'));var jsforce=require(_0x2b9f('0xd'));var deskjs=require(_0x2b9f('0xe'));var toCsv=require(_0x2b9f('0x9'));var querystring=require(_0x2b9f('0xf'));var Papa=require(_0x2b9f('0x10'));var Redis=require(_0x2b9f('0x11'));var authService=require(_0x2b9f('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x2b9f('0x13'));var hardwareService=require(_0x2b9f('0x14'));var logger=require(_0x2b9f('0x15'))(_0x2b9f('0x16'));var utils=require(_0x2b9f('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x2b9f('0x18'));var db=require(_0x2b9f('0x19'))['db'];function respondWithStatusCode(_0x5d6433,_0x2d997f){_0x2d997f=_0x2d997f||0xcc;return function(_0x393bab){if(_0x393bab){return _0x5d6433[_0x2b9f('0x1a')](_0x2d997f);}return _0x5d6433['status'](_0x2d997f)[_0x2b9f('0x1b')]();};}function respondWithResult(_0x5e6bdd,_0x442191){_0x442191=_0x442191||0xc8;return function(_0x2ea992){if(_0x2ea992){return _0x5e6bdd[_0x2b9f('0x1c')](_0x442191)['json'](_0x2ea992);}};}function respondWithFilteredResult(_0x465c5e,_0x4e7674){return function(_0x377838){if(_0x377838){var _0x3b49f0=typeof _0x4e7674[_0x2b9f('0x1d')]===_0x2b9f('0x1e')&&typeof _0x4e7674[_0x2b9f('0x1f')]===_0x2b9f('0x1e');var _0x226d50=_0x377838['count'];var _0x10c902=_0x3b49f0?0x0:_0x4e7674[_0x2b9f('0x1d')];var _0x12a5f9=_0x3b49f0?_0x377838[_0x2b9f('0x20')]:_0x4e7674[_0x2b9f('0x1d')]+_0x4e7674[_0x2b9f('0x1f')];var _0x536c83;if(_0x12a5f9>=_0x226d50){_0x12a5f9=_0x226d50;_0x536c83=0xc8;}else{_0x536c83=0xce;}_0x465c5e[_0x2b9f('0x1c')](_0x536c83);return _0x465c5e[_0x2b9f('0x21')](_0x2b9f('0x22'),_0x10c902+'-'+_0x12a5f9+'/'+_0x226d50)[_0x2b9f('0x23')](_0x377838);}return null;};}function patchUpdates(_0x5c036e){return function(_0xd47995){try{jsonpatch['apply'](_0xd47995,_0x5c036e,!![]);}catch(_0xed6f3b){return BPromise[_0x2b9f('0x24')](_0xed6f3b);}return _0xd47995[_0x2b9f('0x25')]();};}function saveUpdates(_0x223f65,_0x3acf32){return function(_0x39c359){if(_0x39c359){return _0x39c359['update'](_0x223f65)['then'](function(_0x574d2b){return _0x574d2b;});}return null;};}function removeEntity(_0x2ed3f3,_0x5bfd32){return function(_0x1ec957){if(_0x1ec957){return _0x1ec957[_0x2b9f('0x26')]()[_0x2b9f('0x27')](function(){_0x2ed3f3[_0x2b9f('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x148c74,_0x584310){return function(_0x31d11b){if(!_0x31d11b){_0x148c74['sendStatus'](0x194);}return _0x31d11b;};}function handleError(_0x51984e,_0x10ee8f){_0x10ee8f=_0x10ee8f||0x1f4;return function(_0x328d59){logger[_0x2b9f('0x28')](_0x328d59[_0x2b9f('0x29')]);if(_0x328d59[_0x2b9f('0x2a')]){delete _0x328d59['name'];}_0x51984e['status'](_0x10ee8f)[_0x2b9f('0x2b')](_0x328d59);};}exports[_0x2b9f('0x2c')]=function(_0x1a8b93,_0x450f87){var _0x11419c={},_0x5d37a4={},_0x104ec3={'count':0x0,'rows':[]};var _0x3b5e19=_[_0x2b9f('0x2d')](db['MailTransferReport'][_0x2b9f('0x2e')],function(_0x23f93d){return{'name':_0x23f93d[_0x2b9f('0x2f')],'type':_0x23f93d[_0x2b9f('0x30')]['key']};});_0x5d37a4[_0x2b9f('0x31')]=_[_0x2b9f('0x2d')](_0x3b5e19,_0x2b9f('0x2a'));_0x5d37a4[_0x2b9f('0x32')]=_[_0x2b9f('0x33')](_0x1a8b93[_0x2b9f('0x32')]);_0x5d37a4[_0x2b9f('0x34')]=_[_0x2b9f('0x35')](_0x5d37a4[_0x2b9f('0x31')],_0x5d37a4['query']);_0x11419c[_0x2b9f('0x36')]=_['intersection'](_0x5d37a4[_0x2b9f('0x31')],qs['fields'](_0x1a8b93[_0x2b9f('0x32')][_0x2b9f('0x37')]));_0x11419c[_0x2b9f('0x36')]=_0x11419c[_0x2b9f('0x36')]['length']?_0x11419c['attributes']:_0x5d37a4['model'];if(!_0x1a8b93[_0x2b9f('0x32')]['hasOwnProperty'](_0x2b9f('0x38'))){_0x11419c[_0x2b9f('0x1f')]=qs['limit'](_0x1a8b93[_0x2b9f('0x32')][_0x2b9f('0x1f')]);_0x11419c[_0x2b9f('0x1d')]=qs[_0x2b9f('0x1d')](_0x1a8b93[_0x2b9f('0x32')]['offset']);}_0x11419c[_0x2b9f('0x39')]=qs[_0x2b9f('0x3a')](_0x1a8b93['query'][_0x2b9f('0x3a')]);_0x11419c[_0x2b9f('0x3b')]=qs['filters'](_['pick'](_0x1a8b93[_0x2b9f('0x32')],_0x5d37a4['filters']),_0x3b5e19);if(_0x1a8b93[_0x2b9f('0x32')]['filter']){_0x11419c[_0x2b9f('0x3b')]=_[_0x2b9f('0x3c')](_0x11419c[_0x2b9f('0x3b')],{'$or':_['map'](_0x3b5e19,function(_0xc17162){if(_0xc17162['type']!==_0x2b9f('0x3d')){var _0x460fe3={};_0x460fe3[_0xc17162[_0x2b9f('0x2a')]]={'$like':'%'+_0x1a8b93[_0x2b9f('0x32')][_0x2b9f('0x3e')]+'%'};return _0x460fe3;}})});}_0x11419c=_[_0x2b9f('0x3c')]({},_0x11419c,_0x1a8b93[_0x2b9f('0x3f')]);var _0x2bc145={'where':_0x11419c[_0x2b9f('0x3b')]};return db[_0x2b9f('0x40')][_0x2b9f('0x20')](_0x2bc145)[_0x2b9f('0x27')](function(_0x55c115){_0x104ec3[_0x2b9f('0x20')]=_0x55c115;if(_0x1a8b93['query'][_0x2b9f('0x41')]){_0x11419c[_0x2b9f('0x42')]=[{'all':!![]}];}return db[_0x2b9f('0x40')][_0x2b9f('0x43')](_0x11419c);})[_0x2b9f('0x27')](function(_0x1b16ff){_0x104ec3[_0x2b9f('0x44')]=_0x1b16ff;return _0x104ec3;})[_0x2b9f('0x27')](respondWithFilteredResult(_0x450f87,_0x11419c))['catch'](handleError(_0x450f87,null));};exports['show']=function(_0x3c8c67,_0x3341ca){var _0x1c6345={'raw':!![],'where':{'id':_0x3c8c67[_0x2b9f('0x45')]['id']}},_0x54ec26={};_0x54ec26[_0x2b9f('0x31')]=_[_0x2b9f('0x33')](db[_0x2b9f('0x40')][_0x2b9f('0x2e')]);_0x54ec26[_0x2b9f('0x32')]=_[_0x2b9f('0x33')](_0x3c8c67[_0x2b9f('0x32')]);_0x54ec26['filters']=_[_0x2b9f('0x35')](_0x54ec26[_0x2b9f('0x31')],_0x54ec26[_0x2b9f('0x32')]);_0x1c6345[_0x2b9f('0x36')]=_[_0x2b9f('0x35')](_0x54ec26[_0x2b9f('0x31')],qs[_0x2b9f('0x37')](_0x3c8c67[_0x2b9f('0x32')][_0x2b9f('0x37')]));_0x1c6345[_0x2b9f('0x36')]=_0x1c6345[_0x2b9f('0x36')][_0x2b9f('0x46')]?_0x1c6345['attributes']:_0x54ec26['model'];if(_0x3c8c67[_0x2b9f('0x32')][_0x2b9f('0x41')]){_0x1c6345['include']=[{'all':!![]}];}_0x1c6345=_['merge']({},_0x1c6345,_0x3c8c67[_0x2b9f('0x3f')]);return db['MailTransferReport'][_0x2b9f('0x47')](_0x1c6345)[_0x2b9f('0x27')](handleEntityNotFound(_0x3341ca,null))[_0x2b9f('0x27')](respondWithResult(_0x3341ca,null))[_0x2b9f('0x48')](handleError(_0x3341ca,null));};exports[_0x2b9f('0x49')]=function(_0x81379f,_0x1abb57){return db[_0x2b9f('0x40')][_0x2b9f('0x49')](_0x81379f[_0x2b9f('0x4a')],{})[_0x2b9f('0x27')](respondWithResult(_0x1abb57,0xc9))['catch'](handleError(_0x1abb57,null));};exports[_0x2b9f('0x4b')]=function(_0x121017,_0x15f841){if(_0x121017[_0x2b9f('0x4a')]['id']){delete _0x121017['body']['id'];}return db[_0x2b9f('0x40')]['find']({'where':{'id':_0x121017[_0x2b9f('0x45')]['id']}})[_0x2b9f('0x27')](handleEntityNotFound(_0x15f841,null))[_0x2b9f('0x27')](saveUpdates(_0x121017[_0x2b9f('0x4a')],null))[_0x2b9f('0x27')](respondWithResult(_0x15f841,null))[_0x2b9f('0x48')](handleError(_0x15f841,null));};exports[_0x2b9f('0x26')]=function(_0x28b510,_0x347fc4){return db[_0x2b9f('0x40')]['find']({'where':{'id':_0x28b510['params']['id']}})[_0x2b9f('0x27')](handleEntityNotFound(_0x347fc4,null))['then'](removeEntity(_0x347fc4,null))[_0x2b9f('0x48')](handleError(_0x347fc4,null));};exports[_0x2b9f('0x4c')]=function(_0x2d8520,_0x513424){return db[_0x2b9f('0x40')][_0x2b9f('0x4c')]()[_0x2b9f('0x27')](respondWithResult(_0x513424,null))[_0x2b9f('0x48')](handleError(_0x513424,null));};