0f655b4c4697ad2fe2d73f21bed6b3304e1f233d
[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 _0x14f7=['reject','save','update','destroy','then','error','stack','send','map','fieldName','type','model','name','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','sort','where','filter','merge','VIRTUAL','options','include','MailTransferReport','rows','catch','show','rawAttributes','includeAll','find','create','params','body','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','querystring','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','end','status','json','offset','limit','count','Content-Range'];(function(_0x383523,_0x262138){var _0x29c502=function(_0x3e64cd){while(--_0x3e64cd){_0x383523['push'](_0x383523['shift']());}};_0x29c502(++_0x262138);}(_0x14f7,0x71));var _0x714f=function(_0x30ae5e,_0x391fc4){_0x30ae5e=_0x30ae5e-0x0;var _0x1f2e93=_0x14f7[_0x30ae5e];return _0x1f2e93;};'use strict';var emlformat=require(_0x714f('0x0'));var rimraf=require(_0x714f('0x1'));var zipdir=require(_0x714f('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x714f('0x3'));var moment=require(_0x714f('0x4'));var BPromise=require(_0x714f('0x5'));var Mustache=require(_0x714f('0x6'));var util=require(_0x714f('0x7'));var path=require('path');var sox=require(_0x714f('0x8'));var csv=require(_0x714f('0x9'));var ejs=require(_0x714f('0xa'));var fs=require('fs');var fs_extra=require(_0x714f('0xb'));var _=require('lodash');var squel=require(_0x714f('0xc'));var crypto=require(_0x714f('0xd'));var jsforce=require('jsforce');var deskjs=require(_0x714f('0xe'));var toCsv=require(_0x714f('0x9'));var querystring=require(_0x714f('0xf'));var Papa=require(_0x714f('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x714f('0x11'));var as=require(_0x714f('0x12'));var hardwareService=require(_0x714f('0x13'));var logger=require(_0x714f('0x14'))(_0x714f('0x15'));var utils=require('../../config/utils');var config=require(_0x714f('0x16'));var licenseUtil=require(_0x714f('0x17'));var db=require(_0x714f('0x18'))['db'];function respondWithStatusCode(_0x246c16,_0x36dcb3){_0x36dcb3=_0x36dcb3||0xcc;return function(_0x4c4573){if(_0x4c4573){return _0x246c16[_0x714f('0x19')](_0x36dcb3);}return _0x246c16['status'](_0x36dcb3)[_0x714f('0x1a')]();};}function respondWithResult(_0x149eab,_0x38fd7f){_0x38fd7f=_0x38fd7f||0xc8;return function(_0x304fe4){if(_0x304fe4){return _0x149eab[_0x714f('0x1b')](_0x38fd7f)[_0x714f('0x1c')](_0x304fe4);}};}function respondWithFilteredResult(_0x4bdd13,_0x3ebbc6){return function(_0x4ee275){if(_0x4ee275){var _0x15253e=typeof _0x3ebbc6[_0x714f('0x1d')]==='undefined'&&typeof _0x3ebbc6[_0x714f('0x1e')]==='undefined';var _0x5e37aa=_0x4ee275[_0x714f('0x1f')];var _0x394259=_0x15253e?0x0:_0x3ebbc6[_0x714f('0x1d')];var _0x15f83b=_0x15253e?_0x4ee275['count']:_0x3ebbc6[_0x714f('0x1d')]+_0x3ebbc6[_0x714f('0x1e')];var _0x46ae85;if(_0x15f83b>=_0x5e37aa){_0x15f83b=_0x5e37aa;_0x46ae85=0xc8;}else{_0x46ae85=0xce;}_0x4bdd13['status'](_0x46ae85);return _0x4bdd13['set'](_0x714f('0x20'),_0x394259+'-'+_0x15f83b+'/'+_0x5e37aa)[_0x714f('0x1c')](_0x4ee275);}return null;};}function patchUpdates(_0xbe1a90){return function(_0x18ac93){try{jsonpatch['apply'](_0x18ac93,_0xbe1a90,!![]);}catch(_0x169229){return BPromise[_0x714f('0x21')](_0x169229);}return _0x18ac93[_0x714f('0x22')]();};}function saveUpdates(_0x2824de,_0x4f6fb4){return function(_0x572d02){if(_0x572d02){return _0x572d02[_0x714f('0x23')](_0x2824de)['then'](function(_0x517eae){return _0x517eae;});}return null;};}function removeEntity(_0x12280d,_0x282155){return function(_0x155e46){if(_0x155e46){return _0x155e46[_0x714f('0x24')]()[_0x714f('0x25')](function(){_0x12280d[_0x714f('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x357362,_0x1db5f1){return function(_0x50b4c0){if(!_0x50b4c0){_0x357362[_0x714f('0x19')](0x194);}return _0x50b4c0;};}function handleError(_0x4c0338,_0x20f68e){_0x20f68e=_0x20f68e||0x1f4;return function(_0xc4120a){logger[_0x714f('0x26')](_0xc4120a[_0x714f('0x27')]);if(_0xc4120a['name']){delete _0xc4120a['name'];}_0x4c0338[_0x714f('0x1b')](_0x20f68e)[_0x714f('0x28')](_0xc4120a);};}exports['index']=function(_0x47effb,_0x22a598){var _0x4bbcbd={},_0x3a05e3={},_0x2ff9ba={'count':0x0,'rows':[]};var _0x1e4034=_[_0x714f('0x29')](db['MailTransferReport']['rawAttributes'],function(_0x390e3f){return{'name':_0x390e3f[_0x714f('0x2a')],'type':_0x390e3f[_0x714f('0x2b')]['key']};});_0x3a05e3[_0x714f('0x2c')]=_[_0x714f('0x29')](_0x1e4034,_0x714f('0x2d'));_0x3a05e3[_0x714f('0x2e')]=_[_0x714f('0x2f')](_0x47effb[_0x714f('0x2e')]);_0x3a05e3[_0x714f('0x30')]=_[_0x714f('0x31')](_0x3a05e3[_0x714f('0x2c')],_0x3a05e3['query']);_0x4bbcbd['attributes']=_[_0x714f('0x31')](_0x3a05e3[_0x714f('0x2c')],qs[_0x714f('0x32')](_0x47effb[_0x714f('0x2e')]['fields']));_0x4bbcbd['attributes']=_0x4bbcbd[_0x714f('0x33')][_0x714f('0x34')]?_0x4bbcbd['attributes']:_0x3a05e3[_0x714f('0x2c')];if(!_0x47effb[_0x714f('0x2e')][_0x714f('0x35')](_0x714f('0x36'))){_0x4bbcbd[_0x714f('0x1e')]=qs[_0x714f('0x1e')](_0x47effb['query']['limit']);_0x4bbcbd[_0x714f('0x1d')]=qs[_0x714f('0x1d')](_0x47effb['query'][_0x714f('0x1d')]);}_0x4bbcbd['order']=qs['sort'](_0x47effb[_0x714f('0x2e')][_0x714f('0x37')]);_0x4bbcbd[_0x714f('0x38')]=qs[_0x714f('0x30')](_['pick'](_0x47effb[_0x714f('0x2e')],_0x3a05e3[_0x714f('0x30')]),_0x1e4034);if(_0x47effb[_0x714f('0x2e')][_0x714f('0x39')]){_0x4bbcbd[_0x714f('0x38')]=_[_0x714f('0x3a')](_0x4bbcbd[_0x714f('0x38')],{'$or':_[_0x714f('0x29')](_0x1e4034,function(_0x409d79){if(_0x409d79['type']!==_0x714f('0x3b')){var _0x2063ec={};_0x2063ec[_0x409d79[_0x714f('0x2d')]]={'$like':'%'+_0x47effb[_0x714f('0x2e')]['filter']+'%'};return _0x2063ec;}})});}_0x4bbcbd=_[_0x714f('0x3a')]({},_0x4bbcbd,_0x47effb[_0x714f('0x3c')]);var _0x21f0ed={'where':_0x4bbcbd[_0x714f('0x38')]};return db['MailTransferReport'][_0x714f('0x1f')](_0x21f0ed)[_0x714f('0x25')](function(_0x25fd67){_0x2ff9ba[_0x714f('0x1f')]=_0x25fd67;if(_0x47effb[_0x714f('0x2e')]['includeAll']){_0x4bbcbd[_0x714f('0x3d')]=[{'all':!![]}];}return db[_0x714f('0x3e')]['findAll'](_0x4bbcbd);})[_0x714f('0x25')](function(_0x2ee53a){_0x2ff9ba[_0x714f('0x3f')]=_0x2ee53a;return _0x2ff9ba;})[_0x714f('0x25')](respondWithFilteredResult(_0x22a598,_0x4bbcbd))[_0x714f('0x40')](handleError(_0x22a598,null));};exports[_0x714f('0x41')]=function(_0x2ff13a,_0x32c27e){var _0x45b4e0={'raw':!![],'where':{'id':_0x2ff13a['params']['id']}},_0x146614={};_0x146614[_0x714f('0x2c')]=_['keys'](db[_0x714f('0x3e')][_0x714f('0x42')]);_0x146614['query']=_[_0x714f('0x2f')](_0x2ff13a[_0x714f('0x2e')]);_0x146614[_0x714f('0x30')]=_['intersection'](_0x146614[_0x714f('0x2c')],_0x146614[_0x714f('0x2e')]);_0x45b4e0['attributes']=_[_0x714f('0x31')](_0x146614[_0x714f('0x2c')],qs[_0x714f('0x32')](_0x2ff13a[_0x714f('0x2e')][_0x714f('0x32')]));_0x45b4e0[_0x714f('0x33')]=_0x45b4e0[_0x714f('0x33')]['length']?_0x45b4e0[_0x714f('0x33')]:_0x146614['model'];if(_0x2ff13a[_0x714f('0x2e')][_0x714f('0x43')]){_0x45b4e0[_0x714f('0x3d')]=[{'all':!![]}];}_0x45b4e0=_[_0x714f('0x3a')]({},_0x45b4e0,_0x2ff13a[_0x714f('0x3c')]);return db[_0x714f('0x3e')][_0x714f('0x44')](_0x45b4e0)[_0x714f('0x25')](handleEntityNotFound(_0x32c27e,null))['then'](respondWithResult(_0x32c27e,null))[_0x714f('0x40')](handleError(_0x32c27e,null));};exports[_0x714f('0x45')]=function(_0x4c7b87,_0x5d9548){return db['MailTransferReport'][_0x714f('0x45')](_0x4c7b87['body'],{})[_0x714f('0x25')](respondWithResult(_0x5d9548,0xc9))[_0x714f('0x40')](handleError(_0x5d9548,null));};exports[_0x714f('0x23')]=function(_0x3190f3,_0x430628){if(_0x3190f3['body']['id']){delete _0x3190f3['body']['id'];}return db[_0x714f('0x3e')]['find']({'where':{'id':_0x3190f3[_0x714f('0x46')]['id']}})['then'](handleEntityNotFound(_0x430628,null))[_0x714f('0x25')](saveUpdates(_0x3190f3[_0x714f('0x47')],null))[_0x714f('0x25')](respondWithResult(_0x430628,null))[_0x714f('0x40')](handleError(_0x430628,null));};exports[_0x714f('0x24')]=function(_0x1ca3a4,_0x5dd3fb){return db[_0x714f('0x3e')][_0x714f('0x44')]({'where':{'id':_0x1ca3a4['params']['id']}})[_0x714f('0x25')](handleEntityNotFound(_0x5dd3fb,null))['then'](removeEntity(_0x5dd3fb,null))[_0x714f('0x40')](handleError(_0x5dd3fb,null));};exports[_0x714f('0x48')]=function(_0x209cfd,_0x182556){return db[_0x714f('0x3e')][_0x714f('0x48')]()['then'](respondWithResult(_0x182556,null))['catch'](handleError(_0x182556,null));};