7a678af5dfb01d2abba647f53ecd2593da16054b
[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 _0xbc23=['moment','bluebird','mustache','path','sox','to-csv','fs-extra','lodash','squel','crypto','desk.js','querystring','papaparse','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','sendStatus','end','status','json','undefined','count','set','apply','reject','save','update','then','destroy','stack','name','send','MailTransferReport','rawAttributes','fieldName','type','key','model','map','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','offset','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','catch','params','keys','create','body','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise'];(function(_0x99f811,_0x44d59e){var _0x37ba7f=function(_0x3f3961){while(--_0x3f3961){_0x99f811['push'](_0x99f811['shift']());}};_0x37ba7f(++_0x44d59e);}(_0xbc23,0xdf));var _0x3bc2=function(_0x3c3335,_0x1f0b31){_0x3c3335=_0x3c3335-0x0;var _0x340657=_0xbc23[_0x3c3335];return _0x340657;};'use strict';var emlformat=require(_0x3bc2('0x0'));var rimraf=require(_0x3bc2('0x1'));var zipdir=require(_0x3bc2('0x2'));var jsonpatch=require(_0x3bc2('0x3'));var rp=require(_0x3bc2('0x4'));var moment=require(_0x3bc2('0x5'));var BPromise=require(_0x3bc2('0x6'));var Mustache=require(_0x3bc2('0x7'));var util=require('util');var path=require(_0x3bc2('0x8'));var sox=require(_0x3bc2('0x9'));var csv=require(_0x3bc2('0xa'));var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x3bc2('0xb'));var _=require(_0x3bc2('0xc'));var squel=require(_0x3bc2('0xd'));var crypto=require(_0x3bc2('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x3bc2('0xf'));var toCsv=require('to-csv');var querystring=require(_0x3bc2('0x10'));var Papa=require(_0x3bc2('0x11'));var Redis=require('ioredis');var authService=require(_0x3bc2('0x12'));var qs=require(_0x3bc2('0x13'));var as=require(_0x3bc2('0x14'));var hardwareService=require(_0x3bc2('0x15'));var logger=require(_0x3bc2('0x16'))(_0x3bc2('0x17'));var utils=require(_0x3bc2('0x18'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0x3bc2('0x19'))['db'];function respondWithStatusCode(_0x3850e2,_0xaea69b){_0xaea69b=_0xaea69b||0xcc;return function(_0x5818fc){if(_0x5818fc){return _0x3850e2[_0x3bc2('0x1a')](_0xaea69b);}return _0x3850e2['status'](_0xaea69b)[_0x3bc2('0x1b')]();};}function respondWithResult(_0x9e49a7,_0x404a90){_0x404a90=_0x404a90||0xc8;return function(_0x3d1adc){if(_0x3d1adc){return _0x9e49a7[_0x3bc2('0x1c')](_0x404a90)[_0x3bc2('0x1d')](_0x3d1adc);}};}function respondWithFilteredResult(_0x4181ee,_0x1f41e6){return function(_0x8e68cf){if(_0x8e68cf){var _0xe5c89d=typeof _0x1f41e6['offset']===_0x3bc2('0x1e')&&typeof _0x1f41e6['limit']===_0x3bc2('0x1e');var _0x544ecf=_0x8e68cf[_0x3bc2('0x1f')];var _0x408dc6=_0xe5c89d?0x0:_0x1f41e6['offset'];var _0x2f0985=_0xe5c89d?_0x8e68cf[_0x3bc2('0x1f')]:_0x1f41e6['offset']+_0x1f41e6['limit'];var _0x5a5245;if(_0x2f0985>=_0x544ecf){_0x2f0985=_0x544ecf;_0x5a5245=0xc8;}else{_0x5a5245=0xce;}_0x4181ee['status'](_0x5a5245);return _0x4181ee[_0x3bc2('0x20')]('Content-Range',_0x408dc6+'-'+_0x2f0985+'/'+_0x544ecf)[_0x3bc2('0x1d')](_0x8e68cf);}return null;};}function patchUpdates(_0x58398b){return function(_0x1239a9){try{jsonpatch[_0x3bc2('0x21')](_0x1239a9,_0x58398b,!![]);}catch(_0x22b0e){return BPromise[_0x3bc2('0x22')](_0x22b0e);}return _0x1239a9[_0x3bc2('0x23')]();};}function saveUpdates(_0x1c416c,_0x2d7aac){return function(_0x15d272){if(_0x15d272){return _0x15d272[_0x3bc2('0x24')](_0x1c416c)[_0x3bc2('0x25')](function(_0x50c38f){return _0x50c38f;});}return null;};}function removeEntity(_0x4c8e55,_0x7c1d41){return function(_0x3c3f10){if(_0x3c3f10){return _0x3c3f10[_0x3bc2('0x26')]()[_0x3bc2('0x25')](function(){_0x4c8e55[_0x3bc2('0x1c')](0xcc)[_0x3bc2('0x1b')]();});}};}function handleEntityNotFound(_0x252a35,_0x137f7f){return function(_0x5b2460){if(!_0x5b2460){_0x252a35[_0x3bc2('0x1a')](0x194);}return _0x5b2460;};}function handleError(_0x364ef5,_0x4e6246){_0x4e6246=_0x4e6246||0x1f4;return function(_0x574d14){logger['error'](_0x574d14[_0x3bc2('0x27')]);if(_0x574d14[_0x3bc2('0x28')]){delete _0x574d14['name'];}_0x364ef5[_0x3bc2('0x1c')](_0x4e6246)[_0x3bc2('0x29')](_0x574d14);};}exports['index']=function(_0x238815,_0x475bb7){var _0x1c22cb={},_0x3b733d={},_0x42f458={'count':0x0,'rows':[]};var _0x137f3f=_['map'](db[_0x3bc2('0x2a')][_0x3bc2('0x2b')],function(_0xd7f431){return{'name':_0xd7f431[_0x3bc2('0x2c')],'type':_0xd7f431[_0x3bc2('0x2d')][_0x3bc2('0x2e')]};});_0x3b733d[_0x3bc2('0x2f')]=_[_0x3bc2('0x30')](_0x137f3f,_0x3bc2('0x28'));_0x3b733d[_0x3bc2('0x31')]=_['keys'](_0x238815[_0x3bc2('0x31')]);_0x3b733d['filters']=_[_0x3bc2('0x32')](_0x3b733d[_0x3bc2('0x2f')],_0x3b733d[_0x3bc2('0x31')]);_0x1c22cb[_0x3bc2('0x33')]=_[_0x3bc2('0x32')](_0x3b733d[_0x3bc2('0x2f')],qs[_0x3bc2('0x34')](_0x238815[_0x3bc2('0x31')]['fields']));_0x1c22cb[_0x3bc2('0x33')]=_0x1c22cb[_0x3bc2('0x33')][_0x3bc2('0x35')]?_0x1c22cb[_0x3bc2('0x33')]:_0x3b733d[_0x3bc2('0x2f')];if(!_0x238815[_0x3bc2('0x31')][_0x3bc2('0x36')](_0x3bc2('0x37'))){_0x1c22cb['limit']=qs[_0x3bc2('0x38')](_0x238815[_0x3bc2('0x31')][_0x3bc2('0x38')]);_0x1c22cb[_0x3bc2('0x39')]=qs['offset'](_0x238815['query']['offset']);}_0x1c22cb[_0x3bc2('0x3a')]=qs[_0x3bc2('0x3b')](_0x238815[_0x3bc2('0x31')]['sort']);_0x1c22cb[_0x3bc2('0x3c')]=qs[_0x3bc2('0x3d')](_[_0x3bc2('0x3e')](_0x238815[_0x3bc2('0x31')],_0x3b733d[_0x3bc2('0x3d')]),_0x137f3f);if(_0x238815['query'][_0x3bc2('0x3f')]){_0x1c22cb[_0x3bc2('0x3c')]=_[_0x3bc2('0x40')](_0x1c22cb[_0x3bc2('0x3c')],{'$or':_[_0x3bc2('0x30')](_0x137f3f,function(_0x7f29bc){if(_0x7f29bc[_0x3bc2('0x2d')]!==_0x3bc2('0x41')){var _0x18e9d7={};_0x18e9d7[_0x7f29bc[_0x3bc2('0x28')]]={'$like':'%'+_0x238815[_0x3bc2('0x31')][_0x3bc2('0x3f')]+'%'};return _0x18e9d7;}})});}_0x1c22cb=_[_0x3bc2('0x40')]({},_0x1c22cb,_0x238815[_0x3bc2('0x42')]);var _0x56794c={'where':_0x1c22cb[_0x3bc2('0x3c')]};return db[_0x3bc2('0x2a')][_0x3bc2('0x1f')](_0x56794c)['then'](function(_0x383df4){_0x42f458['count']=_0x383df4;if(_0x238815[_0x3bc2('0x31')][_0x3bc2('0x43')]){_0x1c22cb[_0x3bc2('0x44')]=[{'all':!![]}];}return db[_0x3bc2('0x2a')]['findAll'](_0x1c22cb);})[_0x3bc2('0x25')](function(_0x559cbc){_0x42f458['rows']=_0x559cbc;return _0x42f458;})[_0x3bc2('0x25')](respondWithFilteredResult(_0x475bb7,_0x1c22cb))[_0x3bc2('0x45')](handleError(_0x475bb7,null));};exports['show']=function(_0x5576f6,_0xbed36c){var _0xd3b97e={'raw':!![],'where':{'id':_0x5576f6[_0x3bc2('0x46')]['id']}},_0x3c285d={};_0x3c285d[_0x3bc2('0x2f')]=_[_0x3bc2('0x47')](db['MailTransferReport']['rawAttributes']);_0x3c285d[_0x3bc2('0x31')]=_[_0x3bc2('0x47')](_0x5576f6[_0x3bc2('0x31')]);_0x3c285d['filters']=_[_0x3bc2('0x32')](_0x3c285d['model'],_0x3c285d[_0x3bc2('0x31')]);_0xd3b97e[_0x3bc2('0x33')]=_[_0x3bc2('0x32')](_0x3c285d['model'],qs[_0x3bc2('0x34')](_0x5576f6[_0x3bc2('0x31')]['fields']));_0xd3b97e[_0x3bc2('0x33')]=_0xd3b97e[_0x3bc2('0x33')][_0x3bc2('0x35')]?_0xd3b97e['attributes']:_0x3c285d['model'];if(_0x5576f6[_0x3bc2('0x31')][_0x3bc2('0x43')]){_0xd3b97e[_0x3bc2('0x44')]=[{'all':!![]}];}_0xd3b97e=_[_0x3bc2('0x40')]({},_0xd3b97e,_0x5576f6[_0x3bc2('0x42')]);return db['MailTransferReport']['find'](_0xd3b97e)['then'](handleEntityNotFound(_0xbed36c,null))[_0x3bc2('0x25')](respondWithResult(_0xbed36c,null))[_0x3bc2('0x45')](handleError(_0xbed36c,null));};exports[_0x3bc2('0x48')]=function(_0x4b94b7,_0x26273c){return db[_0x3bc2('0x2a')][_0x3bc2('0x48')](_0x4b94b7[_0x3bc2('0x49')],{})[_0x3bc2('0x25')](respondWithResult(_0x26273c,0xc9))[_0x3bc2('0x45')](handleError(_0x26273c,null));};exports[_0x3bc2('0x24')]=function(_0xdc2be2,_0xbcea11){if(_0xdc2be2[_0x3bc2('0x49')]['id']){delete _0xdc2be2['body']['id'];}return db[_0x3bc2('0x2a')][_0x3bc2('0x4a')]({'where':{'id':_0xdc2be2[_0x3bc2('0x46')]['id']}})['then'](handleEntityNotFound(_0xbcea11,null))[_0x3bc2('0x25')](saveUpdates(_0xdc2be2[_0x3bc2('0x49')],null))[_0x3bc2('0x25')](respondWithResult(_0xbcea11,null))['catch'](handleError(_0xbcea11,null));};exports[_0x3bc2('0x26')]=function(_0x1d0569,_0x2f73f5){return db['MailTransferReport']['find']({'where':{'id':_0x1d0569[_0x3bc2('0x46')]['id']}})[_0x3bc2('0x25')](handleEntityNotFound(_0x2f73f5,null))['then'](removeEntity(_0x2f73f5,null))[_0x3bc2('0x45')](handleError(_0x2f73f5,null));};exports['describe']=function(_0x39e37c,_0x18f000){return db['MailTransferReport'][_0x3bc2('0x4b')]()[_0x3bc2('0x25')](respondWithResult(_0x18f000,null))['catch'](handleError(_0x18f000,null));};