e815879f9eadc68c40bd66036497ffbbf2bfecbe
[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 _0x891a=['../../mysqldb','sendStatus','status','json','undefined','count','offset','reject','update','destroy','then','stack','name','send','index','fieldName','type','key','model','map','keys','query','filters','intersection','attributes','fields','length','nolimit','limit','order','sort','where','pick','VIRTUAL','merge','options','MailTransferReport','include','findAll','rows','catch','show','params','rawAttributes','includeAll','find','body','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../config/logger','api','../../config/utils','../../config/environment'];(function(_0x31d4da,_0x3acfa6){var _0xafc711=function(_0x21600f){while(--_0x21600f){_0x31d4da['push'](_0x31d4da['shift']());}};_0xafc711(++_0x3acfa6);}(_0x891a,0x76));var _0xa891=function(_0x5cf0ef,_0x212849){_0x5cf0ef=_0x5cf0ef-0x0;var _0x2904e9=_0x891a[_0x5cf0ef];return _0x2904e9;};'use strict';var emlformat=require(_0xa891('0x0'));var rimraf=require(_0xa891('0x1'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xa891('0x2'));var moment=require(_0xa891('0x3'));var BPromise=require(_0xa891('0x4'));var Mustache=require(_0xa891('0x5'));var util=require(_0xa891('0x6'));var path=require('path');var sox=require(_0xa891('0x7'));var csv=require(_0xa891('0x8'));var ejs=require(_0xa891('0x9'));var fs=require('fs');var fs_extra=require(_0xa891('0xa'));var _=require(_0xa891('0xb'));var squel=require(_0xa891('0xc'));var crypto=require(_0xa891('0xd'));var jsforce=require(_0xa891('0xe'));var deskjs=require(_0xa891('0xf'));var toCsv=require(_0xa891('0x8'));var querystring=require(_0xa891('0x10'));var Papa=require(_0xa891('0x11'));var Redis=require('ioredis');var authService=require(_0xa891('0x12'));var qs=require(_0xa891('0x13'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require(_0xa891('0x14'))(_0xa891('0x15'));var utils=require(_0xa891('0x16'));var config=require(_0xa891('0x17'));var licenseUtil=require('../../config/license/util');var db=require(_0xa891('0x18'))['db'];function respondWithStatusCode(_0x375fa5,_0x532354){_0x532354=_0x532354||0xcc;return function(_0x3e8b17){if(_0x3e8b17){return _0x375fa5[_0xa891('0x19')](_0x532354);}return _0x375fa5['status'](_0x532354)['end']();};}function respondWithResult(_0x935d75,_0x3a7d2a){_0x3a7d2a=_0x3a7d2a||0xc8;return function(_0xd5cace){if(_0xd5cace){return _0x935d75[_0xa891('0x1a')](_0x3a7d2a)[_0xa891('0x1b')](_0xd5cace);}};}function respondWithFilteredResult(_0x499d75,_0x2c5c84){return function(_0x468265){if(_0x468265){var _0x4f3b74=typeof _0x2c5c84['offset']===_0xa891('0x1c')&&typeof _0x2c5c84['limit']===_0xa891('0x1c');var _0x2c373e=_0x468265[_0xa891('0x1d')];var _0x34561e=_0x4f3b74?0x0:_0x2c5c84[_0xa891('0x1e')];var _0x1f0e94=_0x4f3b74?_0x468265[_0xa891('0x1d')]:_0x2c5c84[_0xa891('0x1e')]+_0x2c5c84['limit'];var _0x23326d;if(_0x1f0e94>=_0x2c373e){_0x1f0e94=_0x2c373e;_0x23326d=0xc8;}else{_0x23326d=0xce;}_0x499d75[_0xa891('0x1a')](_0x23326d);return _0x499d75['set']('Content-Range',_0x34561e+'-'+_0x1f0e94+'/'+_0x2c373e)['json'](_0x468265);}return null;};}function patchUpdates(_0x802cfe){return function(_0x4b8ec3){try{jsonpatch['apply'](_0x4b8ec3,_0x802cfe,!![]);}catch(_0x4d3681){return BPromise[_0xa891('0x1f')](_0x4d3681);}return _0x4b8ec3['save']();};}function saveUpdates(_0xa4a7bb,_0x50c5c8){return function(_0x4094f4){if(_0x4094f4){return _0x4094f4[_0xa891('0x20')](_0xa4a7bb)['then'](function(_0x5d29d2){return _0x5d29d2;});}return null;};}function removeEntity(_0x616e68,_0xab4c53){return function(_0x101138){if(_0x101138){return _0x101138[_0xa891('0x21')]()[_0xa891('0x22')](function(){_0x616e68['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4dce15,_0x38ab95){return function(_0x42e4b9){if(!_0x42e4b9){_0x4dce15[_0xa891('0x19')](0x194);}return _0x42e4b9;};}function handleError(_0x3558b5,_0x5bb91d){_0x5bb91d=_0x5bb91d||0x1f4;return function(_0x584546){logger['error'](_0x584546[_0xa891('0x23')]);if(_0x584546[_0xa891('0x24')]){delete _0x584546[_0xa891('0x24')];}_0x3558b5[_0xa891('0x1a')](_0x5bb91d)[_0xa891('0x25')](_0x584546);};}exports[_0xa891('0x26')]=function(_0xcbb3b7,_0xf125a8){var _0xbf60fc={},_0x473fdc={},_0x5541fd={'count':0x0,'rows':[]};var _0x3cbd78=_['map'](db['MailTransferReport']['rawAttributes'],function(_0x55f9f1){return{'name':_0x55f9f1[_0xa891('0x27')],'type':_0x55f9f1[_0xa891('0x28')][_0xa891('0x29')]};});_0x473fdc[_0xa891('0x2a')]=_[_0xa891('0x2b')](_0x3cbd78,'name');_0x473fdc['query']=_[_0xa891('0x2c')](_0xcbb3b7[_0xa891('0x2d')]);_0x473fdc[_0xa891('0x2e')]=_[_0xa891('0x2f')](_0x473fdc[_0xa891('0x2a')],_0x473fdc['query']);_0xbf60fc[_0xa891('0x30')]=_['intersection'](_0x473fdc[_0xa891('0x2a')],qs[_0xa891('0x31')](_0xcbb3b7['query'][_0xa891('0x31')]));_0xbf60fc[_0xa891('0x30')]=_0xbf60fc['attributes'][_0xa891('0x32')]?_0xbf60fc[_0xa891('0x30')]:_0x473fdc['model'];if(!_0xcbb3b7[_0xa891('0x2d')]['hasOwnProperty'](_0xa891('0x33'))){_0xbf60fc[_0xa891('0x34')]=qs[_0xa891('0x34')](_0xcbb3b7[_0xa891('0x2d')]['limit']);_0xbf60fc['offset']=qs[_0xa891('0x1e')](_0xcbb3b7['query'][_0xa891('0x1e')]);}_0xbf60fc[_0xa891('0x35')]=qs['sort'](_0xcbb3b7[_0xa891('0x2d')][_0xa891('0x36')]);_0xbf60fc[_0xa891('0x37')]=qs[_0xa891('0x2e')](_[_0xa891('0x38')](_0xcbb3b7[_0xa891('0x2d')],_0x473fdc[_0xa891('0x2e')]),_0x3cbd78);if(_0xcbb3b7[_0xa891('0x2d')]['filter']){_0xbf60fc['where']=_['merge'](_0xbf60fc[_0xa891('0x37')],{'$or':_[_0xa891('0x2b')](_0x3cbd78,function(_0x3846ff){if(_0x3846ff[_0xa891('0x28')]!==_0xa891('0x39')){var _0x93826e={};_0x93826e[_0x3846ff['name']]={'$like':'%'+_0xcbb3b7[_0xa891('0x2d')]['filter']+'%'};return _0x93826e;}})});}_0xbf60fc=_[_0xa891('0x3a')]({},_0xbf60fc,_0xcbb3b7[_0xa891('0x3b')]);var _0x23f170={'where':_0xbf60fc[_0xa891('0x37')]};return db[_0xa891('0x3c')][_0xa891('0x1d')](_0x23f170)[_0xa891('0x22')](function(_0x12e04c){_0x5541fd[_0xa891('0x1d')]=_0x12e04c;if(_0xcbb3b7[_0xa891('0x2d')]['includeAll']){_0xbf60fc[_0xa891('0x3d')]=[{'all':!![]}];}return db[_0xa891('0x3c')][_0xa891('0x3e')](_0xbf60fc);})[_0xa891('0x22')](function(_0x3ea277){_0x5541fd[_0xa891('0x3f')]=_0x3ea277;return _0x5541fd;})[_0xa891('0x22')](respondWithFilteredResult(_0xf125a8,_0xbf60fc))[_0xa891('0x40')](handleError(_0xf125a8,null));};exports[_0xa891('0x41')]=function(_0x4e4712,_0x5114bd){var _0x1fc882={'raw':!![],'where':{'id':_0x4e4712[_0xa891('0x42')]['id']}},_0x48b3e9={};_0x48b3e9[_0xa891('0x2a')]=_[_0xa891('0x2c')](db[_0xa891('0x3c')][_0xa891('0x43')]);_0x48b3e9[_0xa891('0x2d')]=_[_0xa891('0x2c')](_0x4e4712['query']);_0x48b3e9[_0xa891('0x2e')]=_['intersection'](_0x48b3e9[_0xa891('0x2a')],_0x48b3e9[_0xa891('0x2d')]);_0x1fc882[_0xa891('0x30')]=_[_0xa891('0x2f')](_0x48b3e9[_0xa891('0x2a')],qs[_0xa891('0x31')](_0x4e4712['query']['fields']));_0x1fc882['attributes']=_0x1fc882[_0xa891('0x30')][_0xa891('0x32')]?_0x1fc882[_0xa891('0x30')]:_0x48b3e9['model'];if(_0x4e4712[_0xa891('0x2d')][_0xa891('0x44')]){_0x1fc882[_0xa891('0x3d')]=[{'all':!![]}];}_0x1fc882=_['merge']({},_0x1fc882,_0x4e4712[_0xa891('0x3b')]);return db[_0xa891('0x3c')][_0xa891('0x45')](_0x1fc882)[_0xa891('0x22')](handleEntityNotFound(_0x5114bd,null))[_0xa891('0x22')](respondWithResult(_0x5114bd,null))[_0xa891('0x40')](handleError(_0x5114bd,null));};exports['create']=function(_0x2cd842,_0x4ceaea){return db['MailTransferReport']['create'](_0x2cd842[_0xa891('0x46')],{})['then'](respondWithResult(_0x4ceaea,0xc9))[_0xa891('0x40')](handleError(_0x4ceaea,null));};exports[_0xa891('0x20')]=function(_0x4ba57b,_0x85f599){if(_0x4ba57b['body']['id']){delete _0x4ba57b[_0xa891('0x46')]['id'];}return db['MailTransferReport'][_0xa891('0x45')]({'where':{'id':_0x4ba57b[_0xa891('0x42')]['id']}})[_0xa891('0x22')](handleEntityNotFound(_0x85f599,null))[_0xa891('0x22')](saveUpdates(_0x4ba57b[_0xa891('0x46')],null))[_0xa891('0x22')](respondWithResult(_0x85f599,null))[_0xa891('0x40')](handleError(_0x85f599,null));};exports[_0xa891('0x21')]=function(_0x30e749,_0x3dcdde){return db['MailTransferReport']['find']({'where':{'id':_0x30e749['params']['id']}})[_0xa891('0x22')](handleEntityNotFound(_0x3dcdde,null))[_0xa891('0x22')](removeEntity(_0x3dcdde,null))['catch'](handleError(_0x3dcdde,null));};exports['describe']=function(_0xfb1307,_0x35ef89){return db[_0xa891('0x3c')]['describe']()[_0xa891('0x22')](respondWithResult(_0x35ef89,null))[_0xa891('0x40')](handleError(_0x35ef89,null));};