59f928ae6d877a94a5389e3938e297e77016fc3d
[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 _0x8f30=['destroy','sendStatus','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','filters','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','MailTransferReport','includeAll','include','rows','show','params','keys','options','find','create','body','catch','describe','eml-format','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','status','json','offset','limit','count','reject','update','then'];(function(_0x2e9f19,_0x5db93b){var _0xb80fdf=function(_0x144658){while(--_0x144658){_0x2e9f19['push'](_0x2e9f19['shift']());}};_0xb80fdf(++_0x5db93b);}(_0x8f30,0x109));var _0x08f3=function(_0x3adf27,_0x2942e7){_0x3adf27=_0x3adf27-0x0;var _0x5bd490=_0x8f30[_0x3adf27];return _0x5bd490;};'use strict';var emlformat=require(_0x08f3('0x0'));var rimraf=require(_0x08f3('0x1'));var zipdir=require(_0x08f3('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x08f3('0x3'));var moment=require(_0x08f3('0x4'));var BPromise=require(_0x08f3('0x5'));var Mustache=require(_0x08f3('0x6'));var util=require(_0x08f3('0x7'));var path=require(_0x08f3('0x8'));var sox=require(_0x08f3('0x9'));var csv=require(_0x08f3('0xa'));var ejs=require(_0x08f3('0xb'));var fs=require('fs');var fs_extra=require(_0x08f3('0xc'));var _=require(_0x08f3('0xd'));var squel=require(_0x08f3('0xe'));var crypto=require(_0x08f3('0xf'));var jsforce=require(_0x08f3('0x10'));var deskjs=require('desk.js');var toCsv=require(_0x08f3('0xa'));var querystring=require(_0x08f3('0x11'));var Papa=require(_0x08f3('0x12'));var Redis=require('ioredis');var authService=require(_0x08f3('0x13'));var qs=require(_0x08f3('0x14'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x08f3('0x15'));var logger=require(_0x08f3('0x16'))(_0x08f3('0x17'));var utils=require(_0x08f3('0x18'));var config=require(_0x08f3('0x19'));var licenseUtil=require('../../config/license/util');var db=require(_0x08f3('0x1a'))['db'];function respondWithStatusCode(_0x135ce7,_0x1a89e8){_0x1a89e8=_0x1a89e8||0xcc;return function(_0xfaaf28){if(_0xfaaf28){return _0x135ce7['sendStatus'](_0x1a89e8);}return _0x135ce7[_0x08f3('0x1b')](_0x1a89e8)['end']();};}function respondWithResult(_0x1c3aac,_0xd2ee1d){_0xd2ee1d=_0xd2ee1d||0xc8;return function(_0x242cf6){if(_0x242cf6){return _0x1c3aac[_0x08f3('0x1b')](_0xd2ee1d)[_0x08f3('0x1c')](_0x242cf6);}};}function respondWithFilteredResult(_0x2e5d4e,_0x5e0e0e){return function(_0x3f8dab){if(_0x3f8dab){var _0x2d8d4c=typeof _0x5e0e0e[_0x08f3('0x1d')]==='undefined'&&typeof _0x5e0e0e[_0x08f3('0x1e')]==='undefined';var _0x199031=_0x3f8dab[_0x08f3('0x1f')];var _0x3d35bb=_0x2d8d4c?0x0:_0x5e0e0e[_0x08f3('0x1d')];var _0x2459a2=_0x2d8d4c?_0x3f8dab[_0x08f3('0x1f')]:_0x5e0e0e[_0x08f3('0x1d')]+_0x5e0e0e['limit'];var _0x4c6812;if(_0x2459a2>=_0x199031){_0x2459a2=_0x199031;_0x4c6812=0xc8;}else{_0x4c6812=0xce;}_0x2e5d4e['status'](_0x4c6812);return _0x2e5d4e['set']('Content-Range',_0x3d35bb+'-'+_0x2459a2+'/'+_0x199031)[_0x08f3('0x1c')](_0x3f8dab);}return null;};}function patchUpdates(_0x12faa9){return function(_0x622917){try{jsonpatch['apply'](_0x622917,_0x12faa9,!![]);}catch(_0x4a1ad2){return BPromise[_0x08f3('0x20')](_0x4a1ad2);}return _0x622917['save']();};}function saveUpdates(_0xcd425e,_0xc5d26d){return function(_0x15448c){if(_0x15448c){return _0x15448c[_0x08f3('0x21')](_0xcd425e)[_0x08f3('0x22')](function(_0x57dbeb){return _0x57dbeb;});}return null;};}function removeEntity(_0x1a2f00,_0x4dc708){return function(_0x175c0f){if(_0x175c0f){return _0x175c0f[_0x08f3('0x23')]()[_0x08f3('0x22')](function(){_0x1a2f00[_0x08f3('0x1b')](0xcc)['end']();});}};}function handleEntityNotFound(_0x77dc70,_0x34b6be){return function(_0x34b1f0){if(!_0x34b1f0){_0x77dc70[_0x08f3('0x24')](0x194);}return _0x34b1f0;};}function handleError(_0x3e5bf3,_0x414043){_0x414043=_0x414043||0x1f4;return function(_0x4569fa){logger[_0x08f3('0x25')](_0x4569fa[_0x08f3('0x26')]);if(_0x4569fa[_0x08f3('0x27')]){delete _0x4569fa[_0x08f3('0x27')];}_0x3e5bf3[_0x08f3('0x1b')](_0x414043)[_0x08f3('0x28')](_0x4569fa);};}exports[_0x08f3('0x29')]=function(_0x580f1c,_0x3705ec){var _0x25d4a0={},_0x219e0d={},_0x4494ff={'count':0x0,'rows':[]};var _0x4fbe01=_[_0x08f3('0x2a')](db['MailTransferReport'][_0x08f3('0x2b')],function(_0x3fc2dd){return{'name':_0x3fc2dd[_0x08f3('0x2c')],'type':_0x3fc2dd[_0x08f3('0x2d')][_0x08f3('0x2e')]};});_0x219e0d[_0x08f3('0x2f')]=_[_0x08f3('0x2a')](_0x4fbe01,'name');_0x219e0d[_0x08f3('0x30')]=_['keys'](_0x580f1c[_0x08f3('0x30')]);_0x219e0d[_0x08f3('0x31')]=_['intersection'](_0x219e0d['model'],_0x219e0d[_0x08f3('0x30')]);_0x25d4a0['attributes']=_['intersection'](_0x219e0d['model'],qs['fields'](_0x580f1c[_0x08f3('0x30')][_0x08f3('0x32')]));_0x25d4a0[_0x08f3('0x33')]=_0x25d4a0[_0x08f3('0x33')][_0x08f3('0x34')]?_0x25d4a0[_0x08f3('0x33')]:_0x219e0d[_0x08f3('0x2f')];if(!_0x580f1c[_0x08f3('0x30')][_0x08f3('0x35')](_0x08f3('0x36'))){_0x25d4a0[_0x08f3('0x1e')]=qs['limit'](_0x580f1c['query'][_0x08f3('0x1e')]);_0x25d4a0[_0x08f3('0x1d')]=qs[_0x08f3('0x1d')](_0x580f1c['query'][_0x08f3('0x1d')]);}_0x25d4a0[_0x08f3('0x37')]=qs['sort'](_0x580f1c[_0x08f3('0x30')][_0x08f3('0x38')]);_0x25d4a0[_0x08f3('0x39')]=qs[_0x08f3('0x31')](_[_0x08f3('0x3a')](_0x580f1c[_0x08f3('0x30')],_0x219e0d[_0x08f3('0x31')]),_0x4fbe01);if(_0x580f1c[_0x08f3('0x30')][_0x08f3('0x3b')]){_0x25d4a0[_0x08f3('0x39')]=_[_0x08f3('0x3c')](_0x25d4a0[_0x08f3('0x39')],{'$or':_['map'](_0x4fbe01,function(_0x39235f){if(_0x39235f[_0x08f3('0x2d')]!==_0x08f3('0x3d')){var _0x4985d0={};_0x4985d0[_0x39235f[_0x08f3('0x27')]]={'$like':'%'+_0x580f1c[_0x08f3('0x30')][_0x08f3('0x3b')]+'%'};return _0x4985d0;}})});}_0x25d4a0=_[_0x08f3('0x3c')]({},_0x25d4a0,_0x580f1c['options']);var _0x13a098={'where':_0x25d4a0[_0x08f3('0x39')]};return db[_0x08f3('0x3e')]['count'](_0x13a098)[_0x08f3('0x22')](function(_0x111717){_0x4494ff['count']=_0x111717;if(_0x580f1c[_0x08f3('0x30')][_0x08f3('0x3f')]){_0x25d4a0[_0x08f3('0x40')]=[{'all':!![]}];}return db[_0x08f3('0x3e')]['findAll'](_0x25d4a0);})[_0x08f3('0x22')](function(_0x5209e5){_0x4494ff[_0x08f3('0x41')]=_0x5209e5;return _0x4494ff;})['then'](respondWithFilteredResult(_0x3705ec,_0x25d4a0))['catch'](handleError(_0x3705ec,null));};exports[_0x08f3('0x42')]=function(_0xaf67d3,_0x30adc7){var _0x39ef62={'raw':!![],'where':{'id':_0xaf67d3[_0x08f3('0x43')]['id']}},_0x4dca33={};_0x4dca33[_0x08f3('0x2f')]=_[_0x08f3('0x44')](db[_0x08f3('0x3e')][_0x08f3('0x2b')]);_0x4dca33[_0x08f3('0x30')]=_[_0x08f3('0x44')](_0xaf67d3[_0x08f3('0x30')]);_0x4dca33['filters']=_['intersection'](_0x4dca33[_0x08f3('0x2f')],_0x4dca33[_0x08f3('0x30')]);_0x39ef62['attributes']=_['intersection'](_0x4dca33[_0x08f3('0x2f')],qs[_0x08f3('0x32')](_0xaf67d3[_0x08f3('0x30')][_0x08f3('0x32')]));_0x39ef62[_0x08f3('0x33')]=_0x39ef62[_0x08f3('0x33')]['length']?_0x39ef62['attributes']:_0x4dca33['model'];if(_0xaf67d3[_0x08f3('0x30')][_0x08f3('0x3f')]){_0x39ef62[_0x08f3('0x40')]=[{'all':!![]}];}_0x39ef62=_[_0x08f3('0x3c')]({},_0x39ef62,_0xaf67d3[_0x08f3('0x45')]);return db[_0x08f3('0x3e')][_0x08f3('0x46')](_0x39ef62)['then'](handleEntityNotFound(_0x30adc7,null))[_0x08f3('0x22')](respondWithResult(_0x30adc7,null))['catch'](handleError(_0x30adc7,null));};exports[_0x08f3('0x47')]=function(_0x3cb2f6,_0x1bf13f){return db[_0x08f3('0x3e')][_0x08f3('0x47')](_0x3cb2f6[_0x08f3('0x48')],{})[_0x08f3('0x22')](respondWithResult(_0x1bf13f,0xc9))[_0x08f3('0x49')](handleError(_0x1bf13f,null));};exports[_0x08f3('0x21')]=function(_0x3a930a,_0x4ec77f){if(_0x3a930a[_0x08f3('0x48')]['id']){delete _0x3a930a[_0x08f3('0x48')]['id'];}return db[_0x08f3('0x3e')][_0x08f3('0x46')]({'where':{'id':_0x3a930a[_0x08f3('0x43')]['id']}})[_0x08f3('0x22')](handleEntityNotFound(_0x4ec77f,null))[_0x08f3('0x22')](saveUpdates(_0x3a930a[_0x08f3('0x48')],null))['then'](respondWithResult(_0x4ec77f,null))[_0x08f3('0x49')](handleError(_0x4ec77f,null));};exports['destroy']=function(_0x190489,_0x18e8cb){return db[_0x08f3('0x3e')][_0x08f3('0x46')]({'where':{'id':_0x190489[_0x08f3('0x43')]['id']}})[_0x08f3('0x22')](handleEntityNotFound(_0x18e8cb,null))['then'](removeEntity(_0x18e8cb,null))[_0x08f3('0x49')](handleError(_0x18e8cb,null));};exports['describe']=function(_0x49badf,_0x300cf3){return db[_0x08f3('0x3e')][_0x08f3('0x4a')]()['then'](respondWithResult(_0x300cf3,null))['catch'](handleError(_0x300cf3,null));};