Built motion from commit 52c8a02d.|2.6.29
[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 _0x51df=['fs-extra','lodash','squel','crypto','jsforce','desk.js','ioredis','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','undefined','limit','count','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','MailTransferReport','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','options','includeAll','include','show','params','find','catch','create','body','destroy','describe','eml-format','zip-dir','fast-json-patch','request-promise','moment','mustache','util','path','sox','to-csv','ejs'];(function(_0x59ee6f,_0x450239){var _0x4c0979=function(_0x565e92){while(--_0x565e92){_0x59ee6f['push'](_0x59ee6f['shift']());}};_0x4c0979(++_0x450239);}(_0x51df,0x8b));var _0xf51d=function(_0x513b5a,_0x4fa49a){_0x513b5a=_0x513b5a-0x0;var _0x4f13c2=_0x51df[_0x513b5a];return _0x4f13c2;};'use strict';var emlformat=require(_0xf51d('0x0'));var rimraf=require('rimraf');var zipdir=require(_0xf51d('0x1'));var jsonpatch=require(_0xf51d('0x2'));var rp=require(_0xf51d('0x3'));var moment=require(_0xf51d('0x4'));var BPromise=require('bluebird');var Mustache=require(_0xf51d('0x5'));var util=require(_0xf51d('0x6'));var path=require(_0xf51d('0x7'));var sox=require(_0xf51d('0x8'));var csv=require(_0xf51d('0x9'));var ejs=require(_0xf51d('0xa'));var fs=require('fs');var fs_extra=require(_0xf51d('0xb'));var _=require(_0xf51d('0xc'));var squel=require(_0xf51d('0xd'));var crypto=require(_0xf51d('0xe'));var jsforce=require(_0xf51d('0xf'));var deskjs=require(_0xf51d('0x10'));var toCsv=require(_0xf51d('0x9'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf51d('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xf51d('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf51d('0x13'));var logger=require(_0xf51d('0x14'))(_0xf51d('0x15'));var utils=require('../../config/utils');var config=require(_0xf51d('0x16'));var licenseUtil=require(_0xf51d('0x17'));var db=require(_0xf51d('0x18'))['db'];function respondWithStatusCode(_0xb16918,_0x21196d){_0x21196d=_0x21196d||0xcc;return function(_0x31501e){if(_0x31501e){return _0xb16918[_0xf51d('0x19')](_0x21196d);}return _0xb16918[_0xf51d('0x1a')](_0x21196d)[_0xf51d('0x1b')]();};}function respondWithResult(_0x31de56,_0x24cd59){_0x24cd59=_0x24cd59||0xc8;return function(_0x170579){if(_0x170579){return _0x31de56[_0xf51d('0x1a')](_0x24cd59)[_0xf51d('0x1c')](_0x170579);}};}function respondWithFilteredResult(_0x1b1bc8,_0x58dc81){return function(_0x1626e4){if(_0x1626e4){var _0x10eff=typeof _0x58dc81[_0xf51d('0x1d')]===_0xf51d('0x1e')&&typeof _0x58dc81[_0xf51d('0x1f')]===_0xf51d('0x1e');var _0x13b58a=_0x1626e4['count'];var _0x32b7e8=_0x10eff?0x0:_0x58dc81['offset'];var _0xa98952=_0x10eff?_0x1626e4[_0xf51d('0x20')]:_0x58dc81[_0xf51d('0x1d')]+_0x58dc81[_0xf51d('0x1f')];var _0x180ac7;if(_0xa98952>=_0x13b58a){_0xa98952=_0x13b58a;_0x180ac7=0xc8;}else{_0x180ac7=0xce;}_0x1b1bc8[_0xf51d('0x1a')](_0x180ac7);return _0x1b1bc8['set'](_0xf51d('0x21'),_0x32b7e8+'-'+_0xa98952+'/'+_0x13b58a)[_0xf51d('0x1c')](_0x1626e4);}return null;};}function patchUpdates(_0x188260){return function(_0x43cfec){try{jsonpatch[_0xf51d('0x22')](_0x43cfec,_0x188260,!![]);}catch(_0x555457){return BPromise[_0xf51d('0x23')](_0x555457);}return _0x43cfec[_0xf51d('0x24')]();};}function saveUpdates(_0x4f8cfb,_0x47f1e9){return function(_0x3989b7){if(_0x3989b7){return _0x3989b7[_0xf51d('0x25')](_0x4f8cfb)[_0xf51d('0x26')](function(_0x118a02){return _0x118a02;});}return null;};}function removeEntity(_0x1ccf2b,_0x2046f5){return function(_0x57029b){if(_0x57029b){return _0x57029b['destroy']()[_0xf51d('0x26')](function(){_0x1ccf2b[_0xf51d('0x1a')](0xcc)[_0xf51d('0x1b')]();});}};}function handleEntityNotFound(_0x1aa044,_0x1cabfc){return function(_0x3c555d){if(!_0x3c555d){_0x1aa044[_0xf51d('0x19')](0x194);}return _0x3c555d;};}function handleError(_0x3b2338,_0x24ab84){_0x24ab84=_0x24ab84||0x1f4;return function(_0x16df02){logger[_0xf51d('0x27')](_0x16df02[_0xf51d('0x28')]);if(_0x16df02[_0xf51d('0x29')]){delete _0x16df02[_0xf51d('0x29')];}_0x3b2338[_0xf51d('0x1a')](_0x24ab84)[_0xf51d('0x2a')](_0x16df02);};}exports[_0xf51d('0x2b')]=function(_0x6fc40b,_0x8fe46a){var _0xeeb2d0={},_0x2835e5={},_0x54ad7d={'count':0x0,'rows':[]};var _0xd651c4=_[_0xf51d('0x2c')](db[_0xf51d('0x2d')][_0xf51d('0x2e')],function(_0x1a79dc){return{'name':_0x1a79dc['fieldName'],'type':_0x1a79dc['type'][_0xf51d('0x2f')]};});_0x2835e5[_0xf51d('0x30')]=_[_0xf51d('0x2c')](_0xd651c4,_0xf51d('0x29'));_0x2835e5[_0xf51d('0x31')]=_[_0xf51d('0x32')](_0x6fc40b[_0xf51d('0x31')]);_0x2835e5[_0xf51d('0x33')]=_[_0xf51d('0x34')](_0x2835e5[_0xf51d('0x30')],_0x2835e5[_0xf51d('0x31')]);_0xeeb2d0[_0xf51d('0x35')]=_[_0xf51d('0x34')](_0x2835e5['model'],qs[_0xf51d('0x36')](_0x6fc40b['query']['fields']));_0xeeb2d0['attributes']=_0xeeb2d0[_0xf51d('0x35')][_0xf51d('0x37')]?_0xeeb2d0['attributes']:_0x2835e5['model'];if(!_0x6fc40b[_0xf51d('0x31')][_0xf51d('0x38')](_0xf51d('0x39'))){_0xeeb2d0[_0xf51d('0x1f')]=qs[_0xf51d('0x1f')](_0x6fc40b['query'][_0xf51d('0x1f')]);_0xeeb2d0[_0xf51d('0x1d')]=qs[_0xf51d('0x1d')](_0x6fc40b[_0xf51d('0x31')][_0xf51d('0x1d')]);}_0xeeb2d0[_0xf51d('0x3a')]=qs[_0xf51d('0x3b')](_0x6fc40b[_0xf51d('0x31')][_0xf51d('0x3b')]);_0xeeb2d0['where']=qs['filters'](_[_0xf51d('0x3c')](_0x6fc40b[_0xf51d('0x31')],_0x2835e5[_0xf51d('0x33')]),_0xd651c4);if(_0x6fc40b[_0xf51d('0x31')][_0xf51d('0x3d')]){_0xeeb2d0[_0xf51d('0x3e')]=_[_0xf51d('0x3f')](_0xeeb2d0[_0xf51d('0x3e')],{'$or':_['map'](_0xd651c4,function(_0x3c3e4a){if(_0x3c3e4a['type']!=='VIRTUAL'){var _0x482be4={};_0x482be4[_0x3c3e4a[_0xf51d('0x29')]]={'$like':'%'+_0x6fc40b['query'][_0xf51d('0x3d')]+'%'};return _0x482be4;}})});}_0xeeb2d0=_[_0xf51d('0x3f')]({},_0xeeb2d0,_0x6fc40b[_0xf51d('0x40')]);var _0x3123d0={'where':_0xeeb2d0[_0xf51d('0x3e')]};return db[_0xf51d('0x2d')][_0xf51d('0x20')](_0x3123d0)[_0xf51d('0x26')](function(_0x15fea4){_0x54ad7d[_0xf51d('0x20')]=_0x15fea4;if(_0x6fc40b['query'][_0xf51d('0x41')]){_0xeeb2d0[_0xf51d('0x42')]=[{'all':!![]}];}return db[_0xf51d('0x2d')]['findAll'](_0xeeb2d0);})[_0xf51d('0x26')](function(_0x8525f9){_0x54ad7d['rows']=_0x8525f9;return _0x54ad7d;})[_0xf51d('0x26')](respondWithFilteredResult(_0x8fe46a,_0xeeb2d0))['catch'](handleError(_0x8fe46a,null));};exports[_0xf51d('0x43')]=function(_0x1ff8d5,_0x1c0dc7){var _0x784415={'raw':!![],'where':{'id':_0x1ff8d5[_0xf51d('0x44')]['id']}},_0x3e5d4d={};_0x3e5d4d['model']=_[_0xf51d('0x32')](db[_0xf51d('0x2d')][_0xf51d('0x2e')]);_0x3e5d4d[_0xf51d('0x31')]=_[_0xf51d('0x32')](_0x1ff8d5[_0xf51d('0x31')]);_0x3e5d4d[_0xf51d('0x33')]=_[_0xf51d('0x34')](_0x3e5d4d[_0xf51d('0x30')],_0x3e5d4d[_0xf51d('0x31')]);_0x784415[_0xf51d('0x35')]=_[_0xf51d('0x34')](_0x3e5d4d[_0xf51d('0x30')],qs[_0xf51d('0x36')](_0x1ff8d5[_0xf51d('0x31')][_0xf51d('0x36')]));_0x784415[_0xf51d('0x35')]=_0x784415[_0xf51d('0x35')][_0xf51d('0x37')]?_0x784415['attributes']:_0x3e5d4d['model'];if(_0x1ff8d5[_0xf51d('0x31')][_0xf51d('0x41')]){_0x784415[_0xf51d('0x42')]=[{'all':!![]}];}_0x784415=_['merge']({},_0x784415,_0x1ff8d5[_0xf51d('0x40')]);return db['MailTransferReport'][_0xf51d('0x45')](_0x784415)['then'](handleEntityNotFound(_0x1c0dc7,null))[_0xf51d('0x26')](respondWithResult(_0x1c0dc7,null))[_0xf51d('0x46')](handleError(_0x1c0dc7,null));};exports[_0xf51d('0x47')]=function(_0x300267,_0xfbfcf2){return db[_0xf51d('0x2d')][_0xf51d('0x47')](_0x300267['body'],{})['then'](respondWithResult(_0xfbfcf2,0xc9))[_0xf51d('0x46')](handleError(_0xfbfcf2,null));};exports[_0xf51d('0x25')]=function(_0x438c0e,_0x3de927){if(_0x438c0e[_0xf51d('0x48')]['id']){delete _0x438c0e[_0xf51d('0x48')]['id'];}return db['MailTransferReport'][_0xf51d('0x45')]({'where':{'id':_0x438c0e['params']['id']}})['then'](handleEntityNotFound(_0x3de927,null))['then'](saveUpdates(_0x438c0e[_0xf51d('0x48')],null))[_0xf51d('0x26')](respondWithResult(_0x3de927,null))[_0xf51d('0x46')](handleError(_0x3de927,null));};exports[_0xf51d('0x49')]=function(_0x3093fe,_0xb3bd00){return db[_0xf51d('0x2d')][_0xf51d('0x45')]({'where':{'id':_0x3093fe[_0xf51d('0x44')]['id']}})[_0xf51d('0x26')](handleEntityNotFound(_0xb3bd00,null))[_0xf51d('0x26')](removeEntity(_0xb3bd00,null))[_0xf51d('0x46')](handleError(_0xb3bd00,null));};exports[_0xf51d('0x4a')]=function(_0x45f272,_0x62aeec){return db[_0xf51d('0x2d')][_0xf51d('0x4a')]()['then'](respondWithResult(_0x62aeec,null))['catch'](handleError(_0x62aeec,null));};