Built motion from commit c738b9ac.|2.6.25
[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 _0xf325=['query','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','merge','type','filter','count','include','rows','catch','show','params','rawAttributes','includeAll','options','create','body','update','find','describe','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','path','sox','fs-extra','lodash','squel','desk.js','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/environment','../../config/license/util','sendStatus','status','end','json','offset','undefined','limit','set','Content-Range','reject','save','then','destroy','stack','name','send','index','map','OpenchannelQueueReport','model','keys','filters'];(function(_0x2b04fc,_0x20cd82){var _0x25b587=function(_0x138c52){while(--_0x138c52){_0x2b04fc['push'](_0x2b04fc['shift']());}};_0x25b587(++_0x20cd82);}(_0xf325,0x1d2));var _0x5f32=function(_0x199572,_0x33e667){_0x199572=_0x199572-0x0;var _0x13cfa3=_0xf325[_0x199572];return _0x13cfa3;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x5f32('0x0'));var zipdir=require(_0x5f32('0x1'));var jsonpatch=require(_0x5f32('0x2'));var rp=require(_0x5f32('0x3'));var moment=require('moment');var BPromise=require(_0x5f32('0x4'));var Mustache=require(_0x5f32('0x5'));var util=require('util');var path=require(_0x5f32('0x6'));var sox=require(_0x5f32('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x5f32('0x8'));var _=require(_0x5f32('0x9'));var squel=require(_0x5f32('0xa'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x5f32('0xb'));var toCsv=require(_0x5f32('0xc'));var querystring=require(_0x5f32('0xd'));var Papa=require(_0x5f32('0xe'));var Redis=require(_0x5f32('0xf'));var authService=require(_0x5f32('0x10'));var qs=require('../../components/parsers/qs');var as=require(_0x5f32('0x11'));var hardwareService=require(_0x5f32('0x12'));var logger=require(_0x5f32('0x13'))(_0x5f32('0x14'));var utils=require('../../config/utils');var config=require(_0x5f32('0x15'));var licenseUtil=require(_0x5f32('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x32b4e1,_0x25a534){_0x25a534=_0x25a534||0xcc;return function(_0x485b9c){if(_0x485b9c){return _0x32b4e1[_0x5f32('0x17')](_0x25a534);}return _0x32b4e1[_0x5f32('0x18')](_0x25a534)[_0x5f32('0x19')]();};}function respondWithResult(_0x57d343,_0x3ec841){_0x3ec841=_0x3ec841||0xc8;return function(_0x5c923f){if(_0x5c923f){return _0x57d343[_0x5f32('0x18')](_0x3ec841)[_0x5f32('0x1a')](_0x5c923f);}};}function respondWithFilteredResult(_0x3fdd4b,_0x2eefe2){return function(_0x4503a2){if(_0x4503a2){var _0x137e52=typeof _0x2eefe2[_0x5f32('0x1b')]===_0x5f32('0x1c')&&typeof _0x2eefe2[_0x5f32('0x1d')]===_0x5f32('0x1c');var _0x588645=_0x4503a2['count'];var _0x15bd2d=_0x137e52?0x0:_0x2eefe2['offset'];var _0x2eeb6d=_0x137e52?_0x4503a2['count']:_0x2eefe2[_0x5f32('0x1b')]+_0x2eefe2[_0x5f32('0x1d')];var _0x2fee86;if(_0x2eeb6d>=_0x588645){_0x2eeb6d=_0x588645;_0x2fee86=0xc8;}else{_0x2fee86=0xce;}_0x3fdd4b['status'](_0x2fee86);return _0x3fdd4b[_0x5f32('0x1e')](_0x5f32('0x1f'),_0x15bd2d+'-'+_0x2eeb6d+'/'+_0x588645)['json'](_0x4503a2);}return null;};}function patchUpdates(_0x190bf6){return function(_0x2fa745){try{jsonpatch['apply'](_0x2fa745,_0x190bf6,!![]);}catch(_0x1de92e){return BPromise[_0x5f32('0x20')](_0x1de92e);}return _0x2fa745[_0x5f32('0x21')]();};}function saveUpdates(_0x59492b,_0x4cc156){return function(_0x4028df){if(_0x4028df){return _0x4028df['update'](_0x59492b)[_0x5f32('0x22')](function(_0x4dd94f){return _0x4dd94f;});}return null;};}function removeEntity(_0x2815bc,_0x334eac){return function(_0x13e8ed){if(_0x13e8ed){return _0x13e8ed[_0x5f32('0x23')]()[_0x5f32('0x22')](function(){_0x2815bc['status'](0xcc)[_0x5f32('0x19')]();});}};}function handleEntityNotFound(_0x2da4ea,_0x41bacd){return function(_0xf6b996){if(!_0xf6b996){_0x2da4ea['sendStatus'](0x194);}return _0xf6b996;};}function handleError(_0x3dc70b,_0x273ad3){_0x273ad3=_0x273ad3||0x1f4;return function(_0xf95869){logger['error'](_0xf95869[_0x5f32('0x24')]);if(_0xf95869[_0x5f32('0x25')]){delete _0xf95869[_0x5f32('0x25')];}_0x3dc70b[_0x5f32('0x18')](_0x273ad3)[_0x5f32('0x26')](_0xf95869);};}exports[_0x5f32('0x27')]=function(_0x21854d,_0x1dc12e){var _0x3c7122={},_0x1f4155={},_0x4e6a37={'count':0x0,'rows':[]};var _0x5419e8=_[_0x5f32('0x28')](db[_0x5f32('0x29')]['rawAttributes'],function(_0x5a3323){return{'name':_0x5a3323['fieldName'],'type':_0x5a3323['type']['key']};});_0x1f4155[_0x5f32('0x2a')]=_[_0x5f32('0x28')](_0x5419e8,_0x5f32('0x25'));_0x1f4155['query']=_[_0x5f32('0x2b')](_0x21854d['query']);_0x1f4155[_0x5f32('0x2c')]=_['intersection'](_0x1f4155[_0x5f32('0x2a')],_0x1f4155[_0x5f32('0x2d')]);_0x3c7122['attributes']=_[_0x5f32('0x2e')](_0x1f4155[_0x5f32('0x2a')],qs[_0x5f32('0x2f')](_0x21854d['query'][_0x5f32('0x2f')]));_0x3c7122['attributes']=_0x3c7122[_0x5f32('0x30')][_0x5f32('0x31')]?_0x3c7122['attributes']:_0x1f4155[_0x5f32('0x2a')];if(!_0x21854d[_0x5f32('0x2d')][_0x5f32('0x32')](_0x5f32('0x33'))){_0x3c7122['limit']=qs[_0x5f32('0x1d')](_0x21854d[_0x5f32('0x2d')][_0x5f32('0x1d')]);_0x3c7122[_0x5f32('0x1b')]=qs[_0x5f32('0x1b')](_0x21854d[_0x5f32('0x2d')][_0x5f32('0x1b')]);}_0x3c7122[_0x5f32('0x34')]=qs[_0x5f32('0x35')](_0x21854d[_0x5f32('0x2d')][_0x5f32('0x35')]);_0x3c7122[_0x5f32('0x36')]=qs[_0x5f32('0x2c')](_[_0x5f32('0x37')](_0x21854d['query'],_0x1f4155['filters']),_0x5419e8);if(_0x21854d[_0x5f32('0x2d')]['filter']){_0x3c7122[_0x5f32('0x36')]=_[_0x5f32('0x38')](_0x3c7122['where'],{'$or':_[_0x5f32('0x28')](_0x5419e8,function(_0x50080a){if(_0x50080a[_0x5f32('0x39')]!=='VIRTUAL'){var _0x176af1={};_0x176af1[_0x50080a[_0x5f32('0x25')]]={'$like':'%'+_0x21854d['query'][_0x5f32('0x3a')]+'%'};return _0x176af1;}})});}_0x3c7122=_['merge']({},_0x3c7122,_0x21854d['options']);var _0x637c75={'where':_0x3c7122[_0x5f32('0x36')]};return db[_0x5f32('0x29')][_0x5f32('0x3b')](_0x637c75)[_0x5f32('0x22')](function(_0x4fd483){_0x4e6a37[_0x5f32('0x3b')]=_0x4fd483;if(_0x21854d[_0x5f32('0x2d')]['includeAll']){_0x3c7122[_0x5f32('0x3c')]=[{'all':!![]}];}return db[_0x5f32('0x29')]['findAll'](_0x3c7122);})[_0x5f32('0x22')](function(_0x299146){_0x4e6a37[_0x5f32('0x3d')]=_0x299146;return _0x4e6a37;})['then'](respondWithFilteredResult(_0x1dc12e,_0x3c7122))[_0x5f32('0x3e')](handleError(_0x1dc12e,null));};exports[_0x5f32('0x3f')]=function(_0x4a5634,_0x5767d7){var _0x38ead6={'raw':!![],'where':{'id':_0x4a5634[_0x5f32('0x40')]['id']}},_0x442f7d={};_0x442f7d[_0x5f32('0x2a')]=_[_0x5f32('0x2b')](db[_0x5f32('0x29')][_0x5f32('0x41')]);_0x442f7d[_0x5f32('0x2d')]=_[_0x5f32('0x2b')](_0x4a5634[_0x5f32('0x2d')]);_0x442f7d[_0x5f32('0x2c')]=_[_0x5f32('0x2e')](_0x442f7d[_0x5f32('0x2a')],_0x442f7d[_0x5f32('0x2d')]);_0x38ead6[_0x5f32('0x30')]=_[_0x5f32('0x2e')](_0x442f7d[_0x5f32('0x2a')],qs['fields'](_0x4a5634[_0x5f32('0x2d')]['fields']));_0x38ead6[_0x5f32('0x30')]=_0x38ead6[_0x5f32('0x30')][_0x5f32('0x31')]?_0x38ead6[_0x5f32('0x30')]:_0x442f7d[_0x5f32('0x2a')];if(_0x4a5634['query'][_0x5f32('0x42')]){_0x38ead6[_0x5f32('0x3c')]=[{'all':!![]}];}_0x38ead6=_[_0x5f32('0x38')]({},_0x38ead6,_0x4a5634[_0x5f32('0x43')]);return db[_0x5f32('0x29')]['find'](_0x38ead6)[_0x5f32('0x22')](handleEntityNotFound(_0x5767d7,null))['then'](respondWithResult(_0x5767d7,null))[_0x5f32('0x3e')](handleError(_0x5767d7,null));};exports[_0x5f32('0x44')]=function(_0x274421,_0x97fc3d){return db[_0x5f32('0x29')][_0x5f32('0x44')](_0x274421[_0x5f32('0x45')],{})[_0x5f32('0x22')](respondWithResult(_0x97fc3d,0xc9))[_0x5f32('0x3e')](handleError(_0x97fc3d,null));};exports[_0x5f32('0x46')]=function(_0x3c66ed,_0x142e44){if(_0x3c66ed['body']['id']){delete _0x3c66ed['body']['id'];}return db[_0x5f32('0x29')][_0x5f32('0x47')]({'where':{'id':_0x3c66ed[_0x5f32('0x40')]['id']}})['then'](handleEntityNotFound(_0x142e44,null))[_0x5f32('0x22')](saveUpdates(_0x3c66ed[_0x5f32('0x45')],null))[_0x5f32('0x22')](respondWithResult(_0x142e44,null))[_0x5f32('0x3e')](handleError(_0x142e44,null));};exports[_0x5f32('0x23')]=function(_0x26ac88,_0x519269){return db[_0x5f32('0x29')][_0x5f32('0x47')]({'where':{'id':_0x26ac88[_0x5f32('0x40')]['id']}})[_0x5f32('0x22')](handleEntityNotFound(_0x519269,null))[_0x5f32('0x22')](removeEntity(_0x519269,null))[_0x5f32('0x3e')](handleError(_0x519269,null));};exports[_0x5f32('0x48')]=function(_0xbad4b4,_0x5ce243){return db['OpenchannelQueueReport'][_0x5f32('0x48')]()[_0x5f32('0x22')](respondWithResult(_0x5ce243,null))[_0x5f32('0x3e')](handleError(_0x5ce243,null));};