Built motion from commit (unavailable).|2.5.7
[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 _0x6f58=['querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','status','end','offset','set','Content-Range','json','apply','reject','update','then','destroy','error','stack','name','send','index','MailTransferReport','type','key','map','query','keys','filters','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','limit','order','sort','where','pick','filter','merge','options','count','includeAll','include','findAll','rows','catch','find','create','body','params','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','to-csv','ejs','lodash','squel','crypto','jsforce'];(function(_0x88cd7b,_0x4c884c){var _0x56fcc8=function(_0x513b3d){while(--_0x513b3d){_0x88cd7b['push'](_0x88cd7b['shift']());}};_0x56fcc8(++_0x4c884c);}(_0x6f58,0x1ad));var _0x86f5=function(_0x3615ab,_0x452e2c){_0x3615ab=_0x3615ab-0x0;var _0x4a14e6=_0x6f58[_0x3615ab];return _0x4a14e6;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x86f5('0x0'));var rimraf=require(_0x86f5('0x1'));var zipdir=require(_0x86f5('0x2'));var jsonpatch=require(_0x86f5('0x3'));var rp=require(_0x86f5('0x4'));var moment=require(_0x86f5('0x5'));var BPromise=require(_0x86f5('0x6'));var Mustache=require(_0x86f5('0x7'));var util=require(_0x86f5('0x8'));var path=require('path');var sox=require('sox');var csv=require(_0x86f5('0x9'));var ejs=require(_0x86f5('0xa'));var fs=require('fs');var _=require(_0x86f5('0xb'));var squel=require(_0x86f5('0xc'));var crypto=require(_0x86f5('0xd'));var jsforce=require(_0x86f5('0xe'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x86f5('0xf'));var Papa=require(_0x86f5('0x10'));var Redis=require(_0x86f5('0x11'));var authService=require('../../components/auth/service');var qs=require(_0x86f5('0x12'));var as=require(_0x86f5('0x13'));var hardwareService=require(_0x86f5('0x14'));var logger=require(_0x86f5('0x15'))(_0x86f5('0x16'));var utils=require(_0x86f5('0x17'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3feb18,_0x49bfc1){_0x49bfc1=_0x49bfc1||0xcc;return function(_0x2e42f0){if(_0x2e42f0){return _0x3feb18[_0x86f5('0x18')](_0x49bfc1);}return _0x3feb18[_0x86f5('0x19')](_0x49bfc1)[_0x86f5('0x1a')]();};}function respondWithResult(_0x787e61,_0x5bb136){_0x5bb136=_0x5bb136||0xc8;return function(_0x2b95c6){if(_0x2b95c6){return _0x787e61[_0x86f5('0x19')](_0x5bb136)['json'](_0x2b95c6);}};}function respondWithFilteredResult(_0x40fc26,_0x5c934d){return function(_0x2e3375){if(_0x2e3375){var _0x4cb0fa=_0x2e3375['count'],_0x2811dc=_0x5c934d[_0x86f5('0x1b')],_0x1a4f8f=_0x5c934d['offset']+_0x5c934d['limit'],_0x101d52;if(_0x1a4f8f>=_0x4cb0fa){_0x1a4f8f=_0x4cb0fa;_0x101d52=0xc8;}else{_0x101d52=0xce;}_0x40fc26[_0x86f5('0x19')](_0x101d52);return _0x40fc26[_0x86f5('0x1c')](_0x86f5('0x1d'),_0x2811dc+'-'+_0x1a4f8f+'/'+_0x4cb0fa)[_0x86f5('0x1e')](_0x2e3375);}return null;};}function patchUpdates(_0x2c8b8c){return function(_0x133855){try{jsonpatch[_0x86f5('0x1f')](_0x133855,_0x2c8b8c,!![]);}catch(_0x26c19b){return BPromise[_0x86f5('0x20')](_0x26c19b);}return _0x133855['save']();};}function saveUpdates(_0x11de4c,_0x4e045c){return function(_0x4fb3eb){if(_0x4fb3eb){return _0x4fb3eb[_0x86f5('0x21')](_0x11de4c)[_0x86f5('0x22')](function(_0x24615b){return _0x24615b;});}return null;};}function removeEntity(_0x3381e2,_0x526e99){return function(_0xe5c1db){if(_0xe5c1db){return _0xe5c1db[_0x86f5('0x23')]()[_0x86f5('0x22')](function(){_0x3381e2[_0x86f5('0x19')](0xcc)[_0x86f5('0x1a')]();});}};}function handleEntityNotFound(_0x3a4d63,_0x4c1e43){return function(_0x1447de){if(!_0x1447de){_0x3a4d63[_0x86f5('0x18')](0x194);}return _0x1447de;};}function handleError(_0x4843fc,_0x24a87f){_0x24a87f=_0x24a87f||0x1f4;return function(_0x3d47dc){logger[_0x86f5('0x24')](_0x3d47dc[_0x86f5('0x25')]);if(_0x3d47dc[_0x86f5('0x26')]){delete _0x3d47dc[_0x86f5('0x26')];}_0x4843fc['status'](_0x24a87f)[_0x86f5('0x27')](_0x3d47dc);};}exports[_0x86f5('0x28')]=function(_0x29f0ef,_0x5efed9){var _0x291a22={},_0x1d5866={},_0x33df3c={'count':0x0,'rows':[]};var _0x5100db=_['map'](db[_0x86f5('0x29')]['rawAttributes'],function(_0x21d5c1){return{'name':_0x21d5c1['fieldName'],'type':_0x21d5c1[_0x86f5('0x2a')][_0x86f5('0x2b')]};});_0x1d5866['model']=_[_0x86f5('0x2c')](_0x5100db,_0x86f5('0x26'));_0x1d5866[_0x86f5('0x2d')]=_[_0x86f5('0x2e')](_0x29f0ef['query']);_0x1d5866[_0x86f5('0x2f')]=_['intersection'](_0x1d5866[_0x86f5('0x30')],_0x1d5866[_0x86f5('0x2d')]);_0x291a22[_0x86f5('0x31')]=_[_0x86f5('0x32')](_0x1d5866[_0x86f5('0x30')],qs[_0x86f5('0x33')](_0x29f0ef[_0x86f5('0x2d')]['fields']));_0x291a22[_0x86f5('0x31')]=_0x291a22[_0x86f5('0x31')][_0x86f5('0x34')]?_0x291a22[_0x86f5('0x31')]:_0x1d5866[_0x86f5('0x30')];if(!_0x29f0ef[_0x86f5('0x2d')][_0x86f5('0x35')](_0x86f5('0x36'))){_0x291a22[_0x86f5('0x37')]=qs[_0x86f5('0x37')](_0x29f0ef['query'][_0x86f5('0x37')]);_0x291a22['offset']=qs[_0x86f5('0x1b')](_0x29f0ef['query']['offset']);}_0x291a22[_0x86f5('0x38')]=qs[_0x86f5('0x39')](_0x29f0ef[_0x86f5('0x2d')][_0x86f5('0x39')]);_0x291a22[_0x86f5('0x3a')]=qs['filters'](_[_0x86f5('0x3b')](_0x29f0ef[_0x86f5('0x2d')],_0x1d5866[_0x86f5('0x2f')]),_0x5100db);if(_0x29f0ef[_0x86f5('0x2d')][_0x86f5('0x3c')]){_0x291a22[_0x86f5('0x3a')]=_['merge'](_0x291a22[_0x86f5('0x3a')],{'$or':_['map'](_0x5100db,function(_0x43863c){if(_0x43863c[_0x86f5('0x2a')]!=='VIRTUAL'){var _0x2dde80={};_0x2dde80[_0x43863c[_0x86f5('0x26')]]={'$like':'%'+_0x29f0ef['query']['filter']+'%'};return _0x2dde80;}})});}_0x291a22=_[_0x86f5('0x3d')]({},_0x291a22,_0x29f0ef[_0x86f5('0x3e')]);var _0x1c2fac={'where':_0x291a22['where']};return db[_0x86f5('0x29')][_0x86f5('0x3f')](_0x1c2fac)[_0x86f5('0x22')](function(_0x31494c){_0x33df3c[_0x86f5('0x3f')]=_0x31494c;if(_0x29f0ef['query'][_0x86f5('0x40')]){_0x291a22[_0x86f5('0x41')]=[{'all':!![]}];}return db[_0x86f5('0x29')][_0x86f5('0x42')](_0x291a22);})[_0x86f5('0x22')](function(_0x376956){_0x33df3c[_0x86f5('0x43')]=_0x376956;return _0x33df3c;})['then'](respondWithFilteredResult(_0x5efed9,_0x291a22))[_0x86f5('0x44')](handleError(_0x5efed9,null));};exports['show']=function(_0x232b3a,_0x5ee1a9){var _0x522254={'raw':!![],'where':{'id':_0x232b3a['params']['id']}},_0x3b385e={};_0x3b385e['model']=_['keys'](db[_0x86f5('0x29')]['rawAttributes']);_0x3b385e[_0x86f5('0x2d')]=_[_0x86f5('0x2e')](_0x232b3a[_0x86f5('0x2d')]);_0x3b385e[_0x86f5('0x2f')]=_['intersection'](_0x3b385e['model'],_0x3b385e[_0x86f5('0x2d')]);_0x522254[_0x86f5('0x31')]=_[_0x86f5('0x32')](_0x3b385e[_0x86f5('0x30')],qs['fields'](_0x232b3a[_0x86f5('0x2d')][_0x86f5('0x33')]));_0x522254['attributes']=_0x522254['attributes'][_0x86f5('0x34')]?_0x522254[_0x86f5('0x31')]:_0x3b385e[_0x86f5('0x30')];if(_0x232b3a['query'][_0x86f5('0x40')]){_0x522254[_0x86f5('0x41')]=[{'all':!![]}];}_0x522254=_[_0x86f5('0x3d')]({},_0x522254,_0x232b3a[_0x86f5('0x3e')]);return db[_0x86f5('0x29')][_0x86f5('0x45')](_0x522254)['then'](handleEntityNotFound(_0x5ee1a9,null))[_0x86f5('0x22')](respondWithResult(_0x5ee1a9,null))['catch'](handleError(_0x5ee1a9,null));};exports[_0x86f5('0x46')]=function(_0xa97607,_0x25dfea){return db[_0x86f5('0x29')]['create'](_0xa97607[_0x86f5('0x47')],{})['then'](respondWithResult(_0x25dfea,0xc9))[_0x86f5('0x44')](handleError(_0x25dfea,null));};exports[_0x86f5('0x21')]=function(_0x9f1700,_0x5a6d7a){if(_0x9f1700['body']['id']){delete _0x9f1700['body']['id'];}return db[_0x86f5('0x29')][_0x86f5('0x45')]({'where':{'id':_0x9f1700[_0x86f5('0x48')]['id']}})['then'](handleEntityNotFound(_0x5a6d7a,null))['then'](saveUpdates(_0x9f1700['body'],null))[_0x86f5('0x22')](respondWithResult(_0x5a6d7a,null))['catch'](handleError(_0x5a6d7a,null));};exports[_0x86f5('0x23')]=function(_0x35ebe2,_0x1ce4fe){return db[_0x86f5('0x29')]['find']({'where':{'id':_0x35ebe2[_0x86f5('0x48')]['id']}})['then'](handleEntityNotFound(_0x1ce4fe,null))[_0x86f5('0x22')](removeEntity(_0x1ce4fe,null))[_0x86f5('0x44')](handleError(_0x1ce4fe,null));};exports[_0x86f5('0x49')]=function(_0x33a446,_0xb6d35c){return db['MailTransferReport'][_0x86f5('0x49')]()['then'](respondWithResult(_0xb6d35c,null))[_0x86f5('0x44')](handleError(_0xb6d35c,null));};