8c5a9e26135ae04d59c104382d4b40aa1540e602
[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 _0x59f8=['nolimit','order','sort','where','pick','merge','VIRTUAL','filter','includeAll','include','findAll','rows','catch','params','rawAttributes','create','body','update','find','describe','rimraf','fast-json-patch','request-promise','moment','bluebird','sox','ejs','fs-extra','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','status','json','limit','undefined','count','offset','Content-Range','apply','save','then','destroy','end','error','stack','index','map','MailTransferReport','fieldName','type','model','name','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty'];(function(_0x2e3545,_0x20a6ec){var _0xcf18f=function(_0x3c85dd){while(--_0x3c85dd){_0x2e3545['push'](_0x2e3545['shift']());}};_0xcf18f(++_0x20a6ec);}(_0x59f8,0x1be));var _0x859f=function(_0x867c5e,_0x21f568){_0x867c5e=_0x867c5e-0x0;var _0x38c628=_0x59f8[_0x867c5e];return _0x38c628;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x859f('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x859f('0x1'));var rp=require(_0x859f('0x2'));var moment=require(_0x859f('0x3'));var BPromise=require(_0x859f('0x4'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0x859f('0x5'));var csv=require('to-csv');var ejs=require(_0x859f('0x6'));var fs=require('fs');var fs_extra=require(_0x859f('0x7'));var _=require('lodash');var squel=require(_0x859f('0x8'));var crypto=require(_0x859f('0x9'));var jsforce=require(_0x859f('0xa'));var deskjs=require(_0x859f('0xb'));var toCsv=require(_0x859f('0xc'));var querystring=require(_0x859f('0xd'));var Papa=require(_0x859f('0xe'));var Redis=require(_0x859f('0xf'));var authService=require('../../components/auth/service');var qs=require(_0x859f('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require('../../config/license/hardware');var logger=require('../../config/logger')(_0x859f('0x11'));var utils=require(_0x859f('0x12'));var config=require(_0x859f('0x13'));var licenseUtil=require(_0x859f('0x14'));var db=require(_0x859f('0x15'))['db'];function respondWithStatusCode(_0x43a4ca,_0x3423fb){_0x3423fb=_0x3423fb||0xcc;return function(_0x4f1c44){if(_0x4f1c44){return _0x43a4ca['sendStatus'](_0x3423fb);}return _0x43a4ca['status'](_0x3423fb)['end']();};}function respondWithResult(_0x279991,_0x2958b1){_0x2958b1=_0x2958b1||0xc8;return function(_0xb5388e){if(_0xb5388e){return _0x279991[_0x859f('0x16')](_0x2958b1)[_0x859f('0x17')](_0xb5388e);}};}function respondWithFilteredResult(_0x9f66b2,_0x56e88e){return function(_0x5a1948){if(_0x5a1948){var _0x14d4a5=typeof _0x56e88e['offset']==='undefined'&&typeof _0x56e88e[_0x859f('0x18')]===_0x859f('0x19');var _0x16f5ef=_0x5a1948[_0x859f('0x1a')];var _0x18eb50=_0x14d4a5?0x0:_0x56e88e[_0x859f('0x1b')];var _0x1a278d=_0x14d4a5?_0x5a1948['count']:_0x56e88e[_0x859f('0x1b')]+_0x56e88e[_0x859f('0x18')];var _0x14f8b4;if(_0x1a278d>=_0x16f5ef){_0x1a278d=_0x16f5ef;_0x14f8b4=0xc8;}else{_0x14f8b4=0xce;}_0x9f66b2[_0x859f('0x16')](_0x14f8b4);return _0x9f66b2['set'](_0x859f('0x1c'),_0x18eb50+'-'+_0x1a278d+'/'+_0x16f5ef)[_0x859f('0x17')](_0x5a1948);}return null;};}function patchUpdates(_0x17eda7){return function(_0x10c41c){try{jsonpatch[_0x859f('0x1d')](_0x10c41c,_0x17eda7,!![]);}catch(_0x5a5f34){return BPromise['reject'](_0x5a5f34);}return _0x10c41c[_0x859f('0x1e')]();};}function saveUpdates(_0x3bbe58,_0x2a87e0){return function(_0x45c4fe){if(_0x45c4fe){return _0x45c4fe['update'](_0x3bbe58)[_0x859f('0x1f')](function(_0x210218){return _0x210218;});}return null;};}function removeEntity(_0x388bcc,_0x5b6566){return function(_0x417dca){if(_0x417dca){return _0x417dca[_0x859f('0x20')]()[_0x859f('0x1f')](function(){_0x388bcc['status'](0xcc)[_0x859f('0x21')]();});}};}function handleEntityNotFound(_0x15dae5,_0x51ffe5){return function(_0x121df9){if(!_0x121df9){_0x15dae5['sendStatus'](0x194);}return _0x121df9;};}function handleError(_0x180c75,_0x26b889){_0x26b889=_0x26b889||0x1f4;return function(_0x58aa1f){logger[_0x859f('0x22')](_0x58aa1f[_0x859f('0x23')]);if(_0x58aa1f['name']){delete _0x58aa1f['name'];}_0x180c75[_0x859f('0x16')](_0x26b889)['send'](_0x58aa1f);};}exports[_0x859f('0x24')]=function(_0x263de0,_0x43add2){var _0x1ebd23={},_0x1823c8={},_0x5826bf={'count':0x0,'rows':[]};var _0x2814a9=_[_0x859f('0x25')](db[_0x859f('0x26')]['rawAttributes'],function(_0x4c7481){return{'name':_0x4c7481[_0x859f('0x27')],'type':_0x4c7481[_0x859f('0x28')]['key']};});_0x1823c8[_0x859f('0x29')]=_['map'](_0x2814a9,_0x859f('0x2a'));_0x1823c8[_0x859f('0x2b')]=_[_0x859f('0x2c')](_0x263de0[_0x859f('0x2b')]);_0x1823c8[_0x859f('0x2d')]=_['intersection'](_0x1823c8[_0x859f('0x29')],_0x1823c8['query']);_0x1ebd23['attributes']=_[_0x859f('0x2e')](_0x1823c8[_0x859f('0x29')],qs['fields'](_0x263de0[_0x859f('0x2b')][_0x859f('0x2f')]));_0x1ebd23[_0x859f('0x30')]=_0x1ebd23[_0x859f('0x30')][_0x859f('0x31')]?_0x1ebd23[_0x859f('0x30')]:_0x1823c8['model'];if(!_0x263de0[_0x859f('0x2b')][_0x859f('0x32')](_0x859f('0x33'))){_0x1ebd23[_0x859f('0x18')]=qs[_0x859f('0x18')](_0x263de0[_0x859f('0x2b')][_0x859f('0x18')]);_0x1ebd23[_0x859f('0x1b')]=qs[_0x859f('0x1b')](_0x263de0[_0x859f('0x2b')][_0x859f('0x1b')]);}_0x1ebd23[_0x859f('0x34')]=qs[_0x859f('0x35')](_0x263de0['query'][_0x859f('0x35')]);_0x1ebd23[_0x859f('0x36')]=qs[_0x859f('0x2d')](_[_0x859f('0x37')](_0x263de0['query'],_0x1823c8[_0x859f('0x2d')]),_0x2814a9);if(_0x263de0[_0x859f('0x2b')]['filter']){_0x1ebd23[_0x859f('0x36')]=_[_0x859f('0x38')](_0x1ebd23[_0x859f('0x36')],{'$or':_[_0x859f('0x25')](_0x2814a9,function(_0x3597fe){if(_0x3597fe['type']!==_0x859f('0x39')){var _0x360ef2={};_0x360ef2[_0x3597fe[_0x859f('0x2a')]]={'$like':'%'+_0x263de0[_0x859f('0x2b')][_0x859f('0x3a')]+'%'};return _0x360ef2;}})});}_0x1ebd23=_[_0x859f('0x38')]({},_0x1ebd23,_0x263de0['options']);var _0x13f7ec={'where':_0x1ebd23[_0x859f('0x36')]};return db[_0x859f('0x26')]['count'](_0x13f7ec)[_0x859f('0x1f')](function(_0x3c2dcc){_0x5826bf[_0x859f('0x1a')]=_0x3c2dcc;if(_0x263de0[_0x859f('0x2b')][_0x859f('0x3b')]){_0x1ebd23[_0x859f('0x3c')]=[{'all':!![]}];}return db['MailTransferReport'][_0x859f('0x3d')](_0x1ebd23);})[_0x859f('0x1f')](function(_0x57eedf){_0x5826bf[_0x859f('0x3e')]=_0x57eedf;return _0x5826bf;})[_0x859f('0x1f')](respondWithFilteredResult(_0x43add2,_0x1ebd23))[_0x859f('0x3f')](handleError(_0x43add2,null));};exports['show']=function(_0x8062ac,_0x4b86ae){var _0x3317d6={'raw':!![],'where':{'id':_0x8062ac[_0x859f('0x40')]['id']}},_0x101a51={};_0x101a51[_0x859f('0x29')]=_[_0x859f('0x2c')](db['MailTransferReport'][_0x859f('0x41')]);_0x101a51[_0x859f('0x2b')]=_[_0x859f('0x2c')](_0x8062ac['query']);_0x101a51[_0x859f('0x2d')]=_[_0x859f('0x2e')](_0x101a51['model'],_0x101a51[_0x859f('0x2b')]);_0x3317d6[_0x859f('0x30')]=_[_0x859f('0x2e')](_0x101a51[_0x859f('0x29')],qs[_0x859f('0x2f')](_0x8062ac['query'][_0x859f('0x2f')]));_0x3317d6[_0x859f('0x30')]=_0x3317d6['attributes'][_0x859f('0x31')]?_0x3317d6[_0x859f('0x30')]:_0x101a51[_0x859f('0x29')];if(_0x8062ac['query'][_0x859f('0x3b')]){_0x3317d6[_0x859f('0x3c')]=[{'all':!![]}];}_0x3317d6=_[_0x859f('0x38')]({},_0x3317d6,_0x8062ac['options']);return db[_0x859f('0x26')]['find'](_0x3317d6)[_0x859f('0x1f')](handleEntityNotFound(_0x4b86ae,null))['then'](respondWithResult(_0x4b86ae,null))[_0x859f('0x3f')](handleError(_0x4b86ae,null));};exports[_0x859f('0x42')]=function(_0xa652ff,_0x469090){return db['MailTransferReport'][_0x859f('0x42')](_0xa652ff[_0x859f('0x43')],{})[_0x859f('0x1f')](respondWithResult(_0x469090,0xc9))['catch'](handleError(_0x469090,null));};exports[_0x859f('0x44')]=function(_0x47ccd7,_0x489b44){if(_0x47ccd7[_0x859f('0x43')]['id']){delete _0x47ccd7['body']['id'];}return db[_0x859f('0x26')]['find']({'where':{'id':_0x47ccd7[_0x859f('0x40')]['id']}})[_0x859f('0x1f')](handleEntityNotFound(_0x489b44,null))[_0x859f('0x1f')](saveUpdates(_0x47ccd7[_0x859f('0x43')],null))[_0x859f('0x1f')](respondWithResult(_0x489b44,null))[_0x859f('0x3f')](handleError(_0x489b44,null));};exports[_0x859f('0x20')]=function(_0x402fb1,_0x3d7052){return db[_0x859f('0x26')][_0x859f('0x45')]({'where':{'id':_0x402fb1[_0x859f('0x40')]['id']}})[_0x859f('0x1f')](handleEntityNotFound(_0x3d7052,null))['then'](removeEntity(_0x3d7052,null))[_0x859f('0x3f')](handleError(_0x3d7052,null));};exports[_0x859f('0x46')]=function(_0x33d6ea,_0x9287f){return db[_0x859f('0x26')][_0x859f('0x46')]()['then'](respondWithResult(_0x9287f,null))['catch'](handleError(_0x9287f,null));};