8c6f357abf3a65f9515b13e993f159af7b77d1ed
[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 _0xf684=['count','set','Content-Range','apply','destroy','then','stack','name','index','map','MailTransferReport','fieldName','type','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','find','create','body','update','describe','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','fs-extra','lodash','crypto','jsforce','desk.js','to-csv','querystring','papaparse','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','sendStatus','end','status','offset','undefined','limit'];(function(_0x3cddd2,_0x29ad30){var _0x2b835b=function(_0x17733e){while(--_0x17733e){_0x3cddd2['push'](_0x3cddd2['shift']());}};_0x2b835b(++_0x29ad30);}(_0xf684,0xb6));var _0x4f68=function(_0x4a1582,_0x3b696a){_0x4a1582=_0x4a1582-0x0;var _0x122f16=_0xf684[_0x4a1582];return _0x122f16;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x4f68('0x0'));var zipdir=require(_0x4f68('0x1'));var jsonpatch=require(_0x4f68('0x2'));var rp=require(_0x4f68('0x3'));var moment=require(_0x4f68('0x4'));var BPromise=require(_0x4f68('0x5'));var Mustache=require(_0x4f68('0x6'));var util=require(_0x4f68('0x7'));var path=require(_0x4f68('0x8'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x4f68('0x9'));var fs=require('fs');var fs_extra=require(_0x4f68('0xa'));var _=require(_0x4f68('0xb'));var squel=require('squel');var crypto=require(_0x4f68('0xc'));var jsforce=require(_0x4f68('0xd'));var deskjs=require(_0x4f68('0xe'));var toCsv=require(_0x4f68('0xf'));var querystring=require(_0x4f68('0x10'));var Papa=require(_0x4f68('0x11'));var Redis=require('ioredis');var authService=require(_0x4f68('0x12'));var qs=require('../../components/parsers/qs');var as=require(_0x4f68('0x13'));var hardwareService=require(_0x4f68('0x14'));var logger=require(_0x4f68('0x15'))(_0x4f68('0x16'));var utils=require(_0x4f68('0x17'));var config=require(_0x4f68('0x18'));var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x41c014,_0xd0d1d){_0xd0d1d=_0xd0d1d||0xcc;return function(_0x5e9bdc){if(_0x5e9bdc){return _0x41c014[_0x4f68('0x19')](_0xd0d1d);}return _0x41c014['status'](_0xd0d1d)[_0x4f68('0x1a')]();};}function respondWithResult(_0x2a7c2a,_0x111ada){_0x111ada=_0x111ada||0xc8;return function(_0x388c8a){if(_0x388c8a){return _0x2a7c2a[_0x4f68('0x1b')](_0x111ada)['json'](_0x388c8a);}};}function respondWithFilteredResult(_0x5485ea,_0xf8f072){return function(_0x1ae7bf){if(_0x1ae7bf){var _0x221a05=typeof _0xf8f072[_0x4f68('0x1c')]===_0x4f68('0x1d')&&typeof _0xf8f072[_0x4f68('0x1e')]==='undefined';var _0x4f8757=_0x1ae7bf[_0x4f68('0x1f')];var _0xd0e056=_0x221a05?0x0:_0xf8f072[_0x4f68('0x1c')];var _0x2c9298=_0x221a05?_0x1ae7bf[_0x4f68('0x1f')]:_0xf8f072[_0x4f68('0x1c')]+_0xf8f072[_0x4f68('0x1e')];var _0x4b80f9;if(_0x2c9298>=_0x4f8757){_0x2c9298=_0x4f8757;_0x4b80f9=0xc8;}else{_0x4b80f9=0xce;}_0x5485ea[_0x4f68('0x1b')](_0x4b80f9);return _0x5485ea[_0x4f68('0x20')](_0x4f68('0x21'),_0xd0e056+'-'+_0x2c9298+'/'+_0x4f8757)['json'](_0x1ae7bf);}return null;};}function patchUpdates(_0x3baac2){return function(_0x1a93d0){try{jsonpatch[_0x4f68('0x22')](_0x1a93d0,_0x3baac2,!![]);}catch(_0x41764c){return BPromise['reject'](_0x41764c);}return _0x1a93d0['save']();};}function saveUpdates(_0x3a0bfc,_0x300d69){return function(_0x11b6cc){if(_0x11b6cc){return _0x11b6cc['update'](_0x3a0bfc)['then'](function(_0x5c39a0){return _0x5c39a0;});}return null;};}function removeEntity(_0x297d20,_0x56fbb1){return function(_0x48bb87){if(_0x48bb87){return _0x48bb87[_0x4f68('0x23')]()[_0x4f68('0x24')](function(){_0x297d20['status'](0xcc)[_0x4f68('0x1a')]();});}};}function handleEntityNotFound(_0x8b544f,_0x42d23a){return function(_0x227185){if(!_0x227185){_0x8b544f[_0x4f68('0x19')](0x194);}return _0x227185;};}function handleError(_0x3d59f5,_0x447de0){_0x447de0=_0x447de0||0x1f4;return function(_0x4800bd){logger['error'](_0x4800bd[_0x4f68('0x25')]);if(_0x4800bd[_0x4f68('0x26')]){delete _0x4800bd[_0x4f68('0x26')];}_0x3d59f5[_0x4f68('0x1b')](_0x447de0)['send'](_0x4800bd);};}exports[_0x4f68('0x27')]=function(_0x52a27c,_0x3276d4){var _0x8fd83b={},_0x5b9163={},_0x527c2f={'count':0x0,'rows':[]};var _0x33f04c=_[_0x4f68('0x28')](db[_0x4f68('0x29')]['rawAttributes'],function(_0x301f60){return{'name':_0x301f60[_0x4f68('0x2a')],'type':_0x301f60[_0x4f68('0x2b')]['key']};});_0x5b9163[_0x4f68('0x2c')]=_[_0x4f68('0x28')](_0x33f04c,_0x4f68('0x26'));_0x5b9163[_0x4f68('0x2d')]=_[_0x4f68('0x2e')](_0x52a27c[_0x4f68('0x2d')]);_0x5b9163[_0x4f68('0x2f')]=_[_0x4f68('0x30')](_0x5b9163['model'],_0x5b9163['query']);_0x8fd83b[_0x4f68('0x31')]=_['intersection'](_0x5b9163[_0x4f68('0x2c')],qs[_0x4f68('0x32')](_0x52a27c[_0x4f68('0x2d')][_0x4f68('0x32')]));_0x8fd83b[_0x4f68('0x31')]=_0x8fd83b[_0x4f68('0x31')][_0x4f68('0x33')]?_0x8fd83b[_0x4f68('0x31')]:_0x5b9163[_0x4f68('0x2c')];if(!_0x52a27c['query'][_0x4f68('0x34')](_0x4f68('0x35'))){_0x8fd83b[_0x4f68('0x1e')]=qs['limit'](_0x52a27c[_0x4f68('0x2d')]['limit']);_0x8fd83b[_0x4f68('0x1c')]=qs[_0x4f68('0x1c')](_0x52a27c[_0x4f68('0x2d')][_0x4f68('0x1c')]);}_0x8fd83b[_0x4f68('0x36')]=qs[_0x4f68('0x37')](_0x52a27c['query'][_0x4f68('0x37')]);_0x8fd83b['where']=qs[_0x4f68('0x2f')](_['pick'](_0x52a27c[_0x4f68('0x2d')],_0x5b9163[_0x4f68('0x2f')]),_0x33f04c);if(_0x52a27c[_0x4f68('0x2d')][_0x4f68('0x38')]){_0x8fd83b[_0x4f68('0x39')]=_['merge'](_0x8fd83b[_0x4f68('0x39')],{'$or':_[_0x4f68('0x28')](_0x33f04c,function(_0x1be620){if(_0x1be620['type']!==_0x4f68('0x3a')){var _0x290441={};_0x290441[_0x1be620[_0x4f68('0x26')]]={'$like':'%'+_0x52a27c[_0x4f68('0x2d')]['filter']+'%'};return _0x290441;}})});}_0x8fd83b=_['merge']({},_0x8fd83b,_0x52a27c[_0x4f68('0x3b')]);var _0x3fcf0a={'where':_0x8fd83b[_0x4f68('0x39')]};return db[_0x4f68('0x29')][_0x4f68('0x1f')](_0x3fcf0a)[_0x4f68('0x24')](function(_0x5c6082){_0x527c2f[_0x4f68('0x1f')]=_0x5c6082;if(_0x52a27c[_0x4f68('0x2d')][_0x4f68('0x3c')]){_0x8fd83b[_0x4f68('0x3d')]=[{'all':!![]}];}return db[_0x4f68('0x29')][_0x4f68('0x3e')](_0x8fd83b);})[_0x4f68('0x24')](function(_0x4c940d){_0x527c2f[_0x4f68('0x3f')]=_0x4c940d;return _0x527c2f;})[_0x4f68('0x24')](respondWithFilteredResult(_0x3276d4,_0x8fd83b))[_0x4f68('0x40')](handleError(_0x3276d4,null));};exports['show']=function(_0x22681a,_0x55981b){var _0x211689={'raw':!![],'where':{'id':_0x22681a[_0x4f68('0x41')]['id']}},_0x3a12f4={};_0x3a12f4[_0x4f68('0x2c')]=_[_0x4f68('0x2e')](db['MailTransferReport']['rawAttributes']);_0x3a12f4['query']=_[_0x4f68('0x2e')](_0x22681a[_0x4f68('0x2d')]);_0x3a12f4['filters']=_[_0x4f68('0x30')](_0x3a12f4[_0x4f68('0x2c')],_0x3a12f4[_0x4f68('0x2d')]);_0x211689[_0x4f68('0x31')]=_[_0x4f68('0x30')](_0x3a12f4[_0x4f68('0x2c')],qs[_0x4f68('0x32')](_0x22681a['query'][_0x4f68('0x32')]));_0x211689[_0x4f68('0x31')]=_0x211689[_0x4f68('0x31')]['length']?_0x211689[_0x4f68('0x31')]:_0x3a12f4['model'];if(_0x22681a[_0x4f68('0x2d')]['includeAll']){_0x211689['include']=[{'all':!![]}];}_0x211689=_['merge']({},_0x211689,_0x22681a['options']);return db[_0x4f68('0x29')][_0x4f68('0x42')](_0x211689)['then'](handleEntityNotFound(_0x55981b,null))[_0x4f68('0x24')](respondWithResult(_0x55981b,null))['catch'](handleError(_0x55981b,null));};exports['create']=function(_0x5108f3,_0x1da25e){return db['MailTransferReport'][_0x4f68('0x43')](_0x5108f3[_0x4f68('0x44')],{})[_0x4f68('0x24')](respondWithResult(_0x1da25e,0xc9))[_0x4f68('0x40')](handleError(_0x1da25e,null));};exports[_0x4f68('0x45')]=function(_0x4261ca,_0x93ced8){if(_0x4261ca[_0x4f68('0x44')]['id']){delete _0x4261ca[_0x4f68('0x44')]['id'];}return db[_0x4f68('0x29')][_0x4f68('0x42')]({'where':{'id':_0x4261ca[_0x4f68('0x41')]['id']}})[_0x4f68('0x24')](handleEntityNotFound(_0x93ced8,null))[_0x4f68('0x24')](saveUpdates(_0x4261ca[_0x4f68('0x44')],null))['then'](respondWithResult(_0x93ced8,null))['catch'](handleError(_0x93ced8,null));};exports[_0x4f68('0x23')]=function(_0xa63eca,_0x309190){return db[_0x4f68('0x29')][_0x4f68('0x42')]({'where':{'id':_0xa63eca[_0x4f68('0x41')]['id']}})[_0x4f68('0x24')](handleEntityNotFound(_0x309190,null))[_0x4f68('0x24')](removeEntity(_0x309190,null))[_0x4f68('0x40')](handleError(_0x309190,null));};exports[_0x4f68('0x46')]=function(_0xd30f15,_0x1a08fe){return db['MailTransferReport']['describe']()[_0x4f68('0x24')](respondWithResult(_0x1a08fe,null))[_0x4f68('0x40')](handleError(_0x1a08fe,null));};