Built motion from commit d6d69adf.|2.6.33
[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 _0x8bf4=['map','MailTransferReport','rawAttributes','type','key','model','query','attributes','intersection','fields','length','hasOwnProperty','nolimit','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','keys','find','catch','create','body','describe','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','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/license/util','../../mysqldb','status','json','offset','undefined','limit','count','reject','save','update','destroy','then','end','sendStatus','error','stack','name','send','index'];(function(_0x951e48,_0x422d87){var _0x334df0=function(_0x42c9df){while(--_0x42c9df){_0x951e48['push'](_0x951e48['shift']());}};_0x334df0(++_0x422d87);}(_0x8bf4,0x158));var _0x48bf=function(_0x2cbb74,_0x241c10){_0x2cbb74=_0x2cbb74-0x0;var _0xa6d18=_0x8bf4[_0x2cbb74];return _0xa6d18;};'use strict';var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0x48bf('0x0'));var jsonpatch=require(_0x48bf('0x1'));var rp=require(_0x48bf('0x2'));var moment=require(_0x48bf('0x3'));var BPromise=require(_0x48bf('0x4'));var Mustache=require('mustache');var util=require(_0x48bf('0x5'));var path=require(_0x48bf('0x6'));var sox=require(_0x48bf('0x7'));var csv=require(_0x48bf('0x8'));var ejs=require(_0x48bf('0x9'));var fs=require('fs');var fs_extra=require(_0x48bf('0xa'));var _=require(_0x48bf('0xb'));var squel=require(_0x48bf('0xc'));var crypto=require(_0x48bf('0xd'));var jsforce=require(_0x48bf('0xe'));var deskjs=require(_0x48bf('0xf'));var toCsv=require(_0x48bf('0x8'));var querystring=require(_0x48bf('0x10'));var Papa=require(_0x48bf('0x11'));var Redis=require(_0x48bf('0x12'));var authService=require(_0x48bf('0x13'));var qs=require(_0x48bf('0x14'));var as=require(_0x48bf('0x15'));var hardwareService=require(_0x48bf('0x16'));var logger=require(_0x48bf('0x17'))(_0x48bf('0x18'));var utils=require(_0x48bf('0x19'));var config=require('../../config/environment');var licenseUtil=require(_0x48bf('0x1a'));var db=require(_0x48bf('0x1b'))['db'];function respondWithStatusCode(_0x24df2d,_0x5a0aa8){_0x5a0aa8=_0x5a0aa8||0xcc;return function(_0x314df5){if(_0x314df5){return _0x24df2d['sendStatus'](_0x5a0aa8);}return _0x24df2d['status'](_0x5a0aa8)['end']();};}function respondWithResult(_0x33c342,_0x2efbaf){_0x2efbaf=_0x2efbaf||0xc8;return function(_0x1d8439){if(_0x1d8439){return _0x33c342[_0x48bf('0x1c')](_0x2efbaf)[_0x48bf('0x1d')](_0x1d8439);}};}function respondWithFilteredResult(_0x2af5b6,_0x14b4ff){return function(_0x6a93af){if(_0x6a93af){var _0x49540a=typeof _0x14b4ff[_0x48bf('0x1e')]===_0x48bf('0x1f')&&typeof _0x14b4ff[_0x48bf('0x20')]==='undefined';var _0x1b53f7=_0x6a93af[_0x48bf('0x21')];var _0x4cd244=_0x49540a?0x0:_0x14b4ff[_0x48bf('0x1e')];var _0x2edace=_0x49540a?_0x6a93af[_0x48bf('0x21')]:_0x14b4ff[_0x48bf('0x1e')]+_0x14b4ff[_0x48bf('0x20')];var _0xd394af;if(_0x2edace>=_0x1b53f7){_0x2edace=_0x1b53f7;_0xd394af=0xc8;}else{_0xd394af=0xce;}_0x2af5b6[_0x48bf('0x1c')](_0xd394af);return _0x2af5b6['set']('Content-Range',_0x4cd244+'-'+_0x2edace+'/'+_0x1b53f7)[_0x48bf('0x1d')](_0x6a93af);}return null;};}function patchUpdates(_0x16fd78){return function(_0x526c5c){try{jsonpatch['apply'](_0x526c5c,_0x16fd78,!![]);}catch(_0x2859a7){return BPromise[_0x48bf('0x22')](_0x2859a7);}return _0x526c5c[_0x48bf('0x23')]();};}function saveUpdates(_0x2d94e6,_0x1d49b2){return function(_0x24b099){if(_0x24b099){return _0x24b099[_0x48bf('0x24')](_0x2d94e6)['then'](function(_0x533893){return _0x533893;});}return null;};}function removeEntity(_0x144ba1,_0x1f5630){return function(_0x18183f){if(_0x18183f){return _0x18183f[_0x48bf('0x25')]()[_0x48bf('0x26')](function(){_0x144ba1[_0x48bf('0x1c')](0xcc)[_0x48bf('0x27')]();});}};}function handleEntityNotFound(_0x5ad6df,_0x73c0ff){return function(_0x1c8636){if(!_0x1c8636){_0x5ad6df[_0x48bf('0x28')](0x194);}return _0x1c8636;};}function handleError(_0x26375e,_0x372486){_0x372486=_0x372486||0x1f4;return function(_0x25238b){logger[_0x48bf('0x29')](_0x25238b[_0x48bf('0x2a')]);if(_0x25238b['name']){delete _0x25238b[_0x48bf('0x2b')];}_0x26375e[_0x48bf('0x1c')](_0x372486)[_0x48bf('0x2c')](_0x25238b);};}exports[_0x48bf('0x2d')]=function(_0x487313,_0x4ecdb8){var _0xbe18ed={},_0x15fa96={},_0x3a7d99={'count':0x0,'rows':[]};var _0x536942=_[_0x48bf('0x2e')](db[_0x48bf('0x2f')][_0x48bf('0x30')],function(_0x2db0a9){return{'name':_0x2db0a9['fieldName'],'type':_0x2db0a9[_0x48bf('0x31')][_0x48bf('0x32')]};});_0x15fa96[_0x48bf('0x33')]=_[_0x48bf('0x2e')](_0x536942,_0x48bf('0x2b'));_0x15fa96[_0x48bf('0x34')]=_['keys'](_0x487313[_0x48bf('0x34')]);_0x15fa96['filters']=_['intersection'](_0x15fa96['model'],_0x15fa96[_0x48bf('0x34')]);_0xbe18ed[_0x48bf('0x35')]=_[_0x48bf('0x36')](_0x15fa96[_0x48bf('0x33')],qs[_0x48bf('0x37')](_0x487313['query'][_0x48bf('0x37')]));_0xbe18ed['attributes']=_0xbe18ed[_0x48bf('0x35')][_0x48bf('0x38')]?_0xbe18ed[_0x48bf('0x35')]:_0x15fa96[_0x48bf('0x33')];if(!_0x487313[_0x48bf('0x34')][_0x48bf('0x39')](_0x48bf('0x3a'))){_0xbe18ed[_0x48bf('0x20')]=qs[_0x48bf('0x20')](_0x487313[_0x48bf('0x34')][_0x48bf('0x20')]);_0xbe18ed[_0x48bf('0x1e')]=qs[_0x48bf('0x1e')](_0x487313[_0x48bf('0x34')]['offset']);}_0xbe18ed['order']=qs['sort'](_0x487313['query']['sort']);_0xbe18ed[_0x48bf('0x3b')]=qs['filters'](_[_0x48bf('0x3c')](_0x487313[_0x48bf('0x34')],_0x15fa96[_0x48bf('0x3d')]),_0x536942);if(_0x487313['query'][_0x48bf('0x3e')]){_0xbe18ed[_0x48bf('0x3b')]=_[_0x48bf('0x3f')](_0xbe18ed[_0x48bf('0x3b')],{'$or':_['map'](_0x536942,function(_0x42541f){if(_0x42541f[_0x48bf('0x31')]!==_0x48bf('0x40')){var _0x5e67f7={};_0x5e67f7[_0x42541f[_0x48bf('0x2b')]]={'$like':'%'+_0x487313[_0x48bf('0x34')][_0x48bf('0x3e')]+'%'};return _0x5e67f7;}})});}_0xbe18ed=_[_0x48bf('0x3f')]({},_0xbe18ed,_0x487313[_0x48bf('0x41')]);var _0x1296c7={'where':_0xbe18ed[_0x48bf('0x3b')]};return db['MailTransferReport'][_0x48bf('0x21')](_0x1296c7)['then'](function(_0x422f7f){_0x3a7d99[_0x48bf('0x21')]=_0x422f7f;if(_0x487313[_0x48bf('0x34')][_0x48bf('0x42')]){_0xbe18ed[_0x48bf('0x43')]=[{'all':!![]}];}return db[_0x48bf('0x2f')][_0x48bf('0x44')](_0xbe18ed);})[_0x48bf('0x26')](function(_0xaa8d3d){_0x3a7d99[_0x48bf('0x45')]=_0xaa8d3d;return _0x3a7d99;})['then'](respondWithFilteredResult(_0x4ecdb8,_0xbe18ed))['catch'](handleError(_0x4ecdb8,null));};exports[_0x48bf('0x46')]=function(_0x3fcf14,_0x5ac602){var _0x2ec9ad={'raw':!![],'where':{'id':_0x3fcf14[_0x48bf('0x47')]['id']}},_0x1191b6={};_0x1191b6['model']=_[_0x48bf('0x48')](db['MailTransferReport'][_0x48bf('0x30')]);_0x1191b6[_0x48bf('0x34')]=_['keys'](_0x3fcf14[_0x48bf('0x34')]);_0x1191b6[_0x48bf('0x3d')]=_[_0x48bf('0x36')](_0x1191b6[_0x48bf('0x33')],_0x1191b6[_0x48bf('0x34')]);_0x2ec9ad[_0x48bf('0x35')]=_[_0x48bf('0x36')](_0x1191b6[_0x48bf('0x33')],qs[_0x48bf('0x37')](_0x3fcf14[_0x48bf('0x34')][_0x48bf('0x37')]));_0x2ec9ad['attributes']=_0x2ec9ad[_0x48bf('0x35')]['length']?_0x2ec9ad[_0x48bf('0x35')]:_0x1191b6[_0x48bf('0x33')];if(_0x3fcf14[_0x48bf('0x34')][_0x48bf('0x42')]){_0x2ec9ad[_0x48bf('0x43')]=[{'all':!![]}];}_0x2ec9ad=_[_0x48bf('0x3f')]({},_0x2ec9ad,_0x3fcf14[_0x48bf('0x41')]);return db[_0x48bf('0x2f')][_0x48bf('0x49')](_0x2ec9ad)[_0x48bf('0x26')](handleEntityNotFound(_0x5ac602,null))[_0x48bf('0x26')](respondWithResult(_0x5ac602,null))[_0x48bf('0x4a')](handleError(_0x5ac602,null));};exports[_0x48bf('0x4b')]=function(_0x2d49d9,_0x214b00){return db[_0x48bf('0x2f')]['create'](_0x2d49d9[_0x48bf('0x4c')],{})[_0x48bf('0x26')](respondWithResult(_0x214b00,0xc9))['catch'](handleError(_0x214b00,null));};exports[_0x48bf('0x24')]=function(_0x2a21e6,_0xddfdec){if(_0x2a21e6['body']['id']){delete _0x2a21e6[_0x48bf('0x4c')]['id'];}return db[_0x48bf('0x2f')][_0x48bf('0x49')]({'where':{'id':_0x2a21e6[_0x48bf('0x47')]['id']}})[_0x48bf('0x26')](handleEntityNotFound(_0xddfdec,null))[_0x48bf('0x26')](saveUpdates(_0x2a21e6[_0x48bf('0x4c')],null))['then'](respondWithResult(_0xddfdec,null))[_0x48bf('0x4a')](handleError(_0xddfdec,null));};exports[_0x48bf('0x25')]=function(_0x2cfa86,_0x1bcc52){return db[_0x48bf('0x2f')]['find']({'where':{'id':_0x2cfa86['params']['id']}})[_0x48bf('0x26')](handleEntityNotFound(_0x1bcc52,null))[_0x48bf('0x26')](removeEntity(_0x1bcc52,null))[_0x48bf('0x4a')](handleError(_0x1bcc52,null));};exports['describe']=function(_0x504441,_0x9990b9){return db[_0x48bf('0x2f')][_0x48bf('0x4d')]()[_0x48bf('0x26')](respondWithResult(_0x9990b9,null))[_0x48bf('0x4a')](handleError(_0x9990b9,null));};