Built motion from commit da617fac.|2.6.6
[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 _0xf423=['util','path','sox','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/license/util','status','end','offset','undefined','limit','count','set','reject','save','update','destroy','then','sendStatus','stack','name','send','index','map','rawAttributes','fieldName','type','key','keys','query','filters','model','attributes','intersection','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','options','includeAll','findAll','rows','catch','show','params','MailTransferReport','include','create','body','find','describe','eml-format','rimraf','zip-dir','request-promise','bluebird','mustache'];(function(_0x34f701,_0x37e407){var _0x3e2429=function(_0x20c0c3){while(--_0x20c0c3){_0x34f701['push'](_0x34f701['shift']());}};_0x3e2429(++_0x37e407);}(_0xf423,0xde));var _0x3f42=function(_0x3ca52c,_0x8420f){_0x3ca52c=_0x3ca52c-0x0;var _0x2fb640=_0xf423[_0x3ca52c];return _0x2fb640;};'use strict';var emlformat=require(_0x3f42('0x0'));var rimraf=require(_0x3f42('0x1'));var zipdir=require(_0x3f42('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x3f42('0x3'));var moment=require('moment');var BPromise=require(_0x3f42('0x4'));var Mustache=require(_0x3f42('0x5'));var util=require(_0x3f42('0x6'));var path=require(_0x3f42('0x7'));var sox=require(_0x3f42('0x8'));var csv=require('to-csv');var ejs=require(_0x3f42('0x9'));var fs=require('fs');var fs_extra=require(_0x3f42('0xa'));var _=require(_0x3f42('0xb'));var squel=require(_0x3f42('0xc'));var crypto=require(_0x3f42('0xd'));var jsforce=require(_0x3f42('0xe'));var deskjs=require(_0x3f42('0xf'));var toCsv=require(_0x3f42('0x10'));var querystring=require(_0x3f42('0x11'));var Papa=require(_0x3f42('0x12'));var Redis=require(_0x3f42('0x13'));var authService=require(_0x3f42('0x14'));var qs=require(_0x3f42('0x15'));var as=require(_0x3f42('0x16'));var hardwareService=require(_0x3f42('0x17'));var logger=require(_0x3f42('0x18'))('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x3f42('0x19'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x3cecf2,_0x12a1df){_0x12a1df=_0x12a1df||0xcc;return function(_0x2b1bf2){if(_0x2b1bf2){return _0x3cecf2['sendStatus'](_0x12a1df);}return _0x3cecf2[_0x3f42('0x1a')](_0x12a1df)[_0x3f42('0x1b')]();};}function respondWithResult(_0x551f88,_0x54851a){_0x54851a=_0x54851a||0xc8;return function(_0x244c5f){if(_0x244c5f){return _0x551f88[_0x3f42('0x1a')](_0x54851a)['json'](_0x244c5f);}};}function respondWithFilteredResult(_0x4f6866,_0x2aed23){return function(_0xdcb9c1){if(_0xdcb9c1){var _0x2a4360=typeof _0x2aed23[_0x3f42('0x1c')]===_0x3f42('0x1d')&&typeof _0x2aed23[_0x3f42('0x1e')]==='undefined';var _0xbc1d84=_0xdcb9c1['count'];var _0x564140=_0x2a4360?0x0:_0x2aed23[_0x3f42('0x1c')];var _0x16ef8b=_0x2a4360?_0xdcb9c1[_0x3f42('0x1f')]:_0x2aed23[_0x3f42('0x1c')]+_0x2aed23['limit'];var _0x248f5a;if(_0x16ef8b>=_0xbc1d84){_0x16ef8b=_0xbc1d84;_0x248f5a=0xc8;}else{_0x248f5a=0xce;}_0x4f6866[_0x3f42('0x1a')](_0x248f5a);return _0x4f6866[_0x3f42('0x20')]('Content-Range',_0x564140+'-'+_0x16ef8b+'/'+_0xbc1d84)['json'](_0xdcb9c1);}return null;};}function patchUpdates(_0x28fd1c){return function(_0x2ae210){try{jsonpatch['apply'](_0x2ae210,_0x28fd1c,!![]);}catch(_0x5a98c2){return BPromise[_0x3f42('0x21')](_0x5a98c2);}return _0x2ae210[_0x3f42('0x22')]();};}function saveUpdates(_0x2d360c,_0x5e7b4e){return function(_0x245f10){if(_0x245f10){return _0x245f10[_0x3f42('0x23')](_0x2d360c)['then'](function(_0x283359){return _0x283359;});}return null;};}function removeEntity(_0x3d318c,_0x55faf5){return function(_0x59ffad){if(_0x59ffad){return _0x59ffad[_0x3f42('0x24')]()[_0x3f42('0x25')](function(){_0x3d318c[_0x3f42('0x1a')](0xcc)[_0x3f42('0x1b')]();});}};}function handleEntityNotFound(_0x3b36b8,_0x334d35){return function(_0x43d6dc){if(!_0x43d6dc){_0x3b36b8[_0x3f42('0x26')](0x194);}return _0x43d6dc;};}function handleError(_0x624baf,_0x26dafd){_0x26dafd=_0x26dafd||0x1f4;return function(_0x2258bc){logger['error'](_0x2258bc[_0x3f42('0x27')]);if(_0x2258bc[_0x3f42('0x28')]){delete _0x2258bc[_0x3f42('0x28')];}_0x624baf[_0x3f42('0x1a')](_0x26dafd)[_0x3f42('0x29')](_0x2258bc);};}exports[_0x3f42('0x2a')]=function(_0x3cf9f6,_0x3c68eb){var _0xe0e433={},_0x20e039={},_0x4a0514={'count':0x0,'rows':[]};var _0x34482a=_[_0x3f42('0x2b')](db['MailTransferReport'][_0x3f42('0x2c')],function(_0x202f82){return{'name':_0x202f82[_0x3f42('0x2d')],'type':_0x202f82[_0x3f42('0x2e')][_0x3f42('0x2f')]};});_0x20e039['model']=_[_0x3f42('0x2b')](_0x34482a,_0x3f42('0x28'));_0x20e039['query']=_[_0x3f42('0x30')](_0x3cf9f6[_0x3f42('0x31')]);_0x20e039[_0x3f42('0x32')]=_['intersection'](_0x20e039[_0x3f42('0x33')],_0x20e039[_0x3f42('0x31')]);_0xe0e433[_0x3f42('0x34')]=_[_0x3f42('0x35')](_0x20e039[_0x3f42('0x33')],qs[_0x3f42('0x36')](_0x3cf9f6[_0x3f42('0x31')][_0x3f42('0x36')]));_0xe0e433[_0x3f42('0x34')]=_0xe0e433['attributes'][_0x3f42('0x37')]?_0xe0e433['attributes']:_0x20e039[_0x3f42('0x33')];if(!_0x3cf9f6['query'][_0x3f42('0x38')]('nolimit')){_0xe0e433[_0x3f42('0x1e')]=qs[_0x3f42('0x1e')](_0x3cf9f6[_0x3f42('0x31')][_0x3f42('0x1e')]);_0xe0e433[_0x3f42('0x1c')]=qs[_0x3f42('0x1c')](_0x3cf9f6[_0x3f42('0x31')]['offset']);}_0xe0e433[_0x3f42('0x39')]=qs[_0x3f42('0x3a')](_0x3cf9f6[_0x3f42('0x31')][_0x3f42('0x3a')]);_0xe0e433[_0x3f42('0x3b')]=qs[_0x3f42('0x32')](_[_0x3f42('0x3c')](_0x3cf9f6[_0x3f42('0x31')],_0x20e039[_0x3f42('0x32')]),_0x34482a);if(_0x3cf9f6['query'][_0x3f42('0x3d')]){_0xe0e433[_0x3f42('0x3b')]=_[_0x3f42('0x3e')](_0xe0e433[_0x3f42('0x3b')],{'$or':_[_0x3f42('0x2b')](_0x34482a,function(_0x5c8156){if(_0x5c8156[_0x3f42('0x2e')]!=='VIRTUAL'){var _0x332c71={};_0x332c71[_0x5c8156[_0x3f42('0x28')]]={'$like':'%'+_0x3cf9f6[_0x3f42('0x31')][_0x3f42('0x3d')]+'%'};return _0x332c71;}})});}_0xe0e433=_[_0x3f42('0x3e')]({},_0xe0e433,_0x3cf9f6[_0x3f42('0x3f')]);var _0x1bac20={'where':_0xe0e433[_0x3f42('0x3b')]};return db['MailTransferReport'][_0x3f42('0x1f')](_0x1bac20)[_0x3f42('0x25')](function(_0x5a5f76){_0x4a0514['count']=_0x5a5f76;if(_0x3cf9f6[_0x3f42('0x31')][_0x3f42('0x40')]){_0xe0e433['include']=[{'all':!![]}];}return db['MailTransferReport'][_0x3f42('0x41')](_0xe0e433);})[_0x3f42('0x25')](function(_0xe5f9c4){_0x4a0514[_0x3f42('0x42')]=_0xe5f9c4;return _0x4a0514;})[_0x3f42('0x25')](respondWithFilteredResult(_0x3c68eb,_0xe0e433))[_0x3f42('0x43')](handleError(_0x3c68eb,null));};exports[_0x3f42('0x44')]=function(_0x8bea70,_0x3a6b21){var _0x10cfc8={'raw':!![],'where':{'id':_0x8bea70[_0x3f42('0x45')]['id']}},_0x4ac1d5={};_0x4ac1d5[_0x3f42('0x33')]=_['keys'](db[_0x3f42('0x46')][_0x3f42('0x2c')]);_0x4ac1d5[_0x3f42('0x31')]=_[_0x3f42('0x30')](_0x8bea70['query']);_0x4ac1d5['filters']=_[_0x3f42('0x35')](_0x4ac1d5[_0x3f42('0x33')],_0x4ac1d5[_0x3f42('0x31')]);_0x10cfc8[_0x3f42('0x34')]=_['intersection'](_0x4ac1d5[_0x3f42('0x33')],qs[_0x3f42('0x36')](_0x8bea70[_0x3f42('0x31')][_0x3f42('0x36')]));_0x10cfc8[_0x3f42('0x34')]=_0x10cfc8[_0x3f42('0x34')][_0x3f42('0x37')]?_0x10cfc8[_0x3f42('0x34')]:_0x4ac1d5[_0x3f42('0x33')];if(_0x8bea70[_0x3f42('0x31')]['includeAll']){_0x10cfc8[_0x3f42('0x47')]=[{'all':!![]}];}_0x10cfc8=_[_0x3f42('0x3e')]({},_0x10cfc8,_0x8bea70[_0x3f42('0x3f')]);return db[_0x3f42('0x46')]['find'](_0x10cfc8)[_0x3f42('0x25')](handleEntityNotFound(_0x3a6b21,null))[_0x3f42('0x25')](respondWithResult(_0x3a6b21,null))[_0x3f42('0x43')](handleError(_0x3a6b21,null));};exports['create']=function(_0x1b583b,_0x16bc6c){return db['MailTransferReport'][_0x3f42('0x48')](_0x1b583b[_0x3f42('0x49')],{})[_0x3f42('0x25')](respondWithResult(_0x16bc6c,0xc9))[_0x3f42('0x43')](handleError(_0x16bc6c,null));};exports['update']=function(_0x234be1,_0xf48dc7){if(_0x234be1[_0x3f42('0x49')]['id']){delete _0x234be1['body']['id'];}return db[_0x3f42('0x46')]['find']({'where':{'id':_0x234be1[_0x3f42('0x45')]['id']}})[_0x3f42('0x25')](handleEntityNotFound(_0xf48dc7,null))['then'](saveUpdates(_0x234be1[_0x3f42('0x49')],null))[_0x3f42('0x25')](respondWithResult(_0xf48dc7,null))['catch'](handleError(_0xf48dc7,null));};exports[_0x3f42('0x24')]=function(_0x58440b,_0x459fd4){return db[_0x3f42('0x46')][_0x3f42('0x4a')]({'where':{'id':_0x58440b[_0x3f42('0x45')]['id']}})['then'](handleEntityNotFound(_0x459fd4,null))[_0x3f42('0x25')](removeEntity(_0x459fd4,null))['catch'](handleError(_0x459fd4,null));};exports['describe']=function(_0x1bc6f0,_0x3f1245){return db[_0x3f42('0x46')][_0x3f42('0x4b')]()[_0x3f42('0x25')](respondWithResult(_0x3f1245,null))[_0x3f42('0x43')](handleError(_0x3f1245,null));};