e13a75c513d8183205cd44e915cdb1638190dd8d
[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 _0xa975=['where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','show','params','create','body','find','describe','eml-format','rimraf','zip-dir','request-promise','util','path','sox','ejs','crypto','desk.js','to-csv','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','status','end','offset','undefined','count','limit','Content-Range','json','apply','save','update','then','destroy','sendStatus','stack','name','send','index','map','MailTransferReport','rawAttributes','fieldName','type','keys','query','model','intersection','fields','attributes','hasOwnProperty','nolimit','order','sort'];(function(_0x5b8802,_0x4911ee){var _0x1135be=function(_0x2157b5){while(--_0x2157b5){_0x5b8802['push'](_0x5b8802['shift']());}};_0x1135be(++_0x4911ee);}(_0xa975,0x16a));var _0x5a97=function(_0x245490,_0x40ba27){_0x245490=_0x245490-0x0;var _0x341444=_0xa975[_0x245490];return _0x341444;};'use strict';var emlformat=require(_0x5a97('0x0'));var rimraf=require(_0x5a97('0x1'));var zipdir=require(_0x5a97('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x5a97('0x3'));var moment=require('moment');var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x5a97('0x4'));var path=require(_0x5a97('0x5'));var sox=require(_0x5a97('0x6'));var csv=require('to-csv');var ejs=require(_0x5a97('0x7'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require('squel');var crypto=require(_0x5a97('0x8'));var jsforce=require('jsforce');var deskjs=require(_0x5a97('0x9'));var toCsv=require(_0x5a97('0xa'));var querystring=require('querystring');var Papa=require(_0x5a97('0xb'));var Redis=require(_0x5a97('0xc'));var authService=require(_0x5a97('0xd'));var qs=require('../../components/parsers/qs');var as=require(_0x5a97('0xe'));var hardwareService=require(_0x5a97('0xf'));var logger=require('../../config/logger')(_0x5a97('0x10'));var utils=require(_0x5a97('0x11'));var config=require('../../config/environment');var licenseUtil=require(_0x5a97('0x12'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2275d8,_0x4ae5d5){_0x4ae5d5=_0x4ae5d5||0xcc;return function(_0x1d946c){if(_0x1d946c){return _0x2275d8['sendStatus'](_0x4ae5d5);}return _0x2275d8[_0x5a97('0x13')](_0x4ae5d5)[_0x5a97('0x14')]();};}function respondWithResult(_0x43b37f,_0xf430a0){_0xf430a0=_0xf430a0||0xc8;return function(_0x280148){if(_0x280148){return _0x43b37f[_0x5a97('0x13')](_0xf430a0)['json'](_0x280148);}};}function respondWithFilteredResult(_0x377dca,_0x33db44){return function(_0x1b4d31){if(_0x1b4d31){var _0x4c739d=typeof _0x33db44[_0x5a97('0x15')]===_0x5a97('0x16')&&typeof _0x33db44['limit']===_0x5a97('0x16');var _0xa46629=_0x1b4d31[_0x5a97('0x17')];var _0x882814=_0x4c739d?0x0:_0x33db44['offset'];var _0x1dc1c9=_0x4c739d?_0x1b4d31['count']:_0x33db44['offset']+_0x33db44[_0x5a97('0x18')];var _0x2e2ae0;if(_0x1dc1c9>=_0xa46629){_0x1dc1c9=_0xa46629;_0x2e2ae0=0xc8;}else{_0x2e2ae0=0xce;}_0x377dca[_0x5a97('0x13')](_0x2e2ae0);return _0x377dca['set'](_0x5a97('0x19'),_0x882814+'-'+_0x1dc1c9+'/'+_0xa46629)[_0x5a97('0x1a')](_0x1b4d31);}return null;};}function patchUpdates(_0x5d8f4f){return function(_0x3771e9){try{jsonpatch[_0x5a97('0x1b')](_0x3771e9,_0x5d8f4f,!![]);}catch(_0x14d149){return BPromise['reject'](_0x14d149);}return _0x3771e9[_0x5a97('0x1c')]();};}function saveUpdates(_0x27b64b,_0x1768e7){return function(_0x3c8598){if(_0x3c8598){return _0x3c8598[_0x5a97('0x1d')](_0x27b64b)[_0x5a97('0x1e')](function(_0x22304f){return _0x22304f;});}return null;};}function removeEntity(_0x262b69,_0x2eced3){return function(_0xd8f854){if(_0xd8f854){return _0xd8f854[_0x5a97('0x1f')]()[_0x5a97('0x1e')](function(){_0x262b69[_0x5a97('0x13')](0xcc)[_0x5a97('0x14')]();});}};}function handleEntityNotFound(_0x7c9884,_0x596186){return function(_0x20ea8a){if(!_0x20ea8a){_0x7c9884[_0x5a97('0x20')](0x194);}return _0x20ea8a;};}function handleError(_0x15ed71,_0x1479f7){_0x1479f7=_0x1479f7||0x1f4;return function(_0x4f6023){logger['error'](_0x4f6023[_0x5a97('0x21')]);if(_0x4f6023['name']){delete _0x4f6023[_0x5a97('0x22')];}_0x15ed71[_0x5a97('0x13')](_0x1479f7)[_0x5a97('0x23')](_0x4f6023);};}exports[_0x5a97('0x24')]=function(_0x3bbed8,_0x2c017a){var _0x2eec68={},_0x41f69c={},_0x12bf31={'count':0x0,'rows':[]};var _0x5dc8ed=_[_0x5a97('0x25')](db[_0x5a97('0x26')][_0x5a97('0x27')],function(_0x165047){return{'name':_0x165047[_0x5a97('0x28')],'type':_0x165047[_0x5a97('0x29')]['key']};});_0x41f69c['model']=_['map'](_0x5dc8ed,_0x5a97('0x22'));_0x41f69c['query']=_[_0x5a97('0x2a')](_0x3bbed8[_0x5a97('0x2b')]);_0x41f69c['filters']=_['intersection'](_0x41f69c[_0x5a97('0x2c')],_0x41f69c[_0x5a97('0x2b')]);_0x2eec68['attributes']=_[_0x5a97('0x2d')](_0x41f69c[_0x5a97('0x2c')],qs['fields'](_0x3bbed8[_0x5a97('0x2b')][_0x5a97('0x2e')]));_0x2eec68['attributes']=_0x2eec68[_0x5a97('0x2f')]['length']?_0x2eec68['attributes']:_0x41f69c[_0x5a97('0x2c')];if(!_0x3bbed8['query'][_0x5a97('0x30')](_0x5a97('0x31'))){_0x2eec68[_0x5a97('0x18')]=qs[_0x5a97('0x18')](_0x3bbed8[_0x5a97('0x2b')]['limit']);_0x2eec68[_0x5a97('0x15')]=qs[_0x5a97('0x15')](_0x3bbed8['query'][_0x5a97('0x15')]);}_0x2eec68[_0x5a97('0x32')]=qs[_0x5a97('0x33')](_0x3bbed8[_0x5a97('0x2b')][_0x5a97('0x33')]);_0x2eec68[_0x5a97('0x34')]=qs['filters'](_[_0x5a97('0x35')](_0x3bbed8[_0x5a97('0x2b')],_0x41f69c[_0x5a97('0x36')]),_0x5dc8ed);if(_0x3bbed8[_0x5a97('0x2b')][_0x5a97('0x37')]){_0x2eec68[_0x5a97('0x34')]=_[_0x5a97('0x38')](_0x2eec68[_0x5a97('0x34')],{'$or':_[_0x5a97('0x25')](_0x5dc8ed,function(_0x16c729){if(_0x16c729[_0x5a97('0x29')]!==_0x5a97('0x39')){var _0x2225c1={};_0x2225c1[_0x16c729[_0x5a97('0x22')]]={'$like':'%'+_0x3bbed8['query']['filter']+'%'};return _0x2225c1;}})});}_0x2eec68=_[_0x5a97('0x38')]({},_0x2eec68,_0x3bbed8[_0x5a97('0x3a')]);var _0xedf9e0={'where':_0x2eec68[_0x5a97('0x34')]};return db[_0x5a97('0x26')]['count'](_0xedf9e0)[_0x5a97('0x1e')](function(_0x20b3f4){_0x12bf31[_0x5a97('0x17')]=_0x20b3f4;if(_0x3bbed8[_0x5a97('0x2b')][_0x5a97('0x3b')]){_0x2eec68[_0x5a97('0x3c')]=[{'all':!![]}];}return db[_0x5a97('0x26')]['findAll'](_0x2eec68);})[_0x5a97('0x1e')](function(_0x5a5b8b){_0x12bf31[_0x5a97('0x3d')]=_0x5a5b8b;return _0x12bf31;})[_0x5a97('0x1e')](respondWithFilteredResult(_0x2c017a,_0x2eec68))[_0x5a97('0x3e')](handleError(_0x2c017a,null));};exports[_0x5a97('0x3f')]=function(_0x431308,_0x3b0bbd){var _0x2248a8={'raw':!![],'where':{'id':_0x431308[_0x5a97('0x40')]['id']}},_0x58244a={};_0x58244a[_0x5a97('0x2c')]=_['keys'](db['MailTransferReport']['rawAttributes']);_0x58244a['query']=_[_0x5a97('0x2a')](_0x431308[_0x5a97('0x2b')]);_0x58244a[_0x5a97('0x36')]=_[_0x5a97('0x2d')](_0x58244a['model'],_0x58244a[_0x5a97('0x2b')]);_0x2248a8['attributes']=_[_0x5a97('0x2d')](_0x58244a['model'],qs[_0x5a97('0x2e')](_0x431308[_0x5a97('0x2b')][_0x5a97('0x2e')]));_0x2248a8[_0x5a97('0x2f')]=_0x2248a8[_0x5a97('0x2f')]['length']?_0x2248a8['attributes']:_0x58244a[_0x5a97('0x2c')];if(_0x431308['query'][_0x5a97('0x3b')]){_0x2248a8[_0x5a97('0x3c')]=[{'all':!![]}];}_0x2248a8=_[_0x5a97('0x38')]({},_0x2248a8,_0x431308['options']);return db[_0x5a97('0x26')]['find'](_0x2248a8)[_0x5a97('0x1e')](handleEntityNotFound(_0x3b0bbd,null))['then'](respondWithResult(_0x3b0bbd,null))['catch'](handleError(_0x3b0bbd,null));};exports[_0x5a97('0x41')]=function(_0x1c12a9,_0xb710be){return db['MailTransferReport'][_0x5a97('0x41')](_0x1c12a9[_0x5a97('0x42')],{})[_0x5a97('0x1e')](respondWithResult(_0xb710be,0xc9))[_0x5a97('0x3e')](handleError(_0xb710be,null));};exports[_0x5a97('0x1d')]=function(_0x31fe41,_0x2c909e){if(_0x31fe41['body']['id']){delete _0x31fe41['body']['id'];}return db['MailTransferReport'][_0x5a97('0x43')]({'where':{'id':_0x31fe41[_0x5a97('0x40')]['id']}})[_0x5a97('0x1e')](handleEntityNotFound(_0x2c909e,null))[_0x5a97('0x1e')](saveUpdates(_0x31fe41[_0x5a97('0x42')],null))[_0x5a97('0x1e')](respondWithResult(_0x2c909e,null))[_0x5a97('0x3e')](handleError(_0x2c909e,null));};exports['destroy']=function(_0x1aaf16,_0x227d44){return db[_0x5a97('0x26')]['find']({'where':{'id':_0x1aaf16[_0x5a97('0x40')]['id']}})[_0x5a97('0x1e')](handleEntityNotFound(_0x227d44,null))[_0x5a97('0x1e')](removeEntity(_0x227d44,null))[_0x5a97('0x3e')](handleError(_0x227d44,null));};exports[_0x5a97('0x44')]=function(_0x378f67,_0x754c5e){return db['MailTransferReport'][_0x5a97('0x44')]()[_0x5a97('0x1e')](respondWithResult(_0x754c5e,null))[_0x5a97('0x3e')](handleError(_0x754c5e,null));};