9f578cb8afc35a319a5ebd960a03a44906a4163c
[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 _0xf351=['where','VIRTUAL','filter','merge','count','includeAll','include','findAll','rows','catch','params','keys','rawAttributes','options','create','body','find','describe','html-pdf','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','to-csv','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/license/util','status','offset','limit','set','Content-Range','apply','update','then','destroy','end','error','stack','name','send','index','map','FaxQueueReport','type','key','model','query','filters','intersection','attributes','fields','length','nolimit','order','sort'];(function(_0x555e35,_0x205cc1){var _0x35b56a=function(_0x469cb4){while(--_0x469cb4){_0x555e35['push'](_0x555e35['shift']());}};_0x35b56a(++_0x205cc1);}(_0xf351,0x9c));var _0x1f35=function(_0xcfd89f,_0x106e8f){_0xcfd89f=_0xcfd89f-0x0;var _0x59acd4=_0xf351[_0xcfd89f];return _0x59acd4;};'use strict';var pdf=require(_0x1f35('0x0'));var emlformat=require('eml-format');var rimraf=require('rimraf');var zipdir=require('zip-dir');var jsonpatch=require(_0x1f35('0x1'));var rp=require(_0x1f35('0x2'));var moment=require(_0x1f35('0x3'));var BPromise=require(_0x1f35('0x4'));var Mustache=require(_0x1f35('0x5'));var util=require(_0x1f35('0x6'));var path=require(_0x1f35('0x7'));var sox=require('sox');var csv=require(_0x1f35('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x1f35('0x9'));var crypto=require(_0x1f35('0xa'));var jsforce=require(_0x1f35('0xb'));var deskjs=require(_0x1f35('0xc'));var toCsv=require('to-csv');var querystring=require(_0x1f35('0xd'));var Papa=require('papaparse');var Redis=require(_0x1f35('0xe'));var authService=require(_0x1f35('0xf'));var qs=require('../../components/parsers/qs');var as=require(_0x1f35('0x10'));var hardwareService=require(_0x1f35('0x11'));var logger=require(_0x1f35('0x12'))(_0x1f35('0x13'));var utils=require(_0x1f35('0x14'));var config=require('../../config/environment');var licenseUtil=require(_0x1f35('0x15'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x2ca2cb,_0x14d5dd){_0x14d5dd=_0x14d5dd||0xcc;return function(_0x472a97){if(_0x472a97){return _0x2ca2cb['sendStatus'](_0x14d5dd);}return _0x2ca2cb[_0x1f35('0x16')](_0x14d5dd)['end']();};}function respondWithResult(_0xc5e9b8,_0x57c69e){_0x57c69e=_0x57c69e||0xc8;return function(_0x1318c7){if(_0x1318c7){return _0xc5e9b8[_0x1f35('0x16')](_0x57c69e)['json'](_0x1318c7);}};}function respondWithFilteredResult(_0x12c650,_0x375d45){return function(_0x51c16c){if(_0x51c16c){var _0x51e563=_0x51c16c['count'],_0x5ac2ed=_0x375d45[_0x1f35('0x17')],_0x361488=_0x375d45[_0x1f35('0x17')]+_0x375d45[_0x1f35('0x18')],_0x412c50;if(_0x361488>=_0x51e563){_0x361488=_0x51e563;_0x412c50=0xc8;}else{_0x412c50=0xce;}_0x12c650['status'](_0x412c50);return _0x12c650[_0x1f35('0x19')](_0x1f35('0x1a'),_0x5ac2ed+'-'+_0x361488+'/'+_0x51e563)['json'](_0x51c16c);}return null;};}function patchUpdates(_0x539fe6){return function(_0x560ab1){try{jsonpatch[_0x1f35('0x1b')](_0x560ab1,_0x539fe6,!![]);}catch(_0x3cec83){return BPromise['reject'](_0x3cec83);}return _0x560ab1['save']();};}function saveUpdates(_0xd77343,_0x3ba638){return function(_0x1659ee){if(_0x1659ee){return _0x1659ee[_0x1f35('0x1c')](_0xd77343)[_0x1f35('0x1d')](function(_0x283ade){return _0x283ade;});}return null;};}function removeEntity(_0x52e1e1,_0x233246){return function(_0x4eed20){if(_0x4eed20){return _0x4eed20[_0x1f35('0x1e')]()[_0x1f35('0x1d')](function(){_0x52e1e1['status'](0xcc)[_0x1f35('0x1f')]();});}};}function handleEntityNotFound(_0x51fdac,_0x28639a){return function(_0x224f91){if(!_0x224f91){_0x51fdac['sendStatus'](0x194);}return _0x224f91;};}function handleError(_0x1741b6,_0x17d030){_0x17d030=_0x17d030||0x1f4;return function(_0x4a2e29){logger[_0x1f35('0x20')](_0x4a2e29[_0x1f35('0x21')]);if(_0x4a2e29['name']){delete _0x4a2e29[_0x1f35('0x22')];}_0x1741b6['status'](_0x17d030)[_0x1f35('0x23')](_0x4a2e29);};}exports[_0x1f35('0x24')]=function(_0x5123a8,_0x17ce5f){var _0x33c473={},_0x4fac96={},_0x4d78ab={'count':0x0,'rows':[]};var _0x4948a1=_[_0x1f35('0x25')](db[_0x1f35('0x26')]['rawAttributes'],function(_0x3006d4){return{'name':_0x3006d4['fieldName'],'type':_0x3006d4[_0x1f35('0x27')][_0x1f35('0x28')]};});_0x4fac96[_0x1f35('0x29')]=_[_0x1f35('0x25')](_0x4948a1,_0x1f35('0x22'));_0x4fac96[_0x1f35('0x2a')]=_['keys'](_0x5123a8[_0x1f35('0x2a')]);_0x4fac96[_0x1f35('0x2b')]=_[_0x1f35('0x2c')](_0x4fac96['model'],_0x4fac96[_0x1f35('0x2a')]);_0x33c473[_0x1f35('0x2d')]=_['intersection'](_0x4fac96[_0x1f35('0x29')],qs[_0x1f35('0x2e')](_0x5123a8[_0x1f35('0x2a')][_0x1f35('0x2e')]));_0x33c473['attributes']=_0x33c473[_0x1f35('0x2d')][_0x1f35('0x2f')]?_0x33c473['attributes']:_0x4fac96[_0x1f35('0x29')];if(!_0x5123a8[_0x1f35('0x2a')]['hasOwnProperty'](_0x1f35('0x30'))){_0x33c473[_0x1f35('0x18')]=qs[_0x1f35('0x18')](_0x5123a8[_0x1f35('0x2a')][_0x1f35('0x18')]);_0x33c473['offset']=qs[_0x1f35('0x17')](_0x5123a8[_0x1f35('0x2a')]['offset']);}_0x33c473[_0x1f35('0x31')]=qs[_0x1f35('0x32')](_0x5123a8[_0x1f35('0x2a')][_0x1f35('0x32')]);_0x33c473[_0x1f35('0x33')]=qs[_0x1f35('0x2b')](_['pick'](_0x5123a8['query'],_0x4fac96[_0x1f35('0x2b')]),_0x4948a1);if(_0x5123a8[_0x1f35('0x2a')]['filter']){_0x33c473[_0x1f35('0x33')]=_['merge'](_0x33c473[_0x1f35('0x33')],{'$or':_[_0x1f35('0x25')](_0x4948a1,function(_0x1cc6ca){if(_0x1cc6ca[_0x1f35('0x27')]!==_0x1f35('0x34')){var _0x5e8b0a={};_0x5e8b0a[_0x1cc6ca[_0x1f35('0x22')]]={'$like':'%'+_0x5123a8['query'][_0x1f35('0x35')]+'%'};return _0x5e8b0a;}})});}_0x33c473=_[_0x1f35('0x36')]({},_0x33c473,_0x5123a8['options']);var _0x5d6576={'where':_0x33c473[_0x1f35('0x33')]};return db[_0x1f35('0x26')][_0x1f35('0x37')](_0x5d6576)['then'](function(_0x338fae){_0x4d78ab[_0x1f35('0x37')]=_0x338fae;if(_0x5123a8[_0x1f35('0x2a')][_0x1f35('0x38')]){_0x33c473[_0x1f35('0x39')]=[{'all':!![]}];}return db[_0x1f35('0x26')][_0x1f35('0x3a')](_0x33c473);})[_0x1f35('0x1d')](function(_0x45ab90){_0x4d78ab[_0x1f35('0x3b')]=_0x45ab90;return _0x4d78ab;})['then'](respondWithFilteredResult(_0x17ce5f,_0x33c473))[_0x1f35('0x3c')](handleError(_0x17ce5f,null));};exports['show']=function(_0x40c07f,_0x33e9cb){var _0x122664={'raw':!![],'where':{'id':_0x40c07f[_0x1f35('0x3d')]['id']}},_0x837b13={};_0x837b13[_0x1f35('0x29')]=_[_0x1f35('0x3e')](db[_0x1f35('0x26')][_0x1f35('0x3f')]);_0x837b13['query']=_['keys'](_0x40c07f[_0x1f35('0x2a')]);_0x837b13[_0x1f35('0x2b')]=_['intersection'](_0x837b13[_0x1f35('0x29')],_0x837b13['query']);_0x122664[_0x1f35('0x2d')]=_[_0x1f35('0x2c')](_0x837b13['model'],qs[_0x1f35('0x2e')](_0x40c07f['query'][_0x1f35('0x2e')]));_0x122664['attributes']=_0x122664[_0x1f35('0x2d')]['length']?_0x122664['attributes']:_0x837b13[_0x1f35('0x29')];if(_0x40c07f[_0x1f35('0x2a')][_0x1f35('0x38')]){_0x122664['include']=[{'all':!![]}];}_0x122664=_[_0x1f35('0x36')]({},_0x122664,_0x40c07f[_0x1f35('0x40')]);return db[_0x1f35('0x26')]['find'](_0x122664)[_0x1f35('0x1d')](handleEntityNotFound(_0x33e9cb,null))['then'](respondWithResult(_0x33e9cb,null))[_0x1f35('0x3c')](handleError(_0x33e9cb,null));};exports[_0x1f35('0x41')]=function(_0x4d06bd,_0x51aeb5){return db[_0x1f35('0x26')][_0x1f35('0x41')](_0x4d06bd['body'],{})[_0x1f35('0x1d')](respondWithResult(_0x51aeb5,0xc9))[_0x1f35('0x3c')](handleError(_0x51aeb5,null));};exports[_0x1f35('0x1c')]=function(_0x169b26,_0x1def1f){if(_0x169b26[_0x1f35('0x42')]['id']){delete _0x169b26['body']['id'];}return db[_0x1f35('0x26')][_0x1f35('0x43')]({'where':{'id':_0x169b26[_0x1f35('0x3d')]['id']}})[_0x1f35('0x1d')](handleEntityNotFound(_0x1def1f,null))[_0x1f35('0x1d')](saveUpdates(_0x169b26[_0x1f35('0x42')],null))[_0x1f35('0x1d')](respondWithResult(_0x1def1f,null))['catch'](handleError(_0x1def1f,null));};exports[_0x1f35('0x1e')]=function(_0x25a0b6,_0x2f2d31){return db[_0x1f35('0x26')][_0x1f35('0x43')]({'where':{'id':_0x25a0b6['params']['id']}})[_0x1f35('0x1d')](handleEntityNotFound(_0x2f2d31,null))[_0x1f35('0x1d')](removeEntity(_0x2f2d31,null))[_0x1f35('0x3c')](handleError(_0x2f2d31,null));};exports[_0x1f35('0x44')]=function(_0x4a988b,_0x3ca7b7){return db[_0x1f35('0x26')][_0x1f35('0x44')]()[_0x1f35('0x1d')](respondWithResult(_0x3ca7b7,null))[_0x1f35('0x3c')](handleError(_0x3ca7b7,null));};