41312ef8e31d605c4eee54805254f49e152e8e3b
[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 _0x06f8=['filter','merge','VIRTUAL','options','includeAll','include','rows','show','find','catch','create','body','update','params','describe','eml-format','rimraf','zip-dir','request-promise','moment','mustache','util','path','sox','to-csv','fs-extra','lodash','squel','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','../../config/license/util','../../mysqldb','status','json','offset','undefined','count','set','Content-Range','apply','reject','save','then','destroy','end','error','stack','name','index','map','MailTransferReport','rawAttributes','fieldName','type','key','query','keys','intersection','attributes','model','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','filters','pick'];(function(_0x3fda3d,_0x34be98){var _0x21a46e=function(_0x348692){while(--_0x348692){_0x3fda3d['push'](_0x3fda3d['shift']());}};_0x21a46e(++_0x34be98);}(_0x06f8,0xb3));var _0x806f=function(_0x27d443,_0x4ee5ec){_0x27d443=_0x27d443-0x0;var _0x21b822=_0x06f8[_0x27d443];return _0x21b822;};'use strict';var emlformat=require(_0x806f('0x0'));var rimraf=require(_0x806f('0x1'));var zipdir=require(_0x806f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x806f('0x3'));var moment=require(_0x806f('0x4'));var BPromise=require('bluebird');var Mustache=require(_0x806f('0x5'));var util=require(_0x806f('0x6'));var path=require(_0x806f('0x7'));var sox=require(_0x806f('0x8'));var csv=require(_0x806f('0x9'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x806f('0xa'));var _=require(_0x806f('0xb'));var squel=require(_0x806f('0xc'));var crypto=require(_0x806f('0xd'));var jsforce=require(_0x806f('0xe'));var deskjs=require(_0x806f('0xf'));var toCsv=require(_0x806f('0x9'));var querystring=require(_0x806f('0x10'));var Papa=require(_0x806f('0x11'));var Redis=require(_0x806f('0x12'));var authService=require(_0x806f('0x13'));var qs=require(_0x806f('0x14'));var as=require(_0x806f('0x15'));var hardwareService=require(_0x806f('0x16'));var logger=require(_0x806f('0x17'))(_0x806f('0x18'));var utils=require(_0x806f('0x19'));var config=require(_0x806f('0x1a'));var licenseUtil=require(_0x806f('0x1b'));var db=require(_0x806f('0x1c'))['db'];function respondWithStatusCode(_0xe530ac,_0x44724c){_0x44724c=_0x44724c||0xcc;return function(_0x458900){if(_0x458900){return _0xe530ac['sendStatus'](_0x44724c);}return _0xe530ac[_0x806f('0x1d')](_0x44724c)['end']();};}function respondWithResult(_0x22e36b,_0x166987){_0x166987=_0x166987||0xc8;return function(_0x1724d3){if(_0x1724d3){return _0x22e36b[_0x806f('0x1d')](_0x166987)[_0x806f('0x1e')](_0x1724d3);}};}function respondWithFilteredResult(_0x4a3b5a,_0x18b7a9){return function(_0x351636){if(_0x351636){var _0x18e8cb=typeof _0x18b7a9[_0x806f('0x1f')]===_0x806f('0x20')&&typeof _0x18b7a9['limit']==='undefined';var _0x19f9c5=_0x351636[_0x806f('0x21')];var _0x2f54d2=_0x18e8cb?0x0:_0x18b7a9[_0x806f('0x1f')];var _0xf2d65=_0x18e8cb?_0x351636['count']:_0x18b7a9[_0x806f('0x1f')]+_0x18b7a9['limit'];var _0x24eb80;if(_0xf2d65>=_0x19f9c5){_0xf2d65=_0x19f9c5;_0x24eb80=0xc8;}else{_0x24eb80=0xce;}_0x4a3b5a['status'](_0x24eb80);return _0x4a3b5a[_0x806f('0x22')](_0x806f('0x23'),_0x2f54d2+'-'+_0xf2d65+'/'+_0x19f9c5)[_0x806f('0x1e')](_0x351636);}return null;};}function patchUpdates(_0x1cb47b){return function(_0x1ec928){try{jsonpatch[_0x806f('0x24')](_0x1ec928,_0x1cb47b,!![]);}catch(_0xff6c29){return BPromise[_0x806f('0x25')](_0xff6c29);}return _0x1ec928[_0x806f('0x26')]();};}function saveUpdates(_0x33fd74,_0xbf454a){return function(_0x323895){if(_0x323895){return _0x323895['update'](_0x33fd74)[_0x806f('0x27')](function(_0x502a62){return _0x502a62;});}return null;};}function removeEntity(_0x81023e,_0x3b08ad){return function(_0x5dfa59){if(_0x5dfa59){return _0x5dfa59[_0x806f('0x28')]()[_0x806f('0x27')](function(){_0x81023e['status'](0xcc)[_0x806f('0x29')]();});}};}function handleEntityNotFound(_0x2eed49,_0x26f7db){return function(_0x25a0ae){if(!_0x25a0ae){_0x2eed49['sendStatus'](0x194);}return _0x25a0ae;};}function handleError(_0x2fea79,_0x219674){_0x219674=_0x219674||0x1f4;return function(_0x15037e){logger[_0x806f('0x2a')](_0x15037e[_0x806f('0x2b')]);if(_0x15037e[_0x806f('0x2c')]){delete _0x15037e['name'];}_0x2fea79[_0x806f('0x1d')](_0x219674)['send'](_0x15037e);};}exports[_0x806f('0x2d')]=function(_0x502546,_0xa9294e){var _0x148a77={},_0x10b271={},_0x14056d={'count':0x0,'rows':[]};var _0x2a4f13=_[_0x806f('0x2e')](db[_0x806f('0x2f')][_0x806f('0x30')],function(_0x4a5fb2){return{'name':_0x4a5fb2[_0x806f('0x31')],'type':_0x4a5fb2[_0x806f('0x32')][_0x806f('0x33')]};});_0x10b271['model']=_[_0x806f('0x2e')](_0x2a4f13,'name');_0x10b271[_0x806f('0x34')]=_[_0x806f('0x35')](_0x502546[_0x806f('0x34')]);_0x10b271['filters']=_[_0x806f('0x36')](_0x10b271['model'],_0x10b271['query']);_0x148a77[_0x806f('0x37')]=_['intersection'](_0x10b271[_0x806f('0x38')],qs['fields'](_0x502546[_0x806f('0x34')][_0x806f('0x39')]));_0x148a77['attributes']=_0x148a77[_0x806f('0x37')][_0x806f('0x3a')]?_0x148a77[_0x806f('0x37')]:_0x10b271[_0x806f('0x38')];if(!_0x502546[_0x806f('0x34')][_0x806f('0x3b')](_0x806f('0x3c'))){_0x148a77[_0x806f('0x3d')]=qs['limit'](_0x502546[_0x806f('0x34')]['limit']);_0x148a77['offset']=qs[_0x806f('0x1f')](_0x502546[_0x806f('0x34')][_0x806f('0x1f')]);}_0x148a77[_0x806f('0x3e')]=qs[_0x806f('0x3f')](_0x502546['query'][_0x806f('0x3f')]);_0x148a77[_0x806f('0x40')]=qs[_0x806f('0x41')](_[_0x806f('0x42')](_0x502546[_0x806f('0x34')],_0x10b271[_0x806f('0x41')]),_0x2a4f13);if(_0x502546['query'][_0x806f('0x43')]){_0x148a77[_0x806f('0x40')]=_[_0x806f('0x44')](_0x148a77['where'],{'$or':_[_0x806f('0x2e')](_0x2a4f13,function(_0x3b47c3){if(_0x3b47c3[_0x806f('0x32')]!==_0x806f('0x45')){var _0xd56713={};_0xd56713[_0x3b47c3[_0x806f('0x2c')]]={'$like':'%'+_0x502546['query'][_0x806f('0x43')]+'%'};return _0xd56713;}})});}_0x148a77=_[_0x806f('0x44')]({},_0x148a77,_0x502546[_0x806f('0x46')]);var _0x10142d={'where':_0x148a77[_0x806f('0x40')]};return db[_0x806f('0x2f')][_0x806f('0x21')](_0x10142d)['then'](function(_0x25c34a){_0x14056d[_0x806f('0x21')]=_0x25c34a;if(_0x502546['query'][_0x806f('0x47')]){_0x148a77[_0x806f('0x48')]=[{'all':!![]}];}return db['MailTransferReport']['findAll'](_0x148a77);})[_0x806f('0x27')](function(_0x342aa1){_0x14056d[_0x806f('0x49')]=_0x342aa1;return _0x14056d;})[_0x806f('0x27')](respondWithFilteredResult(_0xa9294e,_0x148a77))['catch'](handleError(_0xa9294e,null));};exports[_0x806f('0x4a')]=function(_0x31558f,_0x1db3ed){var _0x5a2169={'raw':!![],'where':{'id':_0x31558f['params']['id']}},_0x3b53c1={};_0x3b53c1[_0x806f('0x38')]=_[_0x806f('0x35')](db[_0x806f('0x2f')][_0x806f('0x30')]);_0x3b53c1[_0x806f('0x34')]=_[_0x806f('0x35')](_0x31558f['query']);_0x3b53c1[_0x806f('0x41')]=_['intersection'](_0x3b53c1[_0x806f('0x38')],_0x3b53c1[_0x806f('0x34')]);_0x5a2169[_0x806f('0x37')]=_[_0x806f('0x36')](_0x3b53c1[_0x806f('0x38')],qs[_0x806f('0x39')](_0x31558f[_0x806f('0x34')]['fields']));_0x5a2169[_0x806f('0x37')]=_0x5a2169[_0x806f('0x37')][_0x806f('0x3a')]?_0x5a2169[_0x806f('0x37')]:_0x3b53c1[_0x806f('0x38')];if(_0x31558f[_0x806f('0x34')][_0x806f('0x47')]){_0x5a2169[_0x806f('0x48')]=[{'all':!![]}];}_0x5a2169=_[_0x806f('0x44')]({},_0x5a2169,_0x31558f[_0x806f('0x46')]);return db[_0x806f('0x2f')][_0x806f('0x4b')](_0x5a2169)[_0x806f('0x27')](handleEntityNotFound(_0x1db3ed,null))[_0x806f('0x27')](respondWithResult(_0x1db3ed,null))[_0x806f('0x4c')](handleError(_0x1db3ed,null));};exports[_0x806f('0x4d')]=function(_0x4f405b,_0x450b96){return db[_0x806f('0x2f')][_0x806f('0x4d')](_0x4f405b[_0x806f('0x4e')],{})[_0x806f('0x27')](respondWithResult(_0x450b96,0xc9))[_0x806f('0x4c')](handleError(_0x450b96,null));};exports[_0x806f('0x4f')]=function(_0x25bea2,_0x49d770){if(_0x25bea2[_0x806f('0x4e')]['id']){delete _0x25bea2[_0x806f('0x4e')]['id'];}return db[_0x806f('0x2f')][_0x806f('0x4b')]({'where':{'id':_0x25bea2[_0x806f('0x50')]['id']}})[_0x806f('0x27')](handleEntityNotFound(_0x49d770,null))[_0x806f('0x27')](saveUpdates(_0x25bea2[_0x806f('0x4e')],null))[_0x806f('0x27')](respondWithResult(_0x49d770,null))['catch'](handleError(_0x49d770,null));};exports[_0x806f('0x28')]=function(_0x48bd8e,_0x5275b9){return db[_0x806f('0x2f')]['find']({'where':{'id':_0x48bd8e[_0x806f('0x50')]['id']}})['then'](handleEntityNotFound(_0x5275b9,null))[_0x806f('0x27')](removeEntity(_0x5275b9,null))[_0x806f('0x4c')](handleError(_0x5275b9,null));};exports[_0x806f('0x51')]=function(_0x4d8a38,_0x47ea58){return db[_0x806f('0x2f')][_0x806f('0x51')]()[_0x806f('0x27')](respondWithResult(_0x47ea58,null))[_0x806f('0x4c')](handleError(_0x47ea58,null));};