1eccf16d6b4691ac05be76780212316969d11de3
[motion2.git] / server / api / faxQueueReport / faxQueueReport.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 _0xf960=['../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','set','apply','update','then','destroy','error','stack','name','send','map','FaxQueueReport','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','catch','show','rawAttributes','length','options','find','create','body','params','describe','rimraf','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs'];(function(_0x2ce709,_0x41ab1e){var _0x908e80=function(_0x1a6675){while(--_0x1a6675){_0x2ce709['push'](_0x2ce709['shift']());}};_0x908e80(++_0x41ab1e);}(_0xf960,0x7e));var _0x0f96=function(_0x1ae4a9,_0x4c0ed9){_0x1ae4a9=_0x1ae4a9-0x0;var _0x54d0b0=_0xf960[_0x1ae4a9];return _0x54d0b0;};'use strict';var pdf=require('html-pdf');var emlformat=require('eml-format');var rimraf=require(_0x0f96('0x0'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0f96('0x1'));var rp=require('request-promise');var moment=require(_0x0f96('0x2'));var BPromise=require(_0x0f96('0x3'));var Mustache=require(_0x0f96('0x4'));var util=require(_0x0f96('0x5'));var path=require(_0x0f96('0x6'));var sox=require(_0x0f96('0x7'));var csv=require(_0x0f96('0x8'));var ejs=require(_0x0f96('0x9'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0x0f96('0xa'));var deskjs=require(_0x0f96('0xb'));var toCsv=require('to-csv');var querystring=require(_0x0f96('0xc'));var Papa=require(_0x0f96('0xd'));var Redis=require(_0x0f96('0xe'));var authService=require('../../components/auth/service');var qs=require(_0x0f96('0xf'));var as=require(_0x0f96('0x10'));var hardwareService=require(_0x0f96('0x11'));var logger=require(_0x0f96('0x12'))('api');var utils=require(_0x0f96('0x13'));var config=require(_0x0f96('0x14'));var licenseUtil=require(_0x0f96('0x15'));var db=require(_0x0f96('0x16'))['db'];function respondWithStatusCode(_0x4d7d5f,_0x56226a){_0x56226a=_0x56226a||0xcc;return function(_0x1b92c1){if(_0x1b92c1){return _0x4d7d5f[_0x0f96('0x17')](_0x56226a);}return _0x4d7d5f[_0x0f96('0x18')](_0x56226a)[_0x0f96('0x19')]();};}function respondWithResult(_0x46e9eb,_0x584b24){_0x584b24=_0x584b24||0xc8;return function(_0x598862){if(_0x598862){return _0x46e9eb[_0x0f96('0x18')](_0x584b24)[_0x0f96('0x1a')](_0x598862);}};}function respondWithFilteredResult(_0x2aff9f,_0x45d0c2){return function(_0x20dacf){if(_0x20dacf){var _0x1669cb=_0x20dacf[_0x0f96('0x1b')],_0x166963=_0x45d0c2[_0x0f96('0x1c')],_0xb27f8b=_0x45d0c2[_0x0f96('0x1c')]+_0x45d0c2['limit'],_0x28bc38;if(_0xb27f8b>=_0x1669cb){_0xb27f8b=_0x1669cb;_0x28bc38=0xc8;}else{_0x28bc38=0xce;}_0x2aff9f['status'](_0x28bc38);return _0x2aff9f[_0x0f96('0x1d')]('Content-Range',_0x166963+'-'+_0xb27f8b+'/'+_0x1669cb)[_0x0f96('0x1a')](_0x20dacf);}return null;};}function patchUpdates(_0x25219c){return function(_0x4ce889){try{jsonpatch[_0x0f96('0x1e')](_0x4ce889,_0x25219c,!![]);}catch(_0x169818){return BPromise['reject'](_0x169818);}return _0x4ce889['save']();};}function saveUpdates(_0x5a284d,_0x33bcea){return function(_0x4be76b){if(_0x4be76b){return _0x4be76b[_0x0f96('0x1f')](_0x5a284d)[_0x0f96('0x20')](function(_0x26279e){return _0x26279e;});}return null;};}function removeEntity(_0x48dbf6,_0x4a7af3){return function(_0x245d11){if(_0x245d11){return _0x245d11[_0x0f96('0x21')]()[_0x0f96('0x20')](function(){_0x48dbf6[_0x0f96('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0xd91cd7,_0x42dba7){return function(_0x2fca2f){if(!_0x2fca2f){_0xd91cd7[_0x0f96('0x17')](0x194);}return _0x2fca2f;};}function handleError(_0x562913,_0x404366){_0x404366=_0x404366||0x1f4;return function(_0x5187e4){logger[_0x0f96('0x22')](_0x5187e4[_0x0f96('0x23')]);if(_0x5187e4[_0x0f96('0x24')]){delete _0x5187e4[_0x0f96('0x24')];}_0x562913[_0x0f96('0x18')](_0x404366)[_0x0f96('0x25')](_0x5187e4);};}exports['index']=function(_0x259fdf,_0xa5947e){var _0x3055ae={},_0x258811={},_0x51441e={'count':0x0,'rows':[]};var _0x3a1f27=_[_0x0f96('0x26')](db[_0x0f96('0x27')]['rawAttributes'],function(_0x403b37){return{'name':_0x403b37[_0x0f96('0x28')],'type':_0x403b37[_0x0f96('0x29')][_0x0f96('0x2a')]};});_0x258811[_0x0f96('0x2b')]=_[_0x0f96('0x26')](_0x3a1f27,'name');_0x258811[_0x0f96('0x2c')]=_[_0x0f96('0x2d')](_0x259fdf[_0x0f96('0x2c')]);_0x258811[_0x0f96('0x2e')]=_[_0x0f96('0x2f')](_0x258811[_0x0f96('0x2b')],_0x258811[_0x0f96('0x2c')]);_0x3055ae['attributes']=_[_0x0f96('0x2f')](_0x258811[_0x0f96('0x2b')],qs[_0x0f96('0x30')](_0x259fdf[_0x0f96('0x2c')][_0x0f96('0x30')]));_0x3055ae[_0x0f96('0x31')]=_0x3055ae['attributes']['length']?_0x3055ae[_0x0f96('0x31')]:_0x258811['model'];if(!_0x259fdf[_0x0f96('0x2c')]['hasOwnProperty'](_0x0f96('0x32'))){_0x3055ae[_0x0f96('0x33')]=qs[_0x0f96('0x33')](_0x259fdf[_0x0f96('0x2c')][_0x0f96('0x33')]);_0x3055ae[_0x0f96('0x1c')]=qs[_0x0f96('0x1c')](_0x259fdf['query'][_0x0f96('0x1c')]);}_0x3055ae[_0x0f96('0x34')]=qs[_0x0f96('0x35')](_0x259fdf[_0x0f96('0x2c')][_0x0f96('0x35')]);_0x3055ae[_0x0f96('0x36')]=qs[_0x0f96('0x2e')](_[_0x0f96('0x37')](_0x259fdf[_0x0f96('0x2c')],_0x258811[_0x0f96('0x2e')]),_0x3a1f27);if(_0x259fdf[_0x0f96('0x2c')][_0x0f96('0x38')]){_0x3055ae[_0x0f96('0x36')]=_[_0x0f96('0x39')](_0x3055ae[_0x0f96('0x36')],{'$or':_[_0x0f96('0x26')](_0x3a1f27,function(_0x17bf45){if(_0x17bf45['type']!==_0x0f96('0x3a')){var _0x193297={};_0x193297[_0x17bf45[_0x0f96('0x24')]]={'$like':'%'+_0x259fdf[_0x0f96('0x2c')][_0x0f96('0x38')]+'%'};return _0x193297;}})});}_0x3055ae=_[_0x0f96('0x39')]({},_0x3055ae,_0x259fdf['options']);var _0x2ea76b={'where':_0x3055ae[_0x0f96('0x36')]};return db['FaxQueueReport']['count'](_0x2ea76b)[_0x0f96('0x20')](function(_0x45b82e){_0x51441e[_0x0f96('0x1b')]=_0x45b82e;if(_0x259fdf[_0x0f96('0x2c')][_0x0f96('0x3b')]){_0x3055ae[_0x0f96('0x3c')]=[{'all':!![]}];}return db[_0x0f96('0x27')]['findAll'](_0x3055ae);})[_0x0f96('0x20')](function(_0x14758c){_0x51441e['rows']=_0x14758c;return _0x51441e;})[_0x0f96('0x20')](respondWithFilteredResult(_0xa5947e,_0x3055ae))[_0x0f96('0x3d')](handleError(_0xa5947e,null));};exports[_0x0f96('0x3e')]=function(_0x5dd164,_0x45af5e){var _0x4ae7f2={'raw':!![],'where':{'id':_0x5dd164['params']['id']}},_0x2a670d={};_0x2a670d['model']=_[_0x0f96('0x2d')](db[_0x0f96('0x27')][_0x0f96('0x3f')]);_0x2a670d[_0x0f96('0x2c')]=_[_0x0f96('0x2d')](_0x5dd164[_0x0f96('0x2c')]);_0x2a670d[_0x0f96('0x2e')]=_['intersection'](_0x2a670d[_0x0f96('0x2b')],_0x2a670d[_0x0f96('0x2c')]);_0x4ae7f2['attributes']=_[_0x0f96('0x2f')](_0x2a670d[_0x0f96('0x2b')],qs[_0x0f96('0x30')](_0x5dd164[_0x0f96('0x2c')][_0x0f96('0x30')]));_0x4ae7f2['attributes']=_0x4ae7f2[_0x0f96('0x31')][_0x0f96('0x40')]?_0x4ae7f2[_0x0f96('0x31')]:_0x2a670d[_0x0f96('0x2b')];if(_0x5dd164['query']['includeAll']){_0x4ae7f2['include']=[{'all':!![]}];}_0x4ae7f2=_[_0x0f96('0x39')]({},_0x4ae7f2,_0x5dd164[_0x0f96('0x41')]);return db[_0x0f96('0x27')][_0x0f96('0x42')](_0x4ae7f2)[_0x0f96('0x20')](handleEntityNotFound(_0x45af5e,null))[_0x0f96('0x20')](respondWithResult(_0x45af5e,null))[_0x0f96('0x3d')](handleError(_0x45af5e,null));};exports[_0x0f96('0x43')]=function(_0x18981f,_0x139dec){return db['FaxQueueReport'][_0x0f96('0x43')](_0x18981f[_0x0f96('0x44')],{})[_0x0f96('0x20')](respondWithResult(_0x139dec,0xc9))[_0x0f96('0x3d')](handleError(_0x139dec,null));};exports['update']=function(_0x11703d,_0x5d92ee){if(_0x11703d['body']['id']){delete _0x11703d[_0x0f96('0x44')]['id'];}return db['FaxQueueReport'][_0x0f96('0x42')]({'where':{'id':_0x11703d[_0x0f96('0x45')]['id']}})[_0x0f96('0x20')](handleEntityNotFound(_0x5d92ee,null))[_0x0f96('0x20')](saveUpdates(_0x11703d[_0x0f96('0x44')],null))[_0x0f96('0x20')](respondWithResult(_0x5d92ee,null))['catch'](handleError(_0x5d92ee,null));};exports[_0x0f96('0x21')]=function(_0x58ee44,_0x460c5f){return db[_0x0f96('0x27')][_0x0f96('0x42')]({'where':{'id':_0x58ee44[_0x0f96('0x45')]['id']}})[_0x0f96('0x20')](handleEntityNotFound(_0x460c5f,null))[_0x0f96('0x20')](removeEntity(_0x460c5f,null))[_0x0f96('0x3d')](handleError(_0x460c5f,null));};exports['describe']=function(_0x23a1d8,_0x1a724d){return db[_0x0f96('0x27')][_0x0f96('0x46')]()[_0x0f96('0x20')](respondWithResult(_0x1a724d,null))[_0x0f96('0x3d')](handleError(_0x1a724d,null));};