Built motion from commit 9d7072cc.|2.5.39
[motion2.git] / server / api / mailQueueReport / mailQueueReport.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 _0x32f4=['destroy','then','end','error','stack','name','send','map','MailQueueReport','rawAttributes','fieldName','type','query','keys','filters','attributes','intersection','fields','length','model','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','params','find','create','body','describe','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','util','path','sox','to-csv','ejs','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/environment','../../config/license/util','sendStatus','status','json','offset','undefined','count','set','Content-Range','apply','reject','save','update'];(function(_0x49b207,_0x408ade){var _0x2dc8fa=function(_0x150975){while(--_0x150975){_0x49b207['push'](_0x49b207['shift']());}};_0x2dc8fa(++_0x408ade);}(_0x32f4,0x154));var _0x432f=function(_0x58e7ee,_0x1b0708){_0x58e7ee=_0x58e7ee-0x0;var _0x2a3fce=_0x32f4[_0x58e7ee];return _0x2a3fce;};'use strict';var emlformat=require(_0x432f('0x0'));var rimraf=require(_0x432f('0x1'));var zipdir=require(_0x432f('0x2'));var jsonpatch=require(_0x432f('0x3'));var rp=require('request-promise');var moment=require(_0x432f('0x4'));var BPromise=require(_0x432f('0x5'));var Mustache=require('mustache');var util=require(_0x432f('0x6'));var path=require(_0x432f('0x7'));var sox=require(_0x432f('0x8'));var csv=require(_0x432f('0x9'));var ejs=require(_0x432f('0xa'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require('lodash');var squel=require(_0x432f('0xb'));var crypto=require(_0x432f('0xc'));var jsforce=require('jsforce');var deskjs=require(_0x432f('0xd'));var toCsv=require('to-csv');var querystring=require(_0x432f('0xe'));var Papa=require(_0x432f('0xf'));var Redis=require(_0x432f('0x10'));var authService=require(_0x432f('0x11'));var qs=require(_0x432f('0x12'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x432f('0x13'));var logger=require('../../config/logger')(_0x432f('0x14'));var utils=require('../../config/utils');var config=require(_0x432f('0x15'));var licenseUtil=require(_0x432f('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x457389,_0x29f7d2){_0x29f7d2=_0x29f7d2||0xcc;return function(_0x52e40f){if(_0x52e40f){return _0x457389[_0x432f('0x17')](_0x29f7d2);}return _0x457389[_0x432f('0x18')](_0x29f7d2)['end']();};}function respondWithResult(_0x48a4db,_0x28d9e9){_0x28d9e9=_0x28d9e9||0xc8;return function(_0x44756d){if(_0x44756d){return _0x48a4db[_0x432f('0x18')](_0x28d9e9)[_0x432f('0x19')](_0x44756d);}};}function respondWithFilteredResult(_0x419bfe,_0x4f91c5){return function(_0x175ba7){if(_0x175ba7){var _0x2f0708=typeof _0x4f91c5[_0x432f('0x1a')]===_0x432f('0x1b')&&typeof _0x4f91c5['limit']===_0x432f('0x1b');var _0x30f231=_0x175ba7[_0x432f('0x1c')];var _0x243cf=_0x2f0708?0x0:_0x4f91c5[_0x432f('0x1a')];var _0x129582=_0x2f0708?_0x175ba7['count']:_0x4f91c5[_0x432f('0x1a')]+_0x4f91c5['limit'];var _0x3d545d;if(_0x129582>=_0x30f231){_0x129582=_0x30f231;_0x3d545d=0xc8;}else{_0x3d545d=0xce;}_0x419bfe[_0x432f('0x18')](_0x3d545d);return _0x419bfe[_0x432f('0x1d')](_0x432f('0x1e'),_0x243cf+'-'+_0x129582+'/'+_0x30f231)[_0x432f('0x19')](_0x175ba7);}return null;};}function patchUpdates(_0xf1f5d){return function(_0x10f39b){try{jsonpatch[_0x432f('0x1f')](_0x10f39b,_0xf1f5d,!![]);}catch(_0x693eb3){return BPromise[_0x432f('0x20')](_0x693eb3);}return _0x10f39b[_0x432f('0x21')]();};}function saveUpdates(_0x3446fd,_0x4dd230){return function(_0x5940bd){if(_0x5940bd){return _0x5940bd[_0x432f('0x22')](_0x3446fd)['then'](function(_0x28968e){return _0x28968e;});}return null;};}function removeEntity(_0x5b9c70,_0x37f136){return function(_0x175d1b){if(_0x175d1b){return _0x175d1b[_0x432f('0x23')]()[_0x432f('0x24')](function(){_0x5b9c70[_0x432f('0x18')](0xcc)[_0x432f('0x25')]();});}};}function handleEntityNotFound(_0x59f352,_0x252b3b){return function(_0x33edec){if(!_0x33edec){_0x59f352['sendStatus'](0x194);}return _0x33edec;};}function handleError(_0x2cbde9,_0x3e37ec){_0x3e37ec=_0x3e37ec||0x1f4;return function(_0x2bcbb4){logger[_0x432f('0x26')](_0x2bcbb4[_0x432f('0x27')]);if(_0x2bcbb4[_0x432f('0x28')]){delete _0x2bcbb4[_0x432f('0x28')];}_0x2cbde9['status'](_0x3e37ec)[_0x432f('0x29')](_0x2bcbb4);};}exports['index']=function(_0x1f1fdd,_0x573cc5){var _0x20404d={},_0x5a2c14={},_0x3f768b={'count':0x0,'rows':[]};var _0x489ba6=_[_0x432f('0x2a')](db[_0x432f('0x2b')][_0x432f('0x2c')],function(_0x59c1ab){return{'name':_0x59c1ab[_0x432f('0x2d')],'type':_0x59c1ab[_0x432f('0x2e')]['key']};});_0x5a2c14['model']=_[_0x432f('0x2a')](_0x489ba6,_0x432f('0x28'));_0x5a2c14[_0x432f('0x2f')]=_[_0x432f('0x30')](_0x1f1fdd[_0x432f('0x2f')]);_0x5a2c14[_0x432f('0x31')]=_['intersection'](_0x5a2c14['model'],_0x5a2c14[_0x432f('0x2f')]);_0x20404d[_0x432f('0x32')]=_[_0x432f('0x33')](_0x5a2c14['model'],qs[_0x432f('0x34')](_0x1f1fdd[_0x432f('0x2f')][_0x432f('0x34')]));_0x20404d[_0x432f('0x32')]=_0x20404d[_0x432f('0x32')][_0x432f('0x35')]?_0x20404d[_0x432f('0x32')]:_0x5a2c14[_0x432f('0x36')];if(!_0x1f1fdd['query']['hasOwnProperty'](_0x432f('0x37'))){_0x20404d[_0x432f('0x38')]=qs['limit'](_0x1f1fdd['query']['limit']);_0x20404d[_0x432f('0x1a')]=qs[_0x432f('0x1a')](_0x1f1fdd['query'][_0x432f('0x1a')]);}_0x20404d[_0x432f('0x39')]=qs[_0x432f('0x3a')](_0x1f1fdd['query'][_0x432f('0x3a')]);_0x20404d[_0x432f('0x3b')]=qs['filters'](_[_0x432f('0x3c')](_0x1f1fdd[_0x432f('0x2f')],_0x5a2c14['filters']),_0x489ba6);if(_0x1f1fdd[_0x432f('0x2f')][_0x432f('0x3d')]){_0x20404d[_0x432f('0x3b')]=_[_0x432f('0x3e')](_0x20404d[_0x432f('0x3b')],{'$or':_[_0x432f('0x2a')](_0x489ba6,function(_0xbef36e){if(_0xbef36e[_0x432f('0x2e')]!==_0x432f('0x3f')){var _0x2545b7={};_0x2545b7[_0xbef36e[_0x432f('0x28')]]={'$like':'%'+_0x1f1fdd['query'][_0x432f('0x3d')]+'%'};return _0x2545b7;}})});}_0x20404d=_['merge']({},_0x20404d,_0x1f1fdd[_0x432f('0x40')]);var _0x3e8a0a={'where':_0x20404d['where']};return db[_0x432f('0x2b')]['count'](_0x3e8a0a)[_0x432f('0x24')](function(_0x3aca68){_0x3f768b['count']=_0x3aca68;if(_0x1f1fdd['query'][_0x432f('0x41')]){_0x20404d[_0x432f('0x42')]=[{'all':!![]}];}return db[_0x432f('0x2b')][_0x432f('0x43')](_0x20404d);})[_0x432f('0x24')](function(_0x513a57){_0x3f768b['rows']=_0x513a57;return _0x3f768b;})['then'](respondWithFilteredResult(_0x573cc5,_0x20404d))[_0x432f('0x44')](handleError(_0x573cc5,null));};exports[_0x432f('0x45')]=function(_0x55d64c,_0x1f58af){var _0x841572={'raw':!![],'where':{'id':_0x55d64c[_0x432f('0x46')]['id']}},_0x41c90c={};_0x41c90c[_0x432f('0x36')]=_[_0x432f('0x30')](db[_0x432f('0x2b')][_0x432f('0x2c')]);_0x41c90c[_0x432f('0x2f')]=_['keys'](_0x55d64c[_0x432f('0x2f')]);_0x41c90c[_0x432f('0x31')]=_['intersection'](_0x41c90c[_0x432f('0x36')],_0x41c90c[_0x432f('0x2f')]);_0x841572[_0x432f('0x32')]=_[_0x432f('0x33')](_0x41c90c[_0x432f('0x36')],qs[_0x432f('0x34')](_0x55d64c[_0x432f('0x2f')][_0x432f('0x34')]));_0x841572[_0x432f('0x32')]=_0x841572[_0x432f('0x32')][_0x432f('0x35')]?_0x841572[_0x432f('0x32')]:_0x41c90c[_0x432f('0x36')];if(_0x55d64c[_0x432f('0x2f')]['includeAll']){_0x841572['include']=[{'all':!![]}];}_0x841572=_[_0x432f('0x3e')]({},_0x841572,_0x55d64c[_0x432f('0x40')]);return db[_0x432f('0x2b')][_0x432f('0x47')](_0x841572)[_0x432f('0x24')](handleEntityNotFound(_0x1f58af,null))['then'](respondWithResult(_0x1f58af,null))[_0x432f('0x44')](handleError(_0x1f58af,null));};exports[_0x432f('0x48')]=function(_0x46c5ee,_0x2f88d6){return db[_0x432f('0x2b')][_0x432f('0x48')](_0x46c5ee[_0x432f('0x49')],{})['then'](respondWithResult(_0x2f88d6,0xc9))[_0x432f('0x44')](handleError(_0x2f88d6,null));};exports[_0x432f('0x22')]=function(_0x359853,_0x547bd0){if(_0x359853[_0x432f('0x49')]['id']){delete _0x359853[_0x432f('0x49')]['id'];}return db['MailQueueReport']['find']({'where':{'id':_0x359853[_0x432f('0x46')]['id']}})[_0x432f('0x24')](handleEntityNotFound(_0x547bd0,null))['then'](saveUpdates(_0x359853['body'],null))[_0x432f('0x24')](respondWithResult(_0x547bd0,null))['catch'](handleError(_0x547bd0,null));};exports[_0x432f('0x23')]=function(_0x66b80e,_0x5df9b3){return db[_0x432f('0x2b')]['find']({'where':{'id':_0x66b80e[_0x432f('0x46')]['id']}})[_0x432f('0x24')](handleEntityNotFound(_0x5df9b3,null))[_0x432f('0x24')](removeEntity(_0x5df9b3,null))[_0x432f('0x44')](handleError(_0x5df9b3,null));};exports[_0x432f('0x4a')]=function(_0x2a4d36,_0x56f526){return db[_0x432f('0x2b')]['describe']()[_0x432f('0x24')](respondWithResult(_0x56f526,null))[_0x432f('0x44')](handleError(_0x56f526,null));};