Built motion from commit (unavailable).|2.5.20
[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 _0x199f=['request-promise','moment','bluebird','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','querystring','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','stack','name','map','MailQueueReport','rawAttributes','fieldName','type','model','keys','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','include','findAll','rows','catch','show','includeAll','find','create','body','params','describe','html-pdf','zip-dir','fast-json-patch'];(function(_0x8fbc8,_0x2b6311){var _0x1b2025=function(_0x33be46){while(--_0x33be46){_0x8fbc8['push'](_0x8fbc8['shift']());}};_0x1b2025(++_0x2b6311);}(_0x199f,0x1bf));var _0xf199=function(_0x9105f4,_0x3bf6f7){_0x9105f4=_0x9105f4-0x0;var _0x57a818=_0x199f[_0x9105f4];return _0x57a818;};'use strict';var pdf=require(_0xf199('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require(_0xf199('0x1'));var jsonpatch=require(_0xf199('0x2'));var rp=require(_0xf199('0x3'));var moment=require(_0xf199('0x4'));var BPromise=require(_0xf199('0x5'));var Mustache=require('mustache');var util=require(_0xf199('0x6'));var path=require('path');var sox=require(_0xf199('0x7'));var csv=require(_0xf199('0x8'));var ejs=require(_0xf199('0x9'));var fs=require('fs');var _=require(_0xf199('0xa'));var squel=require(_0xf199('0xb'));var crypto=require(_0xf199('0xc'));var jsforce=require(_0xf199('0xd'));var deskjs=require('desk.js');var toCsv=require(_0xf199('0x8'));var querystring=require(_0xf199('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xf199('0xf'));var qs=require(_0xf199('0x10'));var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xf199('0x11'));var logger=require(_0xf199('0x12'))(_0xf199('0x13'));var utils=require(_0xf199('0x14'));var config=require(_0xf199('0x15'));var licenseUtil=require(_0xf199('0x16'));var db=require(_0xf199('0x17'))['db'];function respondWithStatusCode(_0xfde111,_0x5132e8){_0x5132e8=_0x5132e8||0xcc;return function(_0x5d472c){if(_0x5d472c){return _0xfde111[_0xf199('0x18')](_0x5132e8);}return _0xfde111[_0xf199('0x19')](_0x5132e8)[_0xf199('0x1a')]();};}function respondWithResult(_0x48221b,_0x24c992){_0x24c992=_0x24c992||0xc8;return function(_0x1b49d0){if(_0x1b49d0){return _0x48221b[_0xf199('0x19')](_0x24c992)[_0xf199('0x1b')](_0x1b49d0);}};}function respondWithFilteredResult(_0x956149,_0x442b79){return function(_0x4d2c78){if(_0x4d2c78){var _0x1ac005=_0x4d2c78[_0xf199('0x1c')],_0x1ae3eb=_0x442b79[_0xf199('0x1d')],_0x18990d=_0x442b79[_0xf199('0x1d')]+_0x442b79[_0xf199('0x1e')],_0x521206;if(_0x18990d>=_0x1ac005){_0x18990d=_0x1ac005;_0x521206=0xc8;}else{_0x521206=0xce;}_0x956149[_0xf199('0x19')](_0x521206);return _0x956149[_0xf199('0x1f')](_0xf199('0x20'),_0x1ae3eb+'-'+_0x18990d+'/'+_0x1ac005)[_0xf199('0x1b')](_0x4d2c78);}return null;};}function patchUpdates(_0x1c89be){return function(_0x52f377){try{jsonpatch[_0xf199('0x21')](_0x52f377,_0x1c89be,!![]);}catch(_0x8e3dc8){return BPromise[_0xf199('0x22')](_0x8e3dc8);}return _0x52f377[_0xf199('0x23')]();};}function saveUpdates(_0x28d2d9,_0x30324d){return function(_0x49028d){if(_0x49028d){return _0x49028d[_0xf199('0x24')](_0x28d2d9)[_0xf199('0x25')](function(_0x263ea7){return _0x263ea7;});}return null;};}function removeEntity(_0x8cae19,_0x3ac6d5){return function(_0x3093b9){if(_0x3093b9){return _0x3093b9[_0xf199('0x26')]()[_0xf199('0x25')](function(){_0x8cae19[_0xf199('0x19')](0xcc)[_0xf199('0x1a')]();});}};}function handleEntityNotFound(_0x417079,_0x58973b){return function(_0x31568c){if(!_0x31568c){_0x417079[_0xf199('0x18')](0x194);}return _0x31568c;};}function handleError(_0x248fbf,_0x24b4d9){_0x24b4d9=_0x24b4d9||0x1f4;return function(_0x3c60fd){logger['error'](_0x3c60fd[_0xf199('0x27')]);if(_0x3c60fd['name']){delete _0x3c60fd[_0xf199('0x28')];}_0x248fbf[_0xf199('0x19')](_0x24b4d9)['send'](_0x3c60fd);};}exports['index']=function(_0x402c8f,_0x5d3cea){var _0x2dd878={},_0x181abc={},_0x3c040f={'count':0x0,'rows':[]};var _0x1109bf=_[_0xf199('0x29')](db[_0xf199('0x2a')][_0xf199('0x2b')],function(_0x2c520f){return{'name':_0x2c520f[_0xf199('0x2c')],'type':_0x2c520f[_0xf199('0x2d')]['key']};});_0x181abc[_0xf199('0x2e')]=_[_0xf199('0x29')](_0x1109bf,_0xf199('0x28'));_0x181abc['query']=_[_0xf199('0x2f')](_0x402c8f[_0xf199('0x30')]);_0x181abc[_0xf199('0x31')]=_[_0xf199('0x32')](_0x181abc[_0xf199('0x2e')],_0x181abc[_0xf199('0x30')]);_0x2dd878[_0xf199('0x33')]=_[_0xf199('0x32')](_0x181abc['model'],qs[_0xf199('0x34')](_0x402c8f[_0xf199('0x30')][_0xf199('0x34')]));_0x2dd878[_0xf199('0x33')]=_0x2dd878[_0xf199('0x33')][_0xf199('0x35')]?_0x2dd878[_0xf199('0x33')]:_0x181abc['model'];if(!_0x402c8f[_0xf199('0x30')][_0xf199('0x36')](_0xf199('0x37'))){_0x2dd878[_0xf199('0x1e')]=qs['limit'](_0x402c8f[_0xf199('0x30')][_0xf199('0x1e')]);_0x2dd878[_0xf199('0x1d')]=qs[_0xf199('0x1d')](_0x402c8f[_0xf199('0x30')][_0xf199('0x1d')]);}_0x2dd878[_0xf199('0x38')]=qs[_0xf199('0x39')](_0x402c8f[_0xf199('0x30')][_0xf199('0x39')]);_0x2dd878[_0xf199('0x3a')]=qs[_0xf199('0x31')](_[_0xf199('0x3b')](_0x402c8f[_0xf199('0x30')],_0x181abc['filters']),_0x1109bf);if(_0x402c8f[_0xf199('0x30')][_0xf199('0x3c')]){_0x2dd878[_0xf199('0x3a')]=_[_0xf199('0x3d')](_0x2dd878[_0xf199('0x3a')],{'$or':_[_0xf199('0x29')](_0x1109bf,function(_0x1d7a47){if(_0x1d7a47[_0xf199('0x2d')]!==_0xf199('0x3e')){var _0x3b20c6={};_0x3b20c6[_0x1d7a47[_0xf199('0x28')]]={'$like':'%'+_0x402c8f['query'][_0xf199('0x3c')]+'%'};return _0x3b20c6;}})});}_0x2dd878=_[_0xf199('0x3d')]({},_0x2dd878,_0x402c8f[_0xf199('0x3f')]);var _0x35093f={'where':_0x2dd878[_0xf199('0x3a')]};return db[_0xf199('0x2a')][_0xf199('0x1c')](_0x35093f)['then'](function(_0x364586){_0x3c040f[_0xf199('0x1c')]=_0x364586;if(_0x402c8f['query']['includeAll']){_0x2dd878[_0xf199('0x40')]=[{'all':!![]}];}return db[_0xf199('0x2a')][_0xf199('0x41')](_0x2dd878);})[_0xf199('0x25')](function(_0x8ea71e){_0x3c040f[_0xf199('0x42')]=_0x8ea71e;return _0x3c040f;})['then'](respondWithFilteredResult(_0x5d3cea,_0x2dd878))[_0xf199('0x43')](handleError(_0x5d3cea,null));};exports[_0xf199('0x44')]=function(_0x14a707,_0x2650bf){var _0x1816af={'raw':!![],'where':{'id':_0x14a707['params']['id']}},_0x1a00f9={};_0x1a00f9[_0xf199('0x2e')]=_[_0xf199('0x2f')](db['MailQueueReport'][_0xf199('0x2b')]);_0x1a00f9[_0xf199('0x30')]=_[_0xf199('0x2f')](_0x14a707[_0xf199('0x30')]);_0x1a00f9[_0xf199('0x31')]=_[_0xf199('0x32')](_0x1a00f9[_0xf199('0x2e')],_0x1a00f9[_0xf199('0x30')]);_0x1816af['attributes']=_[_0xf199('0x32')](_0x1a00f9[_0xf199('0x2e')],qs[_0xf199('0x34')](_0x14a707['query'][_0xf199('0x34')]));_0x1816af[_0xf199('0x33')]=_0x1816af[_0xf199('0x33')][_0xf199('0x35')]?_0x1816af[_0xf199('0x33')]:_0x1a00f9[_0xf199('0x2e')];if(_0x14a707[_0xf199('0x30')][_0xf199('0x45')]){_0x1816af['include']=[{'all':!![]}];}_0x1816af=_[_0xf199('0x3d')]({},_0x1816af,_0x14a707[_0xf199('0x3f')]);return db[_0xf199('0x2a')][_0xf199('0x46')](_0x1816af)[_0xf199('0x25')](handleEntityNotFound(_0x2650bf,null))[_0xf199('0x25')](respondWithResult(_0x2650bf,null))[_0xf199('0x43')](handleError(_0x2650bf,null));};exports[_0xf199('0x47')]=function(_0x579fd0,_0x29a580){return db['MailQueueReport']['create'](_0x579fd0[_0xf199('0x48')],{})['then'](respondWithResult(_0x29a580,0xc9))['catch'](handleError(_0x29a580,null));};exports[_0xf199('0x24')]=function(_0x46dded,_0x27c7e5){if(_0x46dded[_0xf199('0x48')]['id']){delete _0x46dded[_0xf199('0x48')]['id'];}return db[_0xf199('0x2a')][_0xf199('0x46')]({'where':{'id':_0x46dded[_0xf199('0x49')]['id']}})[_0xf199('0x25')](handleEntityNotFound(_0x27c7e5,null))[_0xf199('0x25')](saveUpdates(_0x46dded['body'],null))[_0xf199('0x25')](respondWithResult(_0x27c7e5,null))['catch'](handleError(_0x27c7e5,null));};exports[_0xf199('0x26')]=function(_0x2f5404,_0x2139dc){return db['MailQueueReport']['find']({'where':{'id':_0x2f5404['params']['id']}})['then'](handleEntityNotFound(_0x2139dc,null))[_0xf199('0x25')](removeEntity(_0x2139dc,null))[_0xf199('0x43')](handleError(_0x2139dc,null));};exports[_0xf199('0x4a')]=function(_0x1d9c58,_0x34e075){return db[_0xf199('0x2a')]['describe']()[_0xf199('0x25')](respondWithResult(_0x34e075,null))[_0xf199('0x43')](handleError(_0x34e075,null));};