Built motion from commit b0a9a629.|2.6.33
[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 _0xb6f9=['show','params','keys','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../config/license/util','sendStatus','end','status','json','offset','limit','undefined','count','set','apply','reject','save','update','then','destroy','error','name','map','MailTransferReport','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','options','includeAll','include','findAll','rows','catch'];(function(_0x4114dd,_0x2ad862){var _0x26f44c=function(_0xad2246){while(--_0xad2246){_0x4114dd['push'](_0x4114dd['shift']());}};_0x26f44c(++_0x2ad862);}(_0xb6f9,0x137));var _0x9b6f=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xb6f9[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x9b6f('0x0'));var rimraf=require(_0x9b6f('0x1'));var zipdir=require(_0x9b6f('0x2'));var jsonpatch=require(_0x9b6f('0x3'));var rp=require(_0x9b6f('0x4'));var moment=require('moment');var BPromise=require(_0x9b6f('0x5'));var Mustache=require(_0x9b6f('0x6'));var util=require(_0x9b6f('0x7'));var path=require(_0x9b6f('0x8'));var sox=require(_0x9b6f('0x9'));var csv=require(_0x9b6f('0xa'));var ejs=require(_0x9b6f('0xb'));var fs=require('fs');var fs_extra=require(_0x9b6f('0xc'));var _=require(_0x9b6f('0xd'));var squel=require('squel');var crypto=require(_0x9b6f('0xe'));var jsforce=require('jsforce');var deskjs=require(_0x9b6f('0xf'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x9b6f('0x10'));var Redis=require(_0x9b6f('0x11'));var authService=require(_0x9b6f('0x12'));var qs=require(_0x9b6f('0x13'));var as=require(_0x9b6f('0x14'));var hardwareService=require(_0x9b6f('0x15'));var logger=require('../../config/logger')(_0x9b6f('0x16'));var utils=require(_0x9b6f('0x17'));var config=require(_0x9b6f('0x18'));var licenseUtil=require(_0x9b6f('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x370bb0,_0x5d5be0){_0x5d5be0=_0x5d5be0||0xcc;return function(_0x44e6ea){if(_0x44e6ea){return _0x370bb0[_0x9b6f('0x1a')](_0x5d5be0);}return _0x370bb0['status'](_0x5d5be0)[_0x9b6f('0x1b')]();};}function respondWithResult(_0x448a34,_0x54a1f2){_0x54a1f2=_0x54a1f2||0xc8;return function(_0xda130e){if(_0xda130e){return _0x448a34[_0x9b6f('0x1c')](_0x54a1f2)[_0x9b6f('0x1d')](_0xda130e);}};}function respondWithFilteredResult(_0xce61a9,_0x30f2a1){return function(_0x1b7513){if(_0x1b7513){var _0x21032c=typeof _0x30f2a1[_0x9b6f('0x1e')]==='undefined'&&typeof _0x30f2a1[_0x9b6f('0x1f')]===_0x9b6f('0x20');var _0x40afed=_0x1b7513[_0x9b6f('0x21')];var _0x10e876=_0x21032c?0x0:_0x30f2a1['offset'];var _0x4424b4=_0x21032c?_0x1b7513[_0x9b6f('0x21')]:_0x30f2a1[_0x9b6f('0x1e')]+_0x30f2a1[_0x9b6f('0x1f')];var _0x4c4703;if(_0x4424b4>=_0x40afed){_0x4424b4=_0x40afed;_0x4c4703=0xc8;}else{_0x4c4703=0xce;}_0xce61a9[_0x9b6f('0x1c')](_0x4c4703);return _0xce61a9[_0x9b6f('0x22')]('Content-Range',_0x10e876+'-'+_0x4424b4+'/'+_0x40afed)[_0x9b6f('0x1d')](_0x1b7513);}return null;};}function patchUpdates(_0x1c1c2a){return function(_0x5f1f3b){try{jsonpatch[_0x9b6f('0x23')](_0x5f1f3b,_0x1c1c2a,!![]);}catch(_0x2fbc0e){return BPromise[_0x9b6f('0x24')](_0x2fbc0e);}return _0x5f1f3b[_0x9b6f('0x25')]();};}function saveUpdates(_0x1ac462,_0x157d83){return function(_0x3e5652){if(_0x3e5652){return _0x3e5652[_0x9b6f('0x26')](_0x1ac462)[_0x9b6f('0x27')](function(_0x14c493){return _0x14c493;});}return null;};}function removeEntity(_0x3e947d,_0x49ec7c){return function(_0x22c9d4){if(_0x22c9d4){return _0x22c9d4[_0x9b6f('0x28')]()[_0x9b6f('0x27')](function(){_0x3e947d[_0x9b6f('0x1c')](0xcc)[_0x9b6f('0x1b')]();});}};}function handleEntityNotFound(_0x34696a,_0x384041){return function(_0x2fcc50){if(!_0x2fcc50){_0x34696a['sendStatus'](0x194);}return _0x2fcc50;};}function handleError(_0x4141b3,_0x1d8680){_0x1d8680=_0x1d8680||0x1f4;return function(_0x4e8c8c){logger[_0x9b6f('0x29')](_0x4e8c8c['stack']);if(_0x4e8c8c['name']){delete _0x4e8c8c[_0x9b6f('0x2a')];}_0x4141b3[_0x9b6f('0x1c')](_0x1d8680)['send'](_0x4e8c8c);};}exports['index']=function(_0x13d3ee,_0x9f3625){var _0x2bfd54={},_0x484ee2={},_0x49a39a={'count':0x0,'rows':[]};var _0x34e56d=_[_0x9b6f('0x2b')](db[_0x9b6f('0x2c')][_0x9b6f('0x2d')],function(_0x350fb0){return{'name':_0x350fb0[_0x9b6f('0x2e')],'type':_0x350fb0['type'][_0x9b6f('0x2f')]};});_0x484ee2[_0x9b6f('0x30')]=_['map'](_0x34e56d,_0x9b6f('0x2a'));_0x484ee2[_0x9b6f('0x31')]=_['keys'](_0x13d3ee[_0x9b6f('0x31')]);_0x484ee2[_0x9b6f('0x32')]=_[_0x9b6f('0x33')](_0x484ee2['model'],_0x484ee2[_0x9b6f('0x31')]);_0x2bfd54[_0x9b6f('0x34')]=_[_0x9b6f('0x33')](_0x484ee2['model'],qs[_0x9b6f('0x35')](_0x13d3ee[_0x9b6f('0x31')][_0x9b6f('0x35')]));_0x2bfd54[_0x9b6f('0x34')]=_0x2bfd54[_0x9b6f('0x34')][_0x9b6f('0x36')]?_0x2bfd54[_0x9b6f('0x34')]:_0x484ee2[_0x9b6f('0x30')];if(!_0x13d3ee[_0x9b6f('0x31')][_0x9b6f('0x37')](_0x9b6f('0x38'))){_0x2bfd54[_0x9b6f('0x1f')]=qs[_0x9b6f('0x1f')](_0x13d3ee[_0x9b6f('0x31')][_0x9b6f('0x1f')]);_0x2bfd54[_0x9b6f('0x1e')]=qs[_0x9b6f('0x1e')](_0x13d3ee[_0x9b6f('0x31')]['offset']);}_0x2bfd54[_0x9b6f('0x39')]=qs[_0x9b6f('0x3a')](_0x13d3ee['query'][_0x9b6f('0x3a')]);_0x2bfd54[_0x9b6f('0x3b')]=qs['filters'](_[_0x9b6f('0x3c')](_0x13d3ee[_0x9b6f('0x31')],_0x484ee2[_0x9b6f('0x32')]),_0x34e56d);if(_0x13d3ee['query'][_0x9b6f('0x3d')]){_0x2bfd54[_0x9b6f('0x3b')]=_[_0x9b6f('0x3e')](_0x2bfd54[_0x9b6f('0x3b')],{'$or':_['map'](_0x34e56d,function(_0x51939d){if(_0x51939d['type']!=='VIRTUAL'){var _0x11b38e={};_0x11b38e[_0x51939d['name']]={'$like':'%'+_0x13d3ee[_0x9b6f('0x31')][_0x9b6f('0x3d')]+'%'};return _0x11b38e;}})});}_0x2bfd54=_[_0x9b6f('0x3e')]({},_0x2bfd54,_0x13d3ee[_0x9b6f('0x3f')]);var _0x57512a={'where':_0x2bfd54[_0x9b6f('0x3b')]};return db[_0x9b6f('0x2c')][_0x9b6f('0x21')](_0x57512a)[_0x9b6f('0x27')](function(_0x53f47e){_0x49a39a[_0x9b6f('0x21')]=_0x53f47e;if(_0x13d3ee[_0x9b6f('0x31')][_0x9b6f('0x40')]){_0x2bfd54[_0x9b6f('0x41')]=[{'all':!![]}];}return db[_0x9b6f('0x2c')][_0x9b6f('0x42')](_0x2bfd54);})[_0x9b6f('0x27')](function(_0x467085){_0x49a39a[_0x9b6f('0x43')]=_0x467085;return _0x49a39a;})[_0x9b6f('0x27')](respondWithFilteredResult(_0x9f3625,_0x2bfd54))[_0x9b6f('0x44')](handleError(_0x9f3625,null));};exports[_0x9b6f('0x45')]=function(_0x150638,_0x34114b){var _0x1b7b06={'raw':!![],'where':{'id':_0x150638[_0x9b6f('0x46')]['id']}},_0x3cbe91={};_0x3cbe91['model']=_['keys'](db['MailTransferReport'][_0x9b6f('0x2d')]);_0x3cbe91['query']=_[_0x9b6f('0x47')](_0x150638[_0x9b6f('0x31')]);_0x3cbe91[_0x9b6f('0x32')]=_[_0x9b6f('0x33')](_0x3cbe91['model'],_0x3cbe91[_0x9b6f('0x31')]);_0x1b7b06['attributes']=_[_0x9b6f('0x33')](_0x3cbe91[_0x9b6f('0x30')],qs[_0x9b6f('0x35')](_0x150638[_0x9b6f('0x31')][_0x9b6f('0x35')]));_0x1b7b06[_0x9b6f('0x34')]=_0x1b7b06['attributes']['length']?_0x1b7b06[_0x9b6f('0x34')]:_0x3cbe91[_0x9b6f('0x30')];if(_0x150638[_0x9b6f('0x31')]['includeAll']){_0x1b7b06[_0x9b6f('0x41')]=[{'all':!![]}];}_0x1b7b06=_[_0x9b6f('0x3e')]({},_0x1b7b06,_0x150638[_0x9b6f('0x3f')]);return db['MailTransferReport'][_0x9b6f('0x48')](_0x1b7b06)[_0x9b6f('0x27')](handleEntityNotFound(_0x34114b,null))[_0x9b6f('0x27')](respondWithResult(_0x34114b,null))[_0x9b6f('0x44')](handleError(_0x34114b,null));};exports['create']=function(_0x13b8fd,_0x4f9f35){return db[_0x9b6f('0x2c')][_0x9b6f('0x49')](_0x13b8fd[_0x9b6f('0x4a')],{})['then'](respondWithResult(_0x4f9f35,0xc9))[_0x9b6f('0x44')](handleError(_0x4f9f35,null));};exports[_0x9b6f('0x26')]=function(_0x2cfffb,_0x48a2be){if(_0x2cfffb['body']['id']){delete _0x2cfffb[_0x9b6f('0x4a')]['id'];}return db[_0x9b6f('0x2c')][_0x9b6f('0x48')]({'where':{'id':_0x2cfffb[_0x9b6f('0x46')]['id']}})[_0x9b6f('0x27')](handleEntityNotFound(_0x48a2be,null))['then'](saveUpdates(_0x2cfffb[_0x9b6f('0x4a')],null))[_0x9b6f('0x27')](respondWithResult(_0x48a2be,null))['catch'](handleError(_0x48a2be,null));};exports[_0x9b6f('0x28')]=function(_0x13f6fe,_0x4c9126){return db[_0x9b6f('0x2c')][_0x9b6f('0x48')]({'where':{'id':_0x13f6fe[_0x9b6f('0x46')]['id']}})[_0x9b6f('0x27')](handleEntityNotFound(_0x4c9126,null))[_0x9b6f('0x27')](removeEntity(_0x4c9126,null))[_0x9b6f('0x44')](handleError(_0x4c9126,null));};exports[_0x9b6f('0x4b')]=function(_0x10d8d1,_0xc6876a){return db['MailTransferReport'][_0x9b6f('0x4b')]()[_0x9b6f('0x27')](respondWithResult(_0xc6876a,null))[_0x9b6f('0x44')](handleError(_0xc6876a,null));};