8bb6ff6cabcabb20c618819980bfa5d9b0bfa20d
[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 _0x955f=['reject','update','then','destroy','error','name','send','index','map','MailQueueReport','rawAttributes','fieldName','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','nolimit','order','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','create','body','find','describe','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','path','to-csv','ejs','fs-extra','squel','crypto','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','undefined','limit','offset','count','set','Content-Range','apply'];(function(_0x1df957,_0x3f01ec){var _0x1e7784=function(_0x377f9f){while(--_0x377f9f){_0x1df957['push'](_0x1df957['shift']());}};_0x1e7784(++_0x3f01ec);}(_0x955f,0x1eb));var _0xf955=function(_0x13fad1,_0x3a9259){_0x13fad1=_0x13fad1-0x0;var _0x4a7f39=_0x955f[_0x13fad1];return _0x4a7f39;};'use strict';var emlformat=require(_0xf955('0x0'));var rimraf=require(_0xf955('0x1'));var zipdir=require(_0xf955('0x2'));var jsonpatch=require(_0xf955('0x3'));var rp=require(_0xf955('0x4'));var moment=require('moment');var BPromise=require(_0xf955('0x5'));var Mustache=require('mustache');var util=require('util');var path=require(_0xf955('0x6'));var sox=require('sox');var csv=require(_0xf955('0x7'));var ejs=require(_0xf955('0x8'));var fs=require('fs');var fs_extra=require(_0xf955('0x9'));var _=require('lodash');var squel=require(_0xf955('0xa'));var crypto=require(_0xf955('0xb'));var jsforce=require('jsforce');var deskjs=require(_0xf955('0xc'));var toCsv=require(_0xf955('0x7'));var querystring=require(_0xf955('0xd'));var Papa=require(_0xf955('0xe'));var Redis=require(_0xf955('0xf'));var authService=require(_0xf955('0x10'));var qs=require(_0xf955('0x11'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf955('0x12'));var logger=require('../../config/logger')(_0xf955('0x13'));var utils=require(_0xf955('0x14'));var config=require(_0xf955('0x15'));var licenseUtil=require('../../config/license/util');var db=require(_0xf955('0x16'))['db'];function respondWithStatusCode(_0x542347,_0x23e0c6){_0x23e0c6=_0x23e0c6||0xcc;return function(_0x50d9a9){if(_0x50d9a9){return _0x542347[_0xf955('0x17')](_0x23e0c6);}return _0x542347[_0xf955('0x18')](_0x23e0c6)[_0xf955('0x19')]();};}function respondWithResult(_0x109bc5,_0x2080c4){_0x2080c4=_0x2080c4||0xc8;return function(_0x341b8c){if(_0x341b8c){return _0x109bc5[_0xf955('0x18')](_0x2080c4)[_0xf955('0x1a')](_0x341b8c);}};}function respondWithFilteredResult(_0x3c6af7,_0x24e75c){return function(_0x5350e4){if(_0x5350e4){var _0xc29b35=typeof _0x24e75c['offset']===_0xf955('0x1b')&&typeof _0x24e75c[_0xf955('0x1c')]===_0xf955('0x1b');var _0x15c07c=_0x5350e4['count'];var _0x5ac6cb=_0xc29b35?0x0:_0x24e75c[_0xf955('0x1d')];var _0xe6de5c=_0xc29b35?_0x5350e4[_0xf955('0x1e')]:_0x24e75c['offset']+_0x24e75c[_0xf955('0x1c')];var _0x3576fa;if(_0xe6de5c>=_0x15c07c){_0xe6de5c=_0x15c07c;_0x3576fa=0xc8;}else{_0x3576fa=0xce;}_0x3c6af7[_0xf955('0x18')](_0x3576fa);return _0x3c6af7[_0xf955('0x1f')](_0xf955('0x20'),_0x5ac6cb+'-'+_0xe6de5c+'/'+_0x15c07c)['json'](_0x5350e4);}return null;};}function patchUpdates(_0x17d86a){return function(_0x3dbbe8){try{jsonpatch[_0xf955('0x21')](_0x3dbbe8,_0x17d86a,!![]);}catch(_0x488d04){return BPromise[_0xf955('0x22')](_0x488d04);}return _0x3dbbe8['save']();};}function saveUpdates(_0x21ae24,_0x43b078){return function(_0x37143d){if(_0x37143d){return _0x37143d[_0xf955('0x23')](_0x21ae24)[_0xf955('0x24')](function(_0x565641){return _0x565641;});}return null;};}function removeEntity(_0x25f4f2,_0x5fab1c){return function(_0x3585c7){if(_0x3585c7){return _0x3585c7[_0xf955('0x25')]()[_0xf955('0x24')](function(){_0x25f4f2[_0xf955('0x18')](0xcc)[_0xf955('0x19')]();});}};}function handleEntityNotFound(_0x552cf3,_0x18f435){return function(_0x1acf33){if(!_0x1acf33){_0x552cf3[_0xf955('0x17')](0x194);}return _0x1acf33;};}function handleError(_0x406632,_0x2dcd55){_0x2dcd55=_0x2dcd55||0x1f4;return function(_0x13a86d){logger[_0xf955('0x26')](_0x13a86d['stack']);if(_0x13a86d[_0xf955('0x27')]){delete _0x13a86d[_0xf955('0x27')];}_0x406632[_0xf955('0x18')](_0x2dcd55)[_0xf955('0x28')](_0x13a86d);};}exports[_0xf955('0x29')]=function(_0x264f6d,_0x4d4af0){var _0x2232a7={},_0x1e5d37={},_0x4ec3e8={'count':0x0,'rows':[]};var _0x256df5=_[_0xf955('0x2a')](db[_0xf955('0x2b')][_0xf955('0x2c')],function(_0x59bfb5){return{'name':_0x59bfb5[_0xf955('0x2d')],'type':_0x59bfb5['type'][_0xf955('0x2e')]};});_0x1e5d37[_0xf955('0x2f')]=_[_0xf955('0x2a')](_0x256df5,_0xf955('0x27'));_0x1e5d37[_0xf955('0x30')]=_[_0xf955('0x31')](_0x264f6d[_0xf955('0x30')]);_0x1e5d37[_0xf955('0x32')]=_['intersection'](_0x1e5d37[_0xf955('0x2f')],_0x1e5d37[_0xf955('0x30')]);_0x2232a7[_0xf955('0x33')]=_[_0xf955('0x34')](_0x1e5d37['model'],qs[_0xf955('0x35')](_0x264f6d[_0xf955('0x30')][_0xf955('0x35')]));_0x2232a7[_0xf955('0x33')]=_0x2232a7[_0xf955('0x33')]['length']?_0x2232a7['attributes']:_0x1e5d37['model'];if(!_0x264f6d[_0xf955('0x30')][_0xf955('0x36')](_0xf955('0x37'))){_0x2232a7[_0xf955('0x1c')]=qs[_0xf955('0x1c')](_0x264f6d[_0xf955('0x30')]['limit']);_0x2232a7[_0xf955('0x1d')]=qs['offset'](_0x264f6d[_0xf955('0x30')][_0xf955('0x1d')]);}_0x2232a7[_0xf955('0x38')]=qs['sort'](_0x264f6d[_0xf955('0x30')]['sort']);_0x2232a7[_0xf955('0x39')]=qs[_0xf955('0x32')](_[_0xf955('0x3a')](_0x264f6d[_0xf955('0x30')],_0x1e5d37['filters']),_0x256df5);if(_0x264f6d[_0xf955('0x30')][_0xf955('0x3b')]){_0x2232a7['where']=_[_0xf955('0x3c')](_0x2232a7[_0xf955('0x39')],{'$or':_[_0xf955('0x2a')](_0x256df5,function(_0x547ed9){if(_0x547ed9[_0xf955('0x3d')]!==_0xf955('0x3e')){var _0x11b7e2={};_0x11b7e2[_0x547ed9['name']]={'$like':'%'+_0x264f6d[_0xf955('0x30')][_0xf955('0x3b')]+'%'};return _0x11b7e2;}})});}_0x2232a7=_[_0xf955('0x3c')]({},_0x2232a7,_0x264f6d[_0xf955('0x3f')]);var _0x2bfbe4={'where':_0x2232a7[_0xf955('0x39')]};return db[_0xf955('0x2b')][_0xf955('0x1e')](_0x2bfbe4)['then'](function(_0x8fa41b){_0x4ec3e8[_0xf955('0x1e')]=_0x8fa41b;if(_0x264f6d[_0xf955('0x30')][_0xf955('0x40')]){_0x2232a7[_0xf955('0x41')]=[{'all':!![]}];}return db[_0xf955('0x2b')][_0xf955('0x42')](_0x2232a7);})[_0xf955('0x24')](function(_0x47651b){_0x4ec3e8[_0xf955('0x43')]=_0x47651b;return _0x4ec3e8;})[_0xf955('0x24')](respondWithFilteredResult(_0x4d4af0,_0x2232a7))[_0xf955('0x44')](handleError(_0x4d4af0,null));};exports[_0xf955('0x45')]=function(_0x159ae3,_0x3557b5){var _0x248f60={'raw':!![],'where':{'id':_0x159ae3[_0xf955('0x46')]['id']}},_0x356ec2={};_0x356ec2[_0xf955('0x2f')]=_['keys'](db[_0xf955('0x2b')][_0xf955('0x2c')]);_0x356ec2[_0xf955('0x30')]=_['keys'](_0x159ae3[_0xf955('0x30')]);_0x356ec2['filters']=_[_0xf955('0x34')](_0x356ec2['model'],_0x356ec2[_0xf955('0x30')]);_0x248f60[_0xf955('0x33')]=_[_0xf955('0x34')](_0x356ec2[_0xf955('0x2f')],qs['fields'](_0x159ae3[_0xf955('0x30')][_0xf955('0x35')]));_0x248f60[_0xf955('0x33')]=_0x248f60['attributes']['length']?_0x248f60[_0xf955('0x33')]:_0x356ec2[_0xf955('0x2f')];if(_0x159ae3[_0xf955('0x30')][_0xf955('0x40')]){_0x248f60['include']=[{'all':!![]}];}_0x248f60=_[_0xf955('0x3c')]({},_0x248f60,_0x159ae3[_0xf955('0x3f')]);return db[_0xf955('0x2b')]['find'](_0x248f60)[_0xf955('0x24')](handleEntityNotFound(_0x3557b5,null))['then'](respondWithResult(_0x3557b5,null))[_0xf955('0x44')](handleError(_0x3557b5,null));};exports[_0xf955('0x47')]=function(_0x2c867f,_0x4dd592){return db[_0xf955('0x2b')][_0xf955('0x47')](_0x2c867f[_0xf955('0x48')],{})[_0xf955('0x24')](respondWithResult(_0x4dd592,0xc9))['catch'](handleError(_0x4dd592,null));};exports[_0xf955('0x23')]=function(_0x4ff0f1,_0x1c6d76){if(_0x4ff0f1[_0xf955('0x48')]['id']){delete _0x4ff0f1[_0xf955('0x48')]['id'];}return db['MailQueueReport'][_0xf955('0x49')]({'where':{'id':_0x4ff0f1['params']['id']}})[_0xf955('0x24')](handleEntityNotFound(_0x1c6d76,null))['then'](saveUpdates(_0x4ff0f1[_0xf955('0x48')],null))['then'](respondWithResult(_0x1c6d76,null))['catch'](handleError(_0x1c6d76,null));};exports[_0xf955('0x25')]=function(_0x45c7fe,_0x4961cc){return db[_0xf955('0x2b')]['find']({'where':{'id':_0x45c7fe['params']['id']}})['then'](handleEntityNotFound(_0x4961cc,null))['then'](removeEntity(_0x4961cc,null))[_0xf955('0x44')](handleError(_0x4961cc,null));};exports[_0xf955('0x4a')]=function(_0x4a7aee,_0x4c4b6d){return db[_0xf955('0x2b')][_0xf955('0x4a')]()[_0xf955('0x24')](respondWithResult(_0x4c4b6d,null))[_0xf955('0x44')](handleError(_0x4c4b6d,null));};