Built motion from commit (unavailable).|2.5.15
[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 _0x189f=['mustache','util','path','ejs','lodash','squel','crypto','jsforce','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','sendStatus','status','json','count','set','apply','save','update','destroy','then','end','error','stack','name','index','map','MailTransferReport','rawAttributes','key','model','query','keys','filters','intersection','attributes','fields','length','limit','offset','order','sort','where','merge','VIRTUAL','includeAll','findAll','show','params','include','options','catch','create','body','find','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch'];(function(_0xd5ef45,_0x570c6e){var _0x28139b=function(_0x11385c){while(--_0x11385c){_0xd5ef45['push'](_0xd5ef45['shift']());}};_0x28139b(++_0x570c6e);}(_0x189f,0x145));var _0xf189=function(_0x4ee2be,_0x188b82){_0x4ee2be=_0x4ee2be-0x0;var _0x165535=_0x189f[_0x4ee2be];return _0x165535;};'use strict';var pdf=require(_0xf189('0x0'));var emlformat=require(_0xf189('0x1'));var rimraf=require(_0xf189('0x2'));var zipdir=require(_0xf189('0x3'));var jsonpatch=require(_0xf189('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf189('0x5'));var util=require(_0xf189('0x6'));var path=require(_0xf189('0x7'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0xf189('0x8'));var fs=require('fs');var _=require(_0xf189('0x9'));var squel=require(_0xf189('0xa'));var crypto=require(_0xf189('0xb'));var jsforce=require(_0xf189('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0xf189('0xd'));var Papa=require(_0xf189('0xe'));var Redis=require('ioredis');var authService=require(_0xf189('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0xf189('0x10'));var hardwareService=require(_0xf189('0x11'));var logger=require(_0xf189('0x12'))(_0xf189('0x13'));var utils=require('../../config/utils');var config=require(_0xf189('0x14'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3826b5,_0x58725d){_0x58725d=_0x58725d||0xcc;return function(_0x359bbf){if(_0x359bbf){return _0x3826b5[_0xf189('0x15')](_0x58725d);}return _0x3826b5[_0xf189('0x16')](_0x58725d)['end']();};}function respondWithResult(_0x5625f1,_0x5f5241){_0x5f5241=_0x5f5241||0xc8;return function(_0x1634f2){if(_0x1634f2){return _0x5625f1[_0xf189('0x16')](_0x5f5241)[_0xf189('0x17')](_0x1634f2);}};}function respondWithFilteredResult(_0x3482db,_0xe42ab8){return function(_0xb279e3){if(_0xb279e3){var _0x5b7889=_0xb279e3[_0xf189('0x18')],_0x40f6b0=_0xe42ab8['offset'],_0x5e458c=_0xe42ab8['offset']+_0xe42ab8['limit'],_0x1f7a2a;if(_0x5e458c>=_0x5b7889){_0x5e458c=_0x5b7889;_0x1f7a2a=0xc8;}else{_0x1f7a2a=0xce;}_0x3482db[_0xf189('0x16')](_0x1f7a2a);return _0x3482db[_0xf189('0x19')]('Content-Range',_0x40f6b0+'-'+_0x5e458c+'/'+_0x5b7889)['json'](_0xb279e3);}return null;};}function patchUpdates(_0x133103){return function(_0x11ae7b){try{jsonpatch[_0xf189('0x1a')](_0x11ae7b,_0x133103,!![]);}catch(_0x3df629){return BPromise['reject'](_0x3df629);}return _0x11ae7b[_0xf189('0x1b')]();};}function saveUpdates(_0x4f28ff,_0xdc0b26){return function(_0x24c868){if(_0x24c868){return _0x24c868[_0xf189('0x1c')](_0x4f28ff)['then'](function(_0x479085){return _0x479085;});}return null;};}function removeEntity(_0x186324,_0x5581be){return function(_0x507d4c){if(_0x507d4c){return _0x507d4c[_0xf189('0x1d')]()[_0xf189('0x1e')](function(){_0x186324[_0xf189('0x16')](0xcc)[_0xf189('0x1f')]();});}};}function handleEntityNotFound(_0xc28f41,_0x17ee9c){return function(_0x844a6){if(!_0x844a6){_0xc28f41[_0xf189('0x15')](0x194);}return _0x844a6;};}function handleError(_0x544842,_0x4f7614){_0x4f7614=_0x4f7614||0x1f4;return function(_0x2b7d3f){logger[_0xf189('0x20')](_0x2b7d3f[_0xf189('0x21')]);if(_0x2b7d3f['name']){delete _0x2b7d3f[_0xf189('0x22')];}_0x544842['status'](_0x4f7614)['send'](_0x2b7d3f);};}exports[_0xf189('0x23')]=function(_0x277546,_0x26ba73){var _0x1905c9={},_0x4c0a09={},_0x504502={'count':0x0,'rows':[]};var _0x2a8af3=_[_0xf189('0x24')](db[_0xf189('0x25')][_0xf189('0x26')],function(_0x31678e){return{'name':_0x31678e['fieldName'],'type':_0x31678e['type'][_0xf189('0x27')]};});_0x4c0a09[_0xf189('0x28')]=_[_0xf189('0x24')](_0x2a8af3,'name');_0x4c0a09[_0xf189('0x29')]=_[_0xf189('0x2a')](_0x277546[_0xf189('0x29')]);_0x4c0a09[_0xf189('0x2b')]=_[_0xf189('0x2c')](_0x4c0a09[_0xf189('0x28')],_0x4c0a09[_0xf189('0x29')]);_0x1905c9[_0xf189('0x2d')]=_['intersection'](_0x4c0a09[_0xf189('0x28')],qs[_0xf189('0x2e')](_0x277546[_0xf189('0x29')]['fields']));_0x1905c9['attributes']=_0x1905c9[_0xf189('0x2d')][_0xf189('0x2f')]?_0x1905c9[_0xf189('0x2d')]:_0x4c0a09['model'];if(!_0x277546['query']['hasOwnProperty']('nolimit')){_0x1905c9[_0xf189('0x30')]=qs['limit'](_0x277546[_0xf189('0x29')][_0xf189('0x30')]);_0x1905c9[_0xf189('0x31')]=qs[_0xf189('0x31')](_0x277546[_0xf189('0x29')][_0xf189('0x31')]);}_0x1905c9[_0xf189('0x32')]=qs[_0xf189('0x33')](_0x277546[_0xf189('0x29')][_0xf189('0x33')]);_0x1905c9[_0xf189('0x34')]=qs[_0xf189('0x2b')](_['pick'](_0x277546[_0xf189('0x29')],_0x4c0a09['filters']),_0x2a8af3);if(_0x277546[_0xf189('0x29')]['filter']){_0x1905c9[_0xf189('0x34')]=_[_0xf189('0x35')](_0x1905c9['where'],{'$or':_[_0xf189('0x24')](_0x2a8af3,function(_0x467da1){if(_0x467da1['type']!==_0xf189('0x36')){var _0xacf1d0={};_0xacf1d0[_0x467da1[_0xf189('0x22')]]={'$like':'%'+_0x277546[_0xf189('0x29')]['filter']+'%'};return _0xacf1d0;}})});}_0x1905c9=_['merge']({},_0x1905c9,_0x277546['options']);var _0x3c02ba={'where':_0x1905c9[_0xf189('0x34')]};return db[_0xf189('0x25')][_0xf189('0x18')](_0x3c02ba)[_0xf189('0x1e')](function(_0x2daf5b){_0x504502[_0xf189('0x18')]=_0x2daf5b;if(_0x277546[_0xf189('0x29')][_0xf189('0x37')]){_0x1905c9['include']=[{'all':!![]}];}return db[_0xf189('0x25')][_0xf189('0x38')](_0x1905c9);})[_0xf189('0x1e')](function(_0x4f4e51){_0x504502['rows']=_0x4f4e51;return _0x504502;})[_0xf189('0x1e')](respondWithFilteredResult(_0x26ba73,_0x1905c9))['catch'](handleError(_0x26ba73,null));};exports[_0xf189('0x39')]=function(_0x337753,_0x20d6e5){var _0x22abd4={'raw':!![],'where':{'id':_0x337753[_0xf189('0x3a')]['id']}},_0x1e48cf={};_0x1e48cf[_0xf189('0x28')]=_[_0xf189('0x2a')](db['MailTransferReport'][_0xf189('0x26')]);_0x1e48cf[_0xf189('0x29')]=_[_0xf189('0x2a')](_0x337753[_0xf189('0x29')]);_0x1e48cf[_0xf189('0x2b')]=_['intersection'](_0x1e48cf[_0xf189('0x28')],_0x1e48cf[_0xf189('0x29')]);_0x22abd4[_0xf189('0x2d')]=_[_0xf189('0x2c')](_0x1e48cf[_0xf189('0x28')],qs[_0xf189('0x2e')](_0x337753[_0xf189('0x29')][_0xf189('0x2e')]));_0x22abd4[_0xf189('0x2d')]=_0x22abd4['attributes'][_0xf189('0x2f')]?_0x22abd4[_0xf189('0x2d')]:_0x1e48cf[_0xf189('0x28')];if(_0x337753['query'][_0xf189('0x37')]){_0x22abd4[_0xf189('0x3b')]=[{'all':!![]}];}_0x22abd4=_[_0xf189('0x35')]({},_0x22abd4,_0x337753[_0xf189('0x3c')]);return db[_0xf189('0x25')]['find'](_0x22abd4)[_0xf189('0x1e')](handleEntityNotFound(_0x20d6e5,null))[_0xf189('0x1e')](respondWithResult(_0x20d6e5,null))[_0xf189('0x3d')](handleError(_0x20d6e5,null));};exports[_0xf189('0x3e')]=function(_0x38f3ae,_0x48f82e){return db[_0xf189('0x25')][_0xf189('0x3e')](_0x38f3ae[_0xf189('0x3f')],{})[_0xf189('0x1e')](respondWithResult(_0x48f82e,0xc9))['catch'](handleError(_0x48f82e,null));};exports[_0xf189('0x1c')]=function(_0x3e7288,_0x44f87e){if(_0x3e7288[_0xf189('0x3f')]['id']){delete _0x3e7288[_0xf189('0x3f')]['id'];}return db[_0xf189('0x25')][_0xf189('0x40')]({'where':{'id':_0x3e7288[_0xf189('0x3a')]['id']}})[_0xf189('0x1e')](handleEntityNotFound(_0x44f87e,null))[_0xf189('0x1e')](saveUpdates(_0x3e7288['body'],null))['then'](respondWithResult(_0x44f87e,null))[_0xf189('0x3d')](handleError(_0x44f87e,null));};exports[_0xf189('0x1d')]=function(_0x481031,_0x3c825a){return db[_0xf189('0x25')][_0xf189('0x40')]({'where':{'id':_0x481031[_0xf189('0x3a')]['id']}})[_0xf189('0x1e')](handleEntityNotFound(_0x3c825a,null))['then'](removeEntity(_0x3c825a,null))[_0xf189('0x3d')](handleError(_0x3c825a,null));};exports['describe']=function(_0x37bfa7,_0x150024){return db[_0xf189('0x25')][_0xf189('0x41')]()[_0xf189('0x1e')](respondWithResult(_0x150024,null))[_0xf189('0x3d')](handleError(_0x150024,null));};