5582794d36a937eaa5149bb127268cfd61c1f362
[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 _0xf735=['rows','catch','show','params','keys','create','body','find','destroy','describe','rimraf','fast-json-patch','request-promise','bluebird','mustache','util','sox','to-csv','ejs','fs-extra','squel','crypto','desk.js','papaparse','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','limit','count','Content-Range','apply','reject','save','update','then','error','stack','name','send','index','map','fieldName','type','key','model','query','filters','intersection','attributes','fields','length','nolimit','sort','merge','where','VIRTUAL','filter','options','MailTransferReport','includeAll','include','findAll'];(function(_0x588edd,_0x293140){var _0x4bc3cc=function(_0x46ec84){while(--_0x46ec84){_0x588edd['push'](_0x588edd['shift']());}};_0x4bc3cc(++_0x293140);}(_0xf735,0x11e));var _0x5f73=function(_0x1444f9,_0x146f98){_0x1444f9=_0x1444f9-0x0;var _0x273b20=_0xf735[_0x1444f9];return _0x273b20;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5f73('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x5f73('0x1'));var rp=require(_0x5f73('0x2'));var moment=require('moment');var BPromise=require(_0x5f73('0x3'));var Mustache=require(_0x5f73('0x4'));var util=require(_0x5f73('0x5'));var path=require('path');var sox=require(_0x5f73('0x6'));var csv=require(_0x5f73('0x7'));var ejs=require(_0x5f73('0x8'));var fs=require('fs');var fs_extra=require(_0x5f73('0x9'));var _=require('lodash');var squel=require(_0x5f73('0xa'));var crypto=require(_0x5f73('0xb'));var jsforce=require('jsforce');var deskjs=require(_0x5f73('0xc'));var toCsv=require(_0x5f73('0x7'));var querystring=require('querystring');var Papa=require(_0x5f73('0xd'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require('../../components/parsers/qs');var as=require(_0x5f73('0xe'));var hardwareService=require(_0x5f73('0xf'));var logger=require(_0x5f73('0x10'))(_0x5f73('0x11'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x5f73('0x12'));var db=require(_0x5f73('0x13'))['db'];function respondWithStatusCode(_0x121d61,_0x2b54d3){_0x2b54d3=_0x2b54d3||0xcc;return function(_0x3062cd){if(_0x3062cd){return _0x121d61[_0x5f73('0x14')](_0x2b54d3);}return _0x121d61[_0x5f73('0x15')](_0x2b54d3)['end']();};}function respondWithResult(_0x513740,_0x14dc0e){_0x14dc0e=_0x14dc0e||0xc8;return function(_0x515bd7){if(_0x515bd7){return _0x513740[_0x5f73('0x15')](_0x14dc0e)['json'](_0x515bd7);}};}function respondWithFilteredResult(_0x49e730,_0x5c3422){return function(_0x289077){if(_0x289077){var _0x258d5d=typeof _0x5c3422[_0x5f73('0x16')]===_0x5f73('0x17')&&typeof _0x5c3422[_0x5f73('0x18')]===_0x5f73('0x17');var _0x4dcdf4=_0x289077[_0x5f73('0x19')];var _0xe94435=_0x258d5d?0x0:_0x5c3422[_0x5f73('0x16')];var _0x333c6b=_0x258d5d?_0x289077['count']:_0x5c3422[_0x5f73('0x16')]+_0x5c3422[_0x5f73('0x18')];var _0x4f172e;if(_0x333c6b>=_0x4dcdf4){_0x333c6b=_0x4dcdf4;_0x4f172e=0xc8;}else{_0x4f172e=0xce;}_0x49e730[_0x5f73('0x15')](_0x4f172e);return _0x49e730['set'](_0x5f73('0x1a'),_0xe94435+'-'+_0x333c6b+'/'+_0x4dcdf4)['json'](_0x289077);}return null;};}function patchUpdates(_0x292f41){return function(_0x15af7c){try{jsonpatch[_0x5f73('0x1b')](_0x15af7c,_0x292f41,!![]);}catch(_0x31200b){return BPromise[_0x5f73('0x1c')](_0x31200b);}return _0x15af7c[_0x5f73('0x1d')]();};}function saveUpdates(_0x57bfc4,_0x13fe28){return function(_0x55827c){if(_0x55827c){return _0x55827c[_0x5f73('0x1e')](_0x57bfc4)[_0x5f73('0x1f')](function(_0x23f70f){return _0x23f70f;});}return null;};}function removeEntity(_0x172113,_0x46ac0f){return function(_0x313316){if(_0x313316){return _0x313316['destroy']()[_0x5f73('0x1f')](function(){_0x172113[_0x5f73('0x15')](0xcc)['end']();});}};}function handleEntityNotFound(_0x296c9a,_0x12b740){return function(_0x3fa95e){if(!_0x3fa95e){_0x296c9a[_0x5f73('0x14')](0x194);}return _0x3fa95e;};}function handleError(_0x54b253,_0x39073a){_0x39073a=_0x39073a||0x1f4;return function(_0x4ba5b9){logger[_0x5f73('0x20')](_0x4ba5b9[_0x5f73('0x21')]);if(_0x4ba5b9[_0x5f73('0x22')]){delete _0x4ba5b9[_0x5f73('0x22')];}_0x54b253[_0x5f73('0x15')](_0x39073a)[_0x5f73('0x23')](_0x4ba5b9);};}exports[_0x5f73('0x24')]=function(_0x1763a4,_0x455e58){var _0x13067b={},_0x1ce806={},_0x4bc17f={'count':0x0,'rows':[]};var _0x1e7eea=_[_0x5f73('0x25')](db['MailTransferReport']['rawAttributes'],function(_0x323b3a){return{'name':_0x323b3a[_0x5f73('0x26')],'type':_0x323b3a[_0x5f73('0x27')][_0x5f73('0x28')]};});_0x1ce806[_0x5f73('0x29')]=_[_0x5f73('0x25')](_0x1e7eea,'name');_0x1ce806[_0x5f73('0x2a')]=_['keys'](_0x1763a4[_0x5f73('0x2a')]);_0x1ce806[_0x5f73('0x2b')]=_[_0x5f73('0x2c')](_0x1ce806[_0x5f73('0x29')],_0x1ce806[_0x5f73('0x2a')]);_0x13067b[_0x5f73('0x2d')]=_['intersection'](_0x1ce806['model'],qs['fields'](_0x1763a4[_0x5f73('0x2a')][_0x5f73('0x2e')]));_0x13067b[_0x5f73('0x2d')]=_0x13067b[_0x5f73('0x2d')][_0x5f73('0x2f')]?_0x13067b['attributes']:_0x1ce806[_0x5f73('0x29')];if(!_0x1763a4['query']['hasOwnProperty'](_0x5f73('0x30'))){_0x13067b[_0x5f73('0x18')]=qs[_0x5f73('0x18')](_0x1763a4['query'][_0x5f73('0x18')]);_0x13067b[_0x5f73('0x16')]=qs[_0x5f73('0x16')](_0x1763a4[_0x5f73('0x2a')]['offset']);}_0x13067b['order']=qs[_0x5f73('0x31')](_0x1763a4[_0x5f73('0x2a')][_0x5f73('0x31')]);_0x13067b['where']=qs['filters'](_['pick'](_0x1763a4[_0x5f73('0x2a')],_0x1ce806['filters']),_0x1e7eea);if(_0x1763a4[_0x5f73('0x2a')]['filter']){_0x13067b['where']=_[_0x5f73('0x32')](_0x13067b[_0x5f73('0x33')],{'$or':_['map'](_0x1e7eea,function(_0x2bc949){if(_0x2bc949[_0x5f73('0x27')]!==_0x5f73('0x34')){var _0x2df857={};_0x2df857[_0x2bc949[_0x5f73('0x22')]]={'$like':'%'+_0x1763a4[_0x5f73('0x2a')][_0x5f73('0x35')]+'%'};return _0x2df857;}})});}_0x13067b=_[_0x5f73('0x32')]({},_0x13067b,_0x1763a4[_0x5f73('0x36')]);var _0x250923={'where':_0x13067b[_0x5f73('0x33')]};return db[_0x5f73('0x37')][_0x5f73('0x19')](_0x250923)[_0x5f73('0x1f')](function(_0xfd5277){_0x4bc17f[_0x5f73('0x19')]=_0xfd5277;if(_0x1763a4['query'][_0x5f73('0x38')]){_0x13067b[_0x5f73('0x39')]=[{'all':!![]}];}return db[_0x5f73('0x37')][_0x5f73('0x3a')](_0x13067b);})[_0x5f73('0x1f')](function(_0x280e57){_0x4bc17f[_0x5f73('0x3b')]=_0x280e57;return _0x4bc17f;})[_0x5f73('0x1f')](respondWithFilteredResult(_0x455e58,_0x13067b))[_0x5f73('0x3c')](handleError(_0x455e58,null));};exports[_0x5f73('0x3d')]=function(_0x2ef800,_0x170cfc){var _0x219f8c={'raw':!![],'where':{'id':_0x2ef800[_0x5f73('0x3e')]['id']}},_0xba2af1={};_0xba2af1[_0x5f73('0x29')]=_[_0x5f73('0x3f')](db[_0x5f73('0x37')]['rawAttributes']);_0xba2af1['query']=_[_0x5f73('0x3f')](_0x2ef800['query']);_0xba2af1['filters']=_[_0x5f73('0x2c')](_0xba2af1[_0x5f73('0x29')],_0xba2af1[_0x5f73('0x2a')]);_0x219f8c['attributes']=_[_0x5f73('0x2c')](_0xba2af1['model'],qs[_0x5f73('0x2e')](_0x2ef800['query'][_0x5f73('0x2e')]));_0x219f8c[_0x5f73('0x2d')]=_0x219f8c[_0x5f73('0x2d')]['length']?_0x219f8c['attributes']:_0xba2af1[_0x5f73('0x29')];if(_0x2ef800[_0x5f73('0x2a')][_0x5f73('0x38')]){_0x219f8c[_0x5f73('0x39')]=[{'all':!![]}];}_0x219f8c=_['merge']({},_0x219f8c,_0x2ef800[_0x5f73('0x36')]);return db[_0x5f73('0x37')]['find'](_0x219f8c)[_0x5f73('0x1f')](handleEntityNotFound(_0x170cfc,null))[_0x5f73('0x1f')](respondWithResult(_0x170cfc,null))[_0x5f73('0x3c')](handleError(_0x170cfc,null));};exports[_0x5f73('0x40')]=function(_0x5051c3,_0x318ce8){return db['MailTransferReport'][_0x5f73('0x40')](_0x5051c3[_0x5f73('0x41')],{})['then'](respondWithResult(_0x318ce8,0xc9))[_0x5f73('0x3c')](handleError(_0x318ce8,null));};exports[_0x5f73('0x1e')]=function(_0x5d5a74,_0x1e39f2){if(_0x5d5a74[_0x5f73('0x41')]['id']){delete _0x5d5a74[_0x5f73('0x41')]['id'];}return db[_0x5f73('0x37')][_0x5f73('0x42')]({'where':{'id':_0x5d5a74['params']['id']}})[_0x5f73('0x1f')](handleEntityNotFound(_0x1e39f2,null))['then'](saveUpdates(_0x5d5a74['body'],null))[_0x5f73('0x1f')](respondWithResult(_0x1e39f2,null))[_0x5f73('0x3c')](handleError(_0x1e39f2,null));};exports[_0x5f73('0x43')]=function(_0xa8ebe1,_0x501a5d){return db[_0x5f73('0x37')][_0x5f73('0x42')]({'where':{'id':_0xa8ebe1[_0x5f73('0x3e')]['id']}})[_0x5f73('0x1f')](handleEntityNotFound(_0x501a5d,null))[_0x5f73('0x1f')](removeEntity(_0x501a5d,null))[_0x5f73('0x3c')](handleError(_0x501a5d,null));};exports[_0x5f73('0x44')]=function(_0x43c243,_0x1f9c76){return db[_0x5f73('0x37')][_0x5f73('0x44')]()[_0x5f73('0x1f')](respondWithResult(_0x1f9c76,null))[_0x5f73('0x3c')](handleError(_0x1f9c76,null));};