Built motion from commit 3e059bc2.|2.5.32
[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 _0x6a55=['rawAttributes','fieldName','type','query','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','filters','pick','filter','where','VIRTUAL','includeAll','findAll','show','keys','include','merge','options','find','catch','create','body','params','destroy','describe','eml-format','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','../../components/auth/service','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','offset','undefined','limit','count','json','reject','save','update','then','end','error','stack','name','index','map','FaxQueueReport'];(function(_0x465028,_0x4570ac){var _0xb783d4=function(_0x5458c5){while(--_0x5458c5){_0x465028['push'](_0x465028['shift']());}};_0xb783d4(++_0x4570ac);}(_0x6a55,0x154));var _0x56a5=function(_0xbf19d7,_0x58b2bf){_0xbf19d7=_0xbf19d7-0x0;var _0x376e11=_0x6a55[_0xbf19d7];return _0x376e11;};'use strict';var emlformat=require(_0x56a5('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x56a5('0x1'));var jsonpatch=require(_0x56a5('0x2'));var rp=require('request-promise');var moment=require(_0x56a5('0x3'));var BPromise=require(_0x56a5('0x4'));var Mustache=require(_0x56a5('0x5'));var util=require(_0x56a5('0x6'));var path=require(_0x56a5('0x7'));var sox=require(_0x56a5('0x8'));var csv=require(_0x56a5('0x9'));var ejs=require(_0x56a5('0xa'));var fs=require('fs');var fs_extra=require(_0x56a5('0xb'));var _=require(_0x56a5('0xc'));var squel=require(_0x56a5('0xd'));var crypto=require(_0x56a5('0xe'));var jsforce=require(_0x56a5('0xf'));var deskjs=require(_0x56a5('0x10'));var toCsv=require('to-csv');var querystring=require(_0x56a5('0x11'));var Papa=require(_0x56a5('0x12'));var Redis=require('ioredis');var authService=require(_0x56a5('0x13'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x56a5('0x14'));var logger=require(_0x56a5('0x15'))(_0x56a5('0x16'));var utils=require(_0x56a5('0x17'));var config=require(_0x56a5('0x18'));var licenseUtil=require(_0x56a5('0x19'));var db=require(_0x56a5('0x1a'))['db'];function respondWithStatusCode(_0x4b4dc7,_0x42dced){_0x42dced=_0x42dced||0xcc;return function(_0x5a80ed){if(_0x5a80ed){return _0x4b4dc7[_0x56a5('0x1b')](_0x42dced);}return _0x4b4dc7[_0x56a5('0x1c')](_0x42dced)['end']();};}function respondWithResult(_0x281d8b,_0x145174){_0x145174=_0x145174||0xc8;return function(_0x11f64d){if(_0x11f64d){return _0x281d8b[_0x56a5('0x1c')](_0x145174)['json'](_0x11f64d);}};}function respondWithFilteredResult(_0x3ad9d9,_0xdfce42){return function(_0x24cb7b){if(_0x24cb7b){var _0x466f52=typeof _0xdfce42[_0x56a5('0x1d')]===_0x56a5('0x1e')&&typeof _0xdfce42[_0x56a5('0x1f')]===_0x56a5('0x1e');var _0x26debc=_0x24cb7b['count'];var _0x52758f=_0x466f52?0x0:_0xdfce42[_0x56a5('0x1d')];var _0x4ed8dc=_0x466f52?_0x24cb7b[_0x56a5('0x20')]:_0xdfce42[_0x56a5('0x1d')]+_0xdfce42[_0x56a5('0x1f')];var _0x365150;if(_0x4ed8dc>=_0x26debc){_0x4ed8dc=_0x26debc;_0x365150=0xc8;}else{_0x365150=0xce;}_0x3ad9d9[_0x56a5('0x1c')](_0x365150);return _0x3ad9d9['set']('Content-Range',_0x52758f+'-'+_0x4ed8dc+'/'+_0x26debc)[_0x56a5('0x21')](_0x24cb7b);}return null;};}function patchUpdates(_0x5882cd){return function(_0x32b71f){try{jsonpatch['apply'](_0x32b71f,_0x5882cd,!![]);}catch(_0x3a8046){return BPromise[_0x56a5('0x22')](_0x3a8046);}return _0x32b71f[_0x56a5('0x23')]();};}function saveUpdates(_0x4cc2e2,_0x25eeb2){return function(_0x5bdefb){if(_0x5bdefb){return _0x5bdefb[_0x56a5('0x24')](_0x4cc2e2)['then'](function(_0x5749ea){return _0x5749ea;});}return null;};}function removeEntity(_0x1228af,_0x488b2a){return function(_0x2cc3c0){if(_0x2cc3c0){return _0x2cc3c0['destroy']()[_0x56a5('0x25')](function(){_0x1228af[_0x56a5('0x1c')](0xcc)[_0x56a5('0x26')]();});}};}function handleEntityNotFound(_0x587d78,_0x38b5e0){return function(_0x2950f6){if(!_0x2950f6){_0x587d78['sendStatus'](0x194);}return _0x2950f6;};}function handleError(_0x1a0dec,_0x3cb7ae){_0x3cb7ae=_0x3cb7ae||0x1f4;return function(_0x3dfdaf){logger[_0x56a5('0x27')](_0x3dfdaf[_0x56a5('0x28')]);if(_0x3dfdaf[_0x56a5('0x29')]){delete _0x3dfdaf['name'];}_0x1a0dec[_0x56a5('0x1c')](_0x3cb7ae)['send'](_0x3dfdaf);};}exports[_0x56a5('0x2a')]=function(_0x42b87b,_0x1355d6){var _0xb1e9c5={},_0x263188={},_0x2de197={'count':0x0,'rows':[]};var _0x512a48=_[_0x56a5('0x2b')](db[_0x56a5('0x2c')][_0x56a5('0x2d')],function(_0x5036cc){return{'name':_0x5036cc[_0x56a5('0x2e')],'type':_0x5036cc[_0x56a5('0x2f')]['key']};});_0x263188['model']=_[_0x56a5('0x2b')](_0x512a48,_0x56a5('0x29'));_0x263188[_0x56a5('0x30')]=_['keys'](_0x42b87b[_0x56a5('0x30')]);_0x263188['filters']=_[_0x56a5('0x31')](_0x263188[_0x56a5('0x32')],_0x263188[_0x56a5('0x30')]);_0xb1e9c5[_0x56a5('0x33')]=_[_0x56a5('0x31')](_0x263188[_0x56a5('0x32')],qs['fields'](_0x42b87b['query'][_0x56a5('0x34')]));_0xb1e9c5[_0x56a5('0x33')]=_0xb1e9c5['attributes'][_0x56a5('0x35')]?_0xb1e9c5[_0x56a5('0x33')]:_0x263188[_0x56a5('0x32')];if(!_0x42b87b['query'][_0x56a5('0x36')](_0x56a5('0x37'))){_0xb1e9c5[_0x56a5('0x1f')]=qs[_0x56a5('0x1f')](_0x42b87b[_0x56a5('0x30')][_0x56a5('0x1f')]);_0xb1e9c5['offset']=qs[_0x56a5('0x1d')](_0x42b87b[_0x56a5('0x30')]['offset']);}_0xb1e9c5[_0x56a5('0x38')]=qs[_0x56a5('0x39')](_0x42b87b[_0x56a5('0x30')][_0x56a5('0x39')]);_0xb1e9c5['where']=qs[_0x56a5('0x3a')](_[_0x56a5('0x3b')](_0x42b87b[_0x56a5('0x30')],_0x263188[_0x56a5('0x3a')]),_0x512a48);if(_0x42b87b[_0x56a5('0x30')][_0x56a5('0x3c')]){_0xb1e9c5['where']=_['merge'](_0xb1e9c5[_0x56a5('0x3d')],{'$or':_[_0x56a5('0x2b')](_0x512a48,function(_0x268f9c){if(_0x268f9c[_0x56a5('0x2f')]!==_0x56a5('0x3e')){var _0x41bd0b={};_0x41bd0b[_0x268f9c['name']]={'$like':'%'+_0x42b87b[_0x56a5('0x30')][_0x56a5('0x3c')]+'%'};return _0x41bd0b;}})});}_0xb1e9c5=_['merge']({},_0xb1e9c5,_0x42b87b['options']);var _0xb44fb0={'where':_0xb1e9c5[_0x56a5('0x3d')]};return db['FaxQueueReport'][_0x56a5('0x20')](_0xb44fb0)[_0x56a5('0x25')](function(_0x47b3fa){_0x2de197[_0x56a5('0x20')]=_0x47b3fa;if(_0x42b87b[_0x56a5('0x30')][_0x56a5('0x3f')]){_0xb1e9c5['include']=[{'all':!![]}];}return db[_0x56a5('0x2c')][_0x56a5('0x40')](_0xb1e9c5);})['then'](function(_0x23bfa5){_0x2de197['rows']=_0x23bfa5;return _0x2de197;})[_0x56a5('0x25')](respondWithFilteredResult(_0x1355d6,_0xb1e9c5))['catch'](handleError(_0x1355d6,null));};exports[_0x56a5('0x41')]=function(_0x17fcee,_0x4431f7){var _0x5205b8={'raw':!![],'where':{'id':_0x17fcee['params']['id']}},_0x39ee9a={};_0x39ee9a[_0x56a5('0x32')]=_[_0x56a5('0x42')](db[_0x56a5('0x2c')][_0x56a5('0x2d')]);_0x39ee9a[_0x56a5('0x30')]=_[_0x56a5('0x42')](_0x17fcee[_0x56a5('0x30')]);_0x39ee9a[_0x56a5('0x3a')]=_['intersection'](_0x39ee9a[_0x56a5('0x32')],_0x39ee9a[_0x56a5('0x30')]);_0x5205b8['attributes']=_[_0x56a5('0x31')](_0x39ee9a[_0x56a5('0x32')],qs['fields'](_0x17fcee['query'][_0x56a5('0x34')]));_0x5205b8[_0x56a5('0x33')]=_0x5205b8[_0x56a5('0x33')][_0x56a5('0x35')]?_0x5205b8[_0x56a5('0x33')]:_0x39ee9a[_0x56a5('0x32')];if(_0x17fcee['query']['includeAll']){_0x5205b8[_0x56a5('0x43')]=[{'all':!![]}];}_0x5205b8=_[_0x56a5('0x44')]({},_0x5205b8,_0x17fcee[_0x56a5('0x45')]);return db['FaxQueueReport'][_0x56a5('0x46')](_0x5205b8)['then'](handleEntityNotFound(_0x4431f7,null))[_0x56a5('0x25')](respondWithResult(_0x4431f7,null))[_0x56a5('0x47')](handleError(_0x4431f7,null));};exports[_0x56a5('0x48')]=function(_0x2ecbaa,_0x37faf5){return db[_0x56a5('0x2c')][_0x56a5('0x48')](_0x2ecbaa[_0x56a5('0x49')],{})[_0x56a5('0x25')](respondWithResult(_0x37faf5,0xc9))['catch'](handleError(_0x37faf5,null));};exports[_0x56a5('0x24')]=function(_0xaaa40c,_0x5a8ba3){if(_0xaaa40c[_0x56a5('0x49')]['id']){delete _0xaaa40c[_0x56a5('0x49')]['id'];}return db[_0x56a5('0x2c')]['find']({'where':{'id':_0xaaa40c[_0x56a5('0x4a')]['id']}})[_0x56a5('0x25')](handleEntityNotFound(_0x5a8ba3,null))[_0x56a5('0x25')](saveUpdates(_0xaaa40c['body'],null))[_0x56a5('0x25')](respondWithResult(_0x5a8ba3,null))[_0x56a5('0x47')](handleError(_0x5a8ba3,null));};exports[_0x56a5('0x4b')]=function(_0x1b0c6f,_0x2b5f2a){return db[_0x56a5('0x2c')][_0x56a5('0x46')]({'where':{'id':_0x1b0c6f[_0x56a5('0x4a')]['id']}})[_0x56a5('0x25')](handleEntityNotFound(_0x2b5f2a,null))[_0x56a5('0x25')](removeEntity(_0x2b5f2a,null))[_0x56a5('0x47')](handleError(_0x2b5f2a,null));};exports[_0x56a5('0x4c')]=function(_0x3229c8,_0xff01fa){return db[_0x56a5('0x2c')][_0x56a5('0x4c')]()['then'](respondWithResult(_0xff01fa,null))['catch'](handleError(_0xff01fa,null));};