85ea4b1fdc3f35598ad005325dc0e5c3d7256d50
[motion2.git] / server / api / openchannelQueueReport / openchannelQueueReport.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 _0x1bf3=['status','end','json','count','offset','limit','Content-Range','apply','reject','save','then','error','stack','send','index','rawAttributes','fieldName','key','map','name','query','filters','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','sort','pick','filter','where','merge','type','VIRTUAL','options','OpenchannelQueueReport','includeAll','include','rows','show','params','keys','find','catch','create','update','body','destroy','describe','html-pdf','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','ejs','lodash','squel','crypto','jsforce','desk.js','to-csv','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus'];(function(_0x524191,_0x5aff6a){var _0x4901b9=function(_0x5b2c29){while(--_0x5b2c29){_0x524191['push'](_0x524191['shift']());}};_0x4901b9(++_0x5aff6a);}(_0x1bf3,0x16f));var _0x31bf=function(_0x4565bf,_0x5ad9d6){_0x4565bf=_0x4565bf-0x0;var _0x5610ba=_0x1bf3[_0x4565bf];return _0x5610ba;};'use strict';var pdf=require(_0x31bf('0x0'));var emlformat=require(_0x31bf('0x1'));var rimraf=require('rimraf');var zipdir=require(_0x31bf('0x2'));var jsonpatch=require(_0x31bf('0x3'));var rp=require(_0x31bf('0x4'));var moment=require(_0x31bf('0x5'));var BPromise=require(_0x31bf('0x6'));var Mustache=require(_0x31bf('0x7'));var util=require(_0x31bf('0x8'));var path=require(_0x31bf('0x9'));var sox=require('sox');var csv=require('to-csv');var ejs=require(_0x31bf('0xa'));var fs=require('fs');var _=require(_0x31bf('0xb'));var squel=require(_0x31bf('0xc'));var crypto=require(_0x31bf('0xd'));var jsforce=require(_0x31bf('0xe'));var deskjs=require(_0x31bf('0xf'));var toCsv=require(_0x31bf('0x10'));var querystring=require(_0x31bf('0x11'));var Papa=require(_0x31bf('0x12'));var Redis=require(_0x31bf('0x13'));var authService=require('../../components/auth/service');var qs=require(_0x31bf('0x14'));var as=require(_0x31bf('0x15'));var hardwareService=require(_0x31bf('0x16'));var logger=require('../../config/logger')(_0x31bf('0x17'));var utils=require(_0x31bf('0x18'));var config=require(_0x31bf('0x19'));var db=require(_0x31bf('0x1a'))['db'];function respondWithStatusCode(_0x596d40,_0x1b00eb){_0x1b00eb=_0x1b00eb||0xcc;return function(_0x55b324){if(_0x55b324){return _0x596d40[_0x31bf('0x1b')](_0x1b00eb);}return _0x596d40[_0x31bf('0x1c')](_0x1b00eb)[_0x31bf('0x1d')]();};}function respondWithResult(_0x5de408,_0x38421a){_0x38421a=_0x38421a||0xc8;return function(_0xb0ab7d){if(_0xb0ab7d){return _0x5de408[_0x31bf('0x1c')](_0x38421a)[_0x31bf('0x1e')](_0xb0ab7d);}};}function respondWithFilteredResult(_0x3bb61d,_0x35702b){return function(_0x1b9fa8){if(_0x1b9fa8){var _0x1930a3=_0x1b9fa8[_0x31bf('0x1f')],_0x5ab39e=_0x35702b[_0x31bf('0x20')],_0x3d1bbe=_0x35702b['offset']+_0x35702b[_0x31bf('0x21')],_0x5081eb;if(_0x3d1bbe>=_0x1930a3){_0x3d1bbe=_0x1930a3;_0x5081eb=0xc8;}else{_0x5081eb=0xce;}_0x3bb61d['status'](_0x5081eb);return _0x3bb61d['set'](_0x31bf('0x22'),_0x5ab39e+'-'+_0x3d1bbe+'/'+_0x1930a3)[_0x31bf('0x1e')](_0x1b9fa8);}return null;};}function patchUpdates(_0x45309f){return function(_0x3c5172){try{jsonpatch[_0x31bf('0x23')](_0x3c5172,_0x45309f,!![]);}catch(_0xd74d08){return BPromise[_0x31bf('0x24')](_0xd74d08);}return _0x3c5172[_0x31bf('0x25')]();};}function saveUpdates(_0x38123c,_0x3bfc34){return function(_0x3fc8b1){if(_0x3fc8b1){return _0x3fc8b1['update'](_0x38123c)[_0x31bf('0x26')](function(_0x4e49a9){return _0x4e49a9;});}return null;};}function removeEntity(_0x1baec8,_0x537964){return function(_0x442746){if(_0x442746){return _0x442746['destroy']()[_0x31bf('0x26')](function(){_0x1baec8[_0x31bf('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x563ba9,_0x3a140a){return function(_0x411ecc){if(!_0x411ecc){_0x563ba9[_0x31bf('0x1b')](0x194);}return _0x411ecc;};}function handleError(_0x54f637,_0x394c){_0x394c=_0x394c||0x1f4;return function(_0x359ce7){logger[_0x31bf('0x27')](_0x359ce7[_0x31bf('0x28')]);if(_0x359ce7['name']){delete _0x359ce7['name'];}_0x54f637[_0x31bf('0x1c')](_0x394c)[_0x31bf('0x29')](_0x359ce7);};}exports[_0x31bf('0x2a')]=function(_0x4688ae,_0x59a29b){var _0x58db5b={},_0x2d82e4={},_0x50f94f={'count':0x0,'rows':[]};var _0x5995a5=_['map'](db['OpenchannelQueueReport'][_0x31bf('0x2b')],function(_0x3b72c0){return{'name':_0x3b72c0[_0x31bf('0x2c')],'type':_0x3b72c0['type'][_0x31bf('0x2d')]};});_0x2d82e4['model']=_[_0x31bf('0x2e')](_0x5995a5,_0x31bf('0x2f'));_0x2d82e4[_0x31bf('0x30')]=_['keys'](_0x4688ae[_0x31bf('0x30')]);_0x2d82e4[_0x31bf('0x31')]=_['intersection'](_0x2d82e4[_0x31bf('0x32')],_0x2d82e4[_0x31bf('0x30')]);_0x58db5b[_0x31bf('0x33')]=_[_0x31bf('0x34')](_0x2d82e4[_0x31bf('0x32')],qs[_0x31bf('0x35')](_0x4688ae[_0x31bf('0x30')][_0x31bf('0x35')]));_0x58db5b[_0x31bf('0x33')]=_0x58db5b[_0x31bf('0x33')][_0x31bf('0x36')]?_0x58db5b['attributes']:_0x2d82e4['model'];if(!_0x4688ae[_0x31bf('0x30')][_0x31bf('0x37')](_0x31bf('0x38'))){_0x58db5b[_0x31bf('0x21')]=qs['limit'](_0x4688ae['query'][_0x31bf('0x21')]);_0x58db5b['offset']=qs[_0x31bf('0x20')](_0x4688ae[_0x31bf('0x30')]['offset']);}_0x58db5b['order']=qs[_0x31bf('0x39')](_0x4688ae['query'][_0x31bf('0x39')]);_0x58db5b['where']=qs['filters'](_[_0x31bf('0x3a')](_0x4688ae[_0x31bf('0x30')],_0x2d82e4[_0x31bf('0x31')]),_0x5995a5);if(_0x4688ae[_0x31bf('0x30')][_0x31bf('0x3b')]){_0x58db5b[_0x31bf('0x3c')]=_[_0x31bf('0x3d')](_0x58db5b[_0x31bf('0x3c')],{'$or':_['map'](_0x5995a5,function(_0x252919){if(_0x252919[_0x31bf('0x3e')]!==_0x31bf('0x3f')){var _0x3a349a={};_0x3a349a[_0x252919[_0x31bf('0x2f')]]={'$like':'%'+_0x4688ae[_0x31bf('0x30')][_0x31bf('0x3b')]+'%'};return _0x3a349a;}})});}_0x58db5b=_[_0x31bf('0x3d')]({},_0x58db5b,_0x4688ae[_0x31bf('0x40')]);var _0x117809={'where':_0x58db5b[_0x31bf('0x3c')]};return db[_0x31bf('0x41')][_0x31bf('0x1f')](_0x117809)[_0x31bf('0x26')](function(_0x5e0e1b){_0x50f94f[_0x31bf('0x1f')]=_0x5e0e1b;if(_0x4688ae[_0x31bf('0x30')][_0x31bf('0x42')]){_0x58db5b[_0x31bf('0x43')]=[{'all':!![]}];}return db[_0x31bf('0x41')]['findAll'](_0x58db5b);})['then'](function(_0x1d4f1d){_0x50f94f[_0x31bf('0x44')]=_0x1d4f1d;return _0x50f94f;})[_0x31bf('0x26')](respondWithFilteredResult(_0x59a29b,_0x58db5b))['catch'](handleError(_0x59a29b,null));};exports[_0x31bf('0x45')]=function(_0x2b65be,_0x3b9670){var _0x30718a={'raw':!![],'where':{'id':_0x2b65be[_0x31bf('0x46')]['id']}},_0x486478={};_0x486478[_0x31bf('0x32')]=_[_0x31bf('0x47')](db[_0x31bf('0x41')][_0x31bf('0x2b')]);_0x486478['query']=_[_0x31bf('0x47')](_0x2b65be[_0x31bf('0x30')]);_0x486478['filters']=_['intersection'](_0x486478['model'],_0x486478[_0x31bf('0x30')]);_0x30718a[_0x31bf('0x33')]=_[_0x31bf('0x34')](_0x486478['model'],qs[_0x31bf('0x35')](_0x2b65be[_0x31bf('0x30')][_0x31bf('0x35')]));_0x30718a[_0x31bf('0x33')]=_0x30718a[_0x31bf('0x33')][_0x31bf('0x36')]?_0x30718a[_0x31bf('0x33')]:_0x486478[_0x31bf('0x32')];if(_0x2b65be[_0x31bf('0x30')][_0x31bf('0x42')]){_0x30718a[_0x31bf('0x43')]=[{'all':!![]}];}_0x30718a=_[_0x31bf('0x3d')]({},_0x30718a,_0x2b65be[_0x31bf('0x40')]);return db[_0x31bf('0x41')][_0x31bf('0x48')](_0x30718a)[_0x31bf('0x26')](handleEntityNotFound(_0x3b9670,null))[_0x31bf('0x26')](respondWithResult(_0x3b9670,null))[_0x31bf('0x49')](handleError(_0x3b9670,null));};exports[_0x31bf('0x4a')]=function(_0x213b6f,_0x5bc7e6){return db['OpenchannelQueueReport'][_0x31bf('0x4a')](_0x213b6f['body'],{})[_0x31bf('0x26')](respondWithResult(_0x5bc7e6,0xc9))[_0x31bf('0x49')](handleError(_0x5bc7e6,null));};exports[_0x31bf('0x4b')]=function(_0x1c7a31,_0x2024e4){if(_0x1c7a31['body']['id']){delete _0x1c7a31['body']['id'];}return db[_0x31bf('0x41')][_0x31bf('0x48')]({'where':{'id':_0x1c7a31[_0x31bf('0x46')]['id']}})[_0x31bf('0x26')](handleEntityNotFound(_0x2024e4,null))['then'](saveUpdates(_0x1c7a31[_0x31bf('0x4c')],null))[_0x31bf('0x26')](respondWithResult(_0x2024e4,null))['catch'](handleError(_0x2024e4,null));};exports[_0x31bf('0x4d')]=function(_0x2716bb,_0x3f2a14){return db[_0x31bf('0x41')]['find']({'where':{'id':_0x2716bb[_0x31bf('0x46')]['id']}})[_0x31bf('0x26')](handleEntityNotFound(_0x3f2a14,null))[_0x31bf('0x26')](removeEntity(_0x3f2a14,null))['catch'](handleError(_0x3f2a14,null));};exports['describe']=function(_0x459866,_0x589b87){return db[_0x31bf('0x41')][_0x31bf('0x4e')]()[_0x31bf('0x26')](respondWithResult(_0x589b87,null))[_0x31bf('0x49')](handleError(_0x589b87,null));};