8486024fa0559d941078dea1223c5f139c6145e6
[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 _0x82f3=['jsforce','desk.js','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','offset','limit','undefined','count','set','Content-Range','apply','save','update','destroy','error','stack','name','send','index','map','fieldName','type','model','query','keys','intersection','fields','attributes','length','nolimit','order','sort','filters','pick','where','VIRTUAL','filter','options','then','includeAll','include','MailTransferReport','findAll','rows','catch','show','merge','find','create','body','params','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','path','to-csv','ejs','fs-extra','lodash','squel'];(function(_0x1b4052,_0x38e4e1){var _0x2518bb=function(_0x222c3b){while(--_0x222c3b){_0x1b4052['push'](_0x1b4052['shift']());}};_0x2518bb(++_0x38e4e1);}(_0x82f3,0x8c));var _0x382f=function(_0x3860c4,_0xcc2eba){_0x3860c4=_0x3860c4-0x0;var _0x494033=_0x82f3[_0x3860c4];return _0x494033;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x382f('0x0'));var zipdir=require(_0x382f('0x1'));var jsonpatch=require(_0x382f('0x2'));var rp=require(_0x382f('0x3'));var moment=require(_0x382f('0x4'));var BPromise=require(_0x382f('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0x382f('0x6'));var sox=require('sox');var csv=require(_0x382f('0x7'));var ejs=require(_0x382f('0x8'));var fs=require('fs');var fs_extra=require(_0x382f('0x9'));var _=require(_0x382f('0xa'));var squel=require(_0x382f('0xb'));var crypto=require('crypto');var jsforce=require(_0x382f('0xc'));var deskjs=require(_0x382f('0xd'));var toCsv=require(_0x382f('0x7'));var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0x382f('0xe'));var authService=require(_0x382f('0xf'));var qs=require(_0x382f('0x10'));var as=require(_0x382f('0x11'));var hardwareService=require(_0x382f('0x12'));var logger=require(_0x382f('0x13'))(_0x382f('0x14'));var utils=require('../../config/utils');var config=require(_0x382f('0x15'));var licenseUtil=require(_0x382f('0x16'));var db=require(_0x382f('0x17'))['db'];function respondWithStatusCode(_0xf9583b,_0x36854b){_0x36854b=_0x36854b||0xcc;return function(_0xedc78){if(_0xedc78){return _0xf9583b[_0x382f('0x18')](_0x36854b);}return _0xf9583b[_0x382f('0x19')](_0x36854b)[_0x382f('0x1a')]();};}function respondWithResult(_0x29a32a,_0x408caa){_0x408caa=_0x408caa||0xc8;return function(_0x2ff58){if(_0x2ff58){return _0x29a32a[_0x382f('0x19')](_0x408caa)[_0x382f('0x1b')](_0x2ff58);}};}function respondWithFilteredResult(_0x1b98e7,_0x34f770){return function(_0x355169){if(_0x355169){var _0x4cdbee=typeof _0x34f770[_0x382f('0x1c')]==='undefined'&&typeof _0x34f770[_0x382f('0x1d')]===_0x382f('0x1e');var _0x43a562=_0x355169[_0x382f('0x1f')];var _0x41670c=_0x4cdbee?0x0:_0x34f770[_0x382f('0x1c')];var _0x3315a7=_0x4cdbee?_0x355169[_0x382f('0x1f')]:_0x34f770[_0x382f('0x1c')]+_0x34f770['limit'];var _0x418a83;if(_0x3315a7>=_0x43a562){_0x3315a7=_0x43a562;_0x418a83=0xc8;}else{_0x418a83=0xce;}_0x1b98e7[_0x382f('0x19')](_0x418a83);return _0x1b98e7[_0x382f('0x20')](_0x382f('0x21'),_0x41670c+'-'+_0x3315a7+'/'+_0x43a562)[_0x382f('0x1b')](_0x355169);}return null;};}function patchUpdates(_0x3cb1fe){return function(_0x4f6bd5){try{jsonpatch[_0x382f('0x22')](_0x4f6bd5,_0x3cb1fe,!![]);}catch(_0x358064){return BPromise['reject'](_0x358064);}return _0x4f6bd5[_0x382f('0x23')]();};}function saveUpdates(_0x24eaf9,_0x3c9d86){return function(_0x103d47){if(_0x103d47){return _0x103d47[_0x382f('0x24')](_0x24eaf9)['then'](function(_0x2e0f1e){return _0x2e0f1e;});}return null;};}function removeEntity(_0x3fa696,_0x3c8fc9){return function(_0x36bc61){if(_0x36bc61){return _0x36bc61[_0x382f('0x25')]()['then'](function(){_0x3fa696[_0x382f('0x19')](0xcc)[_0x382f('0x1a')]();});}};}function handleEntityNotFound(_0x210faf,_0x375ddd){return function(_0x8d07){if(!_0x8d07){_0x210faf['sendStatus'](0x194);}return _0x8d07;};}function handleError(_0xa96527,_0x1add65){_0x1add65=_0x1add65||0x1f4;return function(_0x1e2a79){logger[_0x382f('0x26')](_0x1e2a79[_0x382f('0x27')]);if(_0x1e2a79['name']){delete _0x1e2a79[_0x382f('0x28')];}_0xa96527[_0x382f('0x19')](_0x1add65)[_0x382f('0x29')](_0x1e2a79);};}exports[_0x382f('0x2a')]=function(_0x319213,_0xf1dcff){var _0x4c0899={},_0x3d5cc4={},_0x3f7a6f={'count':0x0,'rows':[]};var _0x3a550d=_[_0x382f('0x2b')](db['MailTransferReport']['rawAttributes'],function(_0x33996c){return{'name':_0x33996c[_0x382f('0x2c')],'type':_0x33996c[_0x382f('0x2d')]['key']};});_0x3d5cc4[_0x382f('0x2e')]=_[_0x382f('0x2b')](_0x3a550d,_0x382f('0x28'));_0x3d5cc4[_0x382f('0x2f')]=_[_0x382f('0x30')](_0x319213[_0x382f('0x2f')]);_0x3d5cc4['filters']=_['intersection'](_0x3d5cc4[_0x382f('0x2e')],_0x3d5cc4['query']);_0x4c0899['attributes']=_[_0x382f('0x31')](_0x3d5cc4[_0x382f('0x2e')],qs[_0x382f('0x32')](_0x319213[_0x382f('0x2f')][_0x382f('0x32')]));_0x4c0899['attributes']=_0x4c0899[_0x382f('0x33')][_0x382f('0x34')]?_0x4c0899[_0x382f('0x33')]:_0x3d5cc4[_0x382f('0x2e')];if(!_0x319213[_0x382f('0x2f')]['hasOwnProperty'](_0x382f('0x35'))){_0x4c0899[_0x382f('0x1d')]=qs[_0x382f('0x1d')](_0x319213[_0x382f('0x2f')][_0x382f('0x1d')]);_0x4c0899[_0x382f('0x1c')]=qs[_0x382f('0x1c')](_0x319213[_0x382f('0x2f')][_0x382f('0x1c')]);}_0x4c0899[_0x382f('0x36')]=qs[_0x382f('0x37')](_0x319213[_0x382f('0x2f')][_0x382f('0x37')]);_0x4c0899['where']=qs[_0x382f('0x38')](_[_0x382f('0x39')](_0x319213[_0x382f('0x2f')],_0x3d5cc4[_0x382f('0x38')]),_0x3a550d);if(_0x319213[_0x382f('0x2f')]['filter']){_0x4c0899['where']=_['merge'](_0x4c0899[_0x382f('0x3a')],{'$or':_[_0x382f('0x2b')](_0x3a550d,function(_0x26925c){if(_0x26925c[_0x382f('0x2d')]!==_0x382f('0x3b')){var _0x5d5912={};_0x5d5912[_0x26925c[_0x382f('0x28')]]={'$like':'%'+_0x319213['query'][_0x382f('0x3c')]+'%'};return _0x5d5912;}})});}_0x4c0899=_['merge']({},_0x4c0899,_0x319213[_0x382f('0x3d')]);var _0x4ea256={'where':_0x4c0899[_0x382f('0x3a')]};return db['MailTransferReport'][_0x382f('0x1f')](_0x4ea256)[_0x382f('0x3e')](function(_0x487fe7){_0x3f7a6f[_0x382f('0x1f')]=_0x487fe7;if(_0x319213[_0x382f('0x2f')][_0x382f('0x3f')]){_0x4c0899[_0x382f('0x40')]=[{'all':!![]}];}return db[_0x382f('0x41')][_0x382f('0x42')](_0x4c0899);})['then'](function(_0xcbc9f6){_0x3f7a6f[_0x382f('0x43')]=_0xcbc9f6;return _0x3f7a6f;})['then'](respondWithFilteredResult(_0xf1dcff,_0x4c0899))[_0x382f('0x44')](handleError(_0xf1dcff,null));};exports[_0x382f('0x45')]=function(_0x556205,_0x5a47ef){var _0x2ca2c1={'raw':!![],'where':{'id':_0x556205['params']['id']}},_0x1b1b1d={};_0x1b1b1d['model']=_[_0x382f('0x30')](db['MailTransferReport']['rawAttributes']);_0x1b1b1d[_0x382f('0x2f')]=_[_0x382f('0x30')](_0x556205[_0x382f('0x2f')]);_0x1b1b1d['filters']=_['intersection'](_0x1b1b1d[_0x382f('0x2e')],_0x1b1b1d[_0x382f('0x2f')]);_0x2ca2c1[_0x382f('0x33')]=_[_0x382f('0x31')](_0x1b1b1d['model'],qs[_0x382f('0x32')](_0x556205[_0x382f('0x2f')]['fields']));_0x2ca2c1[_0x382f('0x33')]=_0x2ca2c1[_0x382f('0x33')]['length']?_0x2ca2c1[_0x382f('0x33')]:_0x1b1b1d['model'];if(_0x556205[_0x382f('0x2f')]['includeAll']){_0x2ca2c1[_0x382f('0x40')]=[{'all':!![]}];}_0x2ca2c1=_[_0x382f('0x46')]({},_0x2ca2c1,_0x556205[_0x382f('0x3d')]);return db['MailTransferReport'][_0x382f('0x47')](_0x2ca2c1)[_0x382f('0x3e')](handleEntityNotFound(_0x5a47ef,null))['then'](respondWithResult(_0x5a47ef,null))[_0x382f('0x44')](handleError(_0x5a47ef,null));};exports[_0x382f('0x48')]=function(_0x19c01b,_0x13bc38){return db[_0x382f('0x41')][_0x382f('0x48')](_0x19c01b[_0x382f('0x49')],{})[_0x382f('0x3e')](respondWithResult(_0x13bc38,0xc9))[_0x382f('0x44')](handleError(_0x13bc38,null));};exports['update']=function(_0x1275b7,_0x185916){if(_0x1275b7[_0x382f('0x49')]['id']){delete _0x1275b7[_0x382f('0x49')]['id'];}return db['MailTransferReport'][_0x382f('0x47')]({'where':{'id':_0x1275b7['params']['id']}})[_0x382f('0x3e')](handleEntityNotFound(_0x185916,null))[_0x382f('0x3e')](saveUpdates(_0x1275b7['body'],null))[_0x382f('0x3e')](respondWithResult(_0x185916,null))[_0x382f('0x44')](handleError(_0x185916,null));};exports[_0x382f('0x25')]=function(_0x554760,_0x53d793){return db[_0x382f('0x41')][_0x382f('0x47')]({'where':{'id':_0x554760[_0x382f('0x4a')]['id']}})[_0x382f('0x3e')](handleEntityNotFound(_0x53d793,null))[_0x382f('0x3e')](removeEntity(_0x53d793,null))[_0x382f('0x44')](handleError(_0x53d793,null));};exports[_0x382f('0x4b')]=function(_0x22cb7e,_0x731178){return db['MailTransferReport'][_0x382f('0x4b')]()[_0x382f('0x3e')](respondWithResult(_0x731178,null))[_0x382f('0x44')](handleError(_0x731178,null));};