52559ce13ce26d11660b891ec7034c49688845da
[motion2.git] / server / api / chatQueueReport / chatQueueReport.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 _0xf417=['params','intersection','find','create','body','update','describe','rimraf','zip-dir','fast-json-patch','moment','util','fs-extra','squel','crypto','desk.js','querystring','ioredis','../../components/auth/service','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','end','status','json','offset','undefined','count','limit','set','apply','reject','save','destroy','then','error','stack','send','map','rawAttributes','fieldName','name','query','keys','filters','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','VIRTUAL','filter','merge','options','ChatQueueReport','includeAll','include','findAll','rows','catch','show'];(function(_0x5760dc,_0x3828c3){var _0x446ae0=function(_0x122a96){while(--_0x122a96){_0x5760dc['push'](_0x5760dc['shift']());}};_0x446ae0(++_0x3828c3);}(_0xf417,0x8f));var _0x7f41=function(_0x21a5ff,_0x571074){_0x21a5ff=_0x21a5ff-0x0;var _0x1f9af8=_0xf417[_0x21a5ff];return _0x1f9af8;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x7f41('0x0'));var zipdir=require(_0x7f41('0x1'));var jsonpatch=require(_0x7f41('0x2'));var rp=require('request-promise');var moment=require(_0x7f41('0x3'));var BPromise=require('bluebird');var Mustache=require('mustache');var util=require(_0x7f41('0x4'));var path=require('path');var sox=require('sox');var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var fs_extra=require(_0x7f41('0x5'));var _=require('lodash');var squel=require(_0x7f41('0x6'));var crypto=require(_0x7f41('0x7'));var jsforce=require('jsforce');var deskjs=require(_0x7f41('0x8'));var toCsv=require('to-csv');var querystring=require(_0x7f41('0x9'));var Papa=require('papaparse');var Redis=require(_0x7f41('0xa'));var authService=require(_0x7f41('0xb'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0x7f41('0xc'));var logger=require('../../config/logger')('api');var utils=require(_0x7f41('0xd'));var config=require(_0x7f41('0xe'));var licenseUtil=require(_0x7f41('0xf'));var db=require(_0x7f41('0x10'))['db'];function respondWithStatusCode(_0x637b2d,_0x46dcfe){_0x46dcfe=_0x46dcfe||0xcc;return function(_0xf2f383){if(_0xf2f383){return _0x637b2d['sendStatus'](_0x46dcfe);}return _0x637b2d['status'](_0x46dcfe)[_0x7f41('0x11')]();};}function respondWithResult(_0x4f5b74,_0x568eea){_0x568eea=_0x568eea||0xc8;return function(_0x466907){if(_0x466907){return _0x4f5b74[_0x7f41('0x12')](_0x568eea)[_0x7f41('0x13')](_0x466907);}};}function respondWithFilteredResult(_0x5a517f,_0x212b28){return function(_0x5ef6a7){if(_0x5ef6a7){var _0x27c0f6=typeof _0x212b28[_0x7f41('0x14')]===_0x7f41('0x15')&&typeof _0x212b28['limit']===_0x7f41('0x15');var _0x1ae462=_0x5ef6a7[_0x7f41('0x16')];var _0x5434d2=_0x27c0f6?0x0:_0x212b28[_0x7f41('0x14')];var _0x26580c=_0x27c0f6?_0x5ef6a7['count']:_0x212b28[_0x7f41('0x14')]+_0x212b28[_0x7f41('0x17')];var _0x1f4af0;if(_0x26580c>=_0x1ae462){_0x26580c=_0x1ae462;_0x1f4af0=0xc8;}else{_0x1f4af0=0xce;}_0x5a517f['status'](_0x1f4af0);return _0x5a517f[_0x7f41('0x18')]('Content-Range',_0x5434d2+'-'+_0x26580c+'/'+_0x1ae462)['json'](_0x5ef6a7);}return null;};}function patchUpdates(_0x3fe620){return function(_0x7de9c2){try{jsonpatch[_0x7f41('0x19')](_0x7de9c2,_0x3fe620,!![]);}catch(_0x21660b){return BPromise[_0x7f41('0x1a')](_0x21660b);}return _0x7de9c2[_0x7f41('0x1b')]();};}function saveUpdates(_0x5e0f8b,_0x5e568d){return function(_0x3e8000){if(_0x3e8000){return _0x3e8000['update'](_0x5e0f8b)['then'](function(_0xb27d9c){return _0xb27d9c;});}return null;};}function removeEntity(_0x388946,_0x4fdd78){return function(_0x3f3ee0){if(_0x3f3ee0){return _0x3f3ee0[_0x7f41('0x1c')]()[_0x7f41('0x1d')](function(){_0x388946[_0x7f41('0x12')](0xcc)[_0x7f41('0x11')]();});}};}function handleEntityNotFound(_0x4cbee7,_0x57a302){return function(_0x4dbed0){if(!_0x4dbed0){_0x4cbee7['sendStatus'](0x194);}return _0x4dbed0;};}function handleError(_0x16b410,_0x183ac7){_0x183ac7=_0x183ac7||0x1f4;return function(_0x55a32a){logger[_0x7f41('0x1e')](_0x55a32a[_0x7f41('0x1f')]);if(_0x55a32a['name']){delete _0x55a32a['name'];}_0x16b410['status'](_0x183ac7)[_0x7f41('0x20')](_0x55a32a);};}exports['index']=function(_0x4ee09e,_0x501076){var _0x3889b1={},_0x379dbe={},_0x4fa7e8={'count':0x0,'rows':[]};var _0x2b93e4=_[_0x7f41('0x21')](db['ChatQueueReport'][_0x7f41('0x22')],function(_0x1c33fb){return{'name':_0x1c33fb[_0x7f41('0x23')],'type':_0x1c33fb['type']['key']};});_0x379dbe['model']=_[_0x7f41('0x21')](_0x2b93e4,_0x7f41('0x24'));_0x379dbe[_0x7f41('0x25')]=_[_0x7f41('0x26')](_0x4ee09e[_0x7f41('0x25')]);_0x379dbe[_0x7f41('0x27')]=_['intersection'](_0x379dbe[_0x7f41('0x28')],_0x379dbe[_0x7f41('0x25')]);_0x3889b1[_0x7f41('0x29')]=_['intersection'](_0x379dbe[_0x7f41('0x28')],qs['fields'](_0x4ee09e[_0x7f41('0x25')][_0x7f41('0x2a')]));_0x3889b1[_0x7f41('0x29')]=_0x3889b1['attributes'][_0x7f41('0x2b')]?_0x3889b1[_0x7f41('0x29')]:_0x379dbe[_0x7f41('0x28')];if(!_0x4ee09e[_0x7f41('0x25')][_0x7f41('0x2c')](_0x7f41('0x2d'))){_0x3889b1[_0x7f41('0x17')]=qs[_0x7f41('0x17')](_0x4ee09e['query'][_0x7f41('0x17')]);_0x3889b1[_0x7f41('0x14')]=qs[_0x7f41('0x14')](_0x4ee09e[_0x7f41('0x25')][_0x7f41('0x14')]);}_0x3889b1[_0x7f41('0x2e')]=qs[_0x7f41('0x2f')](_0x4ee09e[_0x7f41('0x25')][_0x7f41('0x2f')]);_0x3889b1[_0x7f41('0x30')]=qs[_0x7f41('0x27')](_[_0x7f41('0x31')](_0x4ee09e['query'],_0x379dbe[_0x7f41('0x27')]),_0x2b93e4);if(_0x4ee09e[_0x7f41('0x25')]['filter']){_0x3889b1[_0x7f41('0x30')]=_['merge'](_0x3889b1[_0x7f41('0x30')],{'$or':_[_0x7f41('0x21')](_0x2b93e4,function(_0x2d2c62){if(_0x2d2c62['type']!==_0x7f41('0x32')){var _0x18ed9a={};_0x18ed9a[_0x2d2c62['name']]={'$like':'%'+_0x4ee09e['query'][_0x7f41('0x33')]+'%'};return _0x18ed9a;}})});}_0x3889b1=_[_0x7f41('0x34')]({},_0x3889b1,_0x4ee09e[_0x7f41('0x35')]);var _0x33f9d5={'where':_0x3889b1[_0x7f41('0x30')]};return db[_0x7f41('0x36')][_0x7f41('0x16')](_0x33f9d5)[_0x7f41('0x1d')](function(_0x2ea20d){_0x4fa7e8['count']=_0x2ea20d;if(_0x4ee09e[_0x7f41('0x25')][_0x7f41('0x37')]){_0x3889b1[_0x7f41('0x38')]=[{'all':!![]}];}return db[_0x7f41('0x36')][_0x7f41('0x39')](_0x3889b1);})[_0x7f41('0x1d')](function(_0x5a2d93){_0x4fa7e8[_0x7f41('0x3a')]=_0x5a2d93;return _0x4fa7e8;})[_0x7f41('0x1d')](respondWithFilteredResult(_0x501076,_0x3889b1))[_0x7f41('0x3b')](handleError(_0x501076,null));};exports[_0x7f41('0x3c')]=function(_0x58235e,_0x51067c){var _0xd4d821={'raw':!![],'where':{'id':_0x58235e[_0x7f41('0x3d')]['id']}},_0x3a87a0={};_0x3a87a0['model']=_[_0x7f41('0x26')](db[_0x7f41('0x36')]['rawAttributes']);_0x3a87a0[_0x7f41('0x25')]=_[_0x7f41('0x26')](_0x58235e[_0x7f41('0x25')]);_0x3a87a0[_0x7f41('0x27')]=_['intersection'](_0x3a87a0[_0x7f41('0x28')],_0x3a87a0['query']);_0xd4d821[_0x7f41('0x29')]=_[_0x7f41('0x3e')](_0x3a87a0[_0x7f41('0x28')],qs[_0x7f41('0x2a')](_0x58235e['query'][_0x7f41('0x2a')]));_0xd4d821[_0x7f41('0x29')]=_0xd4d821[_0x7f41('0x29')]['length']?_0xd4d821[_0x7f41('0x29')]:_0x3a87a0['model'];if(_0x58235e['query'][_0x7f41('0x37')]){_0xd4d821[_0x7f41('0x38')]=[{'all':!![]}];}_0xd4d821=_[_0x7f41('0x34')]({},_0xd4d821,_0x58235e[_0x7f41('0x35')]);return db[_0x7f41('0x36')][_0x7f41('0x3f')](_0xd4d821)[_0x7f41('0x1d')](handleEntityNotFound(_0x51067c,null))[_0x7f41('0x1d')](respondWithResult(_0x51067c,null))[_0x7f41('0x3b')](handleError(_0x51067c,null));};exports[_0x7f41('0x40')]=function(_0x319a90,_0x12d73f){return db['ChatQueueReport'][_0x7f41('0x40')](_0x319a90[_0x7f41('0x41')],{})[_0x7f41('0x1d')](respondWithResult(_0x12d73f,0xc9))[_0x7f41('0x3b')](handleError(_0x12d73f,null));};exports[_0x7f41('0x42')]=function(_0x3a0b0a,_0x12ac2d){if(_0x3a0b0a[_0x7f41('0x41')]['id']){delete _0x3a0b0a[_0x7f41('0x41')]['id'];}return db['ChatQueueReport'][_0x7f41('0x3f')]({'where':{'id':_0x3a0b0a['params']['id']}})['then'](handleEntityNotFound(_0x12ac2d,null))[_0x7f41('0x1d')](saveUpdates(_0x3a0b0a[_0x7f41('0x41')],null))[_0x7f41('0x1d')](respondWithResult(_0x12ac2d,null))['catch'](handleError(_0x12ac2d,null));};exports[_0x7f41('0x1c')]=function(_0x2d20b2,_0x398e57){return db[_0x7f41('0x36')]['find']({'where':{'id':_0x2d20b2[_0x7f41('0x3d')]['id']}})['then'](handleEntityNotFound(_0x398e57,null))[_0x7f41('0x1d')](removeEntity(_0x398e57,null))[_0x7f41('0x3b')](handleError(_0x398e57,null));};exports['describe']=function(_0x2ced2f,_0x1f885b){return db[_0x7f41('0x36')][_0x7f41('0x43')]()['then'](respondWithResult(_0x1f885b,null))['catch'](handleError(_0x1f885b,null));};