386c0bf1e13af82bb37c25340ef8e3a8d4c1e9b7
[motion2.git] / server / api / voiceAgentReport / voiceAgentReport.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 _0x643f=['querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../config/license/hardware','../../config/logger','api','../../config/environment','sendStatus','status','end','json','offset','limit','set','Content-Range','apply','reject','save','update','then','destroy','error','stack','name','send','VoiceAgentReport','rawAttributes','model','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','filter','map','type','merge','options','includeAll','include','findAll','catch','show','params','length','find','create','body','describe','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','mustache','util','path','to-csv','ejs','lodash','crypto','jsforce','desk.js'];(function(_0x124ac2,_0x2a859b){var _0x20c8a8=function(_0x58e110){while(--_0x58e110){_0x124ac2['push'](_0x124ac2['shift']());}};_0x20c8a8(++_0x2a859b);}(_0x643f,0x7e));var _0xf643=function(_0x460d91,_0x56a01b){_0x460d91=_0x460d91-0x0;var _0x39484b=_0x643f[_0x460d91];return _0x39484b;};'use strict';var pdf=require(_0xf643('0x0'));var emlformat=require(_0xf643('0x1'));var rimraf=require(_0xf643('0x2'));var zipdir=require(_0xf643('0x3'));var jsonpatch=require(_0xf643('0x4'));var rp=require('request-promise');var moment=require('moment');var BPromise=require('bluebird');var Mustache=require(_0xf643('0x5'));var util=require(_0xf643('0x6'));var path=require(_0xf643('0x7'));var sox=require('sox');var csv=require(_0xf643('0x8'));var ejs=require(_0xf643('0x9'));var fs=require('fs');var _=require(_0xf643('0xa'));var squel=require('squel');var crypto=require(_0xf643('0xb'));var jsforce=require(_0xf643('0xc'));var deskjs=require(_0xf643('0xd'));var toCsv=require(_0xf643('0x8'));var querystring=require(_0xf643('0xe'));var Papa=require(_0xf643('0xf'));var Redis=require(_0xf643('0x10'));var authService=require(_0xf643('0x11'));var qs=require(_0xf643('0x12'));var hardwareService=require(_0xf643('0x13'));var logger=require(_0xf643('0x14'))(_0xf643('0x15'));var utils=require('../../config/utils');var config=require(_0xf643('0x16'));var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x38f4df,_0x307c8d){_0x307c8d=_0x307c8d||0xcc;return function(_0x1d08c4){if(_0x1d08c4){return _0x38f4df[_0xf643('0x17')](_0x307c8d);}return _0x38f4df[_0xf643('0x18')](_0x307c8d)[_0xf643('0x19')]();};}function respondWithResult(_0x3e2e27,_0x29362e){_0x29362e=_0x29362e||0xc8;return function(_0x583d16){if(_0x583d16){return _0x3e2e27[_0xf643('0x18')](_0x29362e)[_0xf643('0x1a')](_0x583d16);}};}function respondWithFilteredResult(_0x1f8bf5,_0x12fe2c){return function(_0x157f4b){if(_0x157f4b){var _0x1d41da=_0x157f4b['count'],_0x448770=_0x12fe2c[_0xf643('0x1b')],_0x50d89a=_0x12fe2c[_0xf643('0x1b')]+_0x12fe2c[_0xf643('0x1c')],_0x32bcb2;if(_0x50d89a>=_0x1d41da){_0x50d89a=_0x1d41da;_0x32bcb2=0xc8;}else{_0x32bcb2=0xce;}_0x1f8bf5[_0xf643('0x18')](_0x32bcb2);return _0x1f8bf5[_0xf643('0x1d')](_0xf643('0x1e'),_0x448770+'-'+_0x50d89a+'/'+_0x1d41da)[_0xf643('0x1a')](_0x157f4b);}return null;};}function patchUpdates(_0x2a06cd){return function(_0x23ed48){try{jsonpatch[_0xf643('0x1f')](_0x23ed48,_0x2a06cd,!![]);}catch(_0x110c4c){return BPromise[_0xf643('0x20')](_0x110c4c);}return _0x23ed48[_0xf643('0x21')]();};}function saveUpdates(_0x12b604,_0x32220e){return function(_0x431dc6){if(_0x431dc6){return _0x431dc6[_0xf643('0x22')](_0x12b604)[_0xf643('0x23')](function(_0x294f80){return _0x294f80;});}return null;};}function removeEntity(_0x37f4dc,_0x338c7f){return function(_0x20a780){if(_0x20a780){return _0x20a780[_0xf643('0x24')]()[_0xf643('0x23')](function(){_0x37f4dc[_0xf643('0x18')](0xcc)[_0xf643('0x19')]();});}};}function handleEntityNotFound(_0x3bdb0a,_0x4a315d){return function(_0x369245){if(!_0x369245){_0x3bdb0a[_0xf643('0x17')](0x194);}return _0x369245;};}function handleError(_0x2816dd,_0x41965d){_0x41965d=_0x41965d||0x1f4;return function(_0x28899d){logger[_0xf643('0x25')](_0x28899d[_0xf643('0x26')]);if(_0x28899d[_0xf643('0x27')]){delete _0x28899d[_0xf643('0x27')];}_0x2816dd[_0xf643('0x18')](_0x41965d)[_0xf643('0x28')](_0x28899d);};}exports['index']=function(_0x5cfe36,_0x557c43){var _0x58504c={},_0x242957={},_0x464f54={'count':0x0,'rows':[]};var _0x8c568=db[_0xf643('0x29')][_0xf643('0x2a')];_0x242957[_0xf643('0x2b')]=_['keys'](_0x8c568);_0x242957[_0xf643('0x2c')]=_[_0xf643('0x2d')](_0x5cfe36[_0xf643('0x2c')]);_0x242957[_0xf643('0x2e')]=_[_0xf643('0x2f')](_0x242957['model'],_0x242957[_0xf643('0x2c')]);_0x58504c[_0xf643('0x30')]=_[_0xf643('0x2f')](_0x242957['model'],qs[_0xf643('0x31')](_0x5cfe36[_0xf643('0x2c')][_0xf643('0x31')]));_0x58504c[_0xf643('0x30')]=_0x58504c['attributes']['length']?_0x58504c['attributes']:_0x242957[_0xf643('0x2b')];if(!_0x5cfe36['query'][_0xf643('0x32')]('nolimit')){_0x58504c[_0xf643('0x1c')]=qs[_0xf643('0x1c')](_0x5cfe36[_0xf643('0x2c')][_0xf643('0x1c')]);_0x58504c[_0xf643('0x1b')]=qs[_0xf643('0x1b')](_0x5cfe36[_0xf643('0x2c')][_0xf643('0x1b')]);}_0x58504c[_0xf643('0x33')]=qs[_0xf643('0x34')](_0x5cfe36['query']['sort']);_0x58504c[_0xf643('0x35')]=qs['filters'](_['pick'](_0x5cfe36[_0xf643('0x2c')],_0x242957[_0xf643('0x2e')]));if(_0x5cfe36['query'][_0xf643('0x36')]){_0x58504c[_0xf643('0x35')]=_['merge'](_0x58504c[_0xf643('0x35')],{'$or':_[_0xf643('0x37')](_0x8c568,function(_0x402af3){if(_0x402af3[_0xf643('0x38')]['key']!=='VIRTUAL'){var _0x3e9df2={};_0x3e9df2[_0x402af3['field']]={'$like':'%'+_0x5cfe36['query'][_0xf643('0x36')]+'%'};return _0x3e9df2;}})});}_0x58504c=_[_0xf643('0x39')]({},_0x58504c,_0x5cfe36[_0xf643('0x3a')]);var _0x6dc7c3={'where':_0x58504c['where']};return db[_0xf643('0x29')]['count'](_0x6dc7c3)[_0xf643('0x23')](function(_0x345fc9){_0x464f54['count']=_0x345fc9;if(_0x5cfe36[_0xf643('0x2c')][_0xf643('0x3b')]){_0x58504c[_0xf643('0x3c')]=[{'all':!![]}];}return db[_0xf643('0x29')][_0xf643('0x3d')](_0x58504c);})[_0xf643('0x23')](function(_0x3f5660){_0x464f54['rows']=_0x3f5660;return _0x464f54;})[_0xf643('0x23')](respondWithFilteredResult(_0x557c43,_0x58504c))[_0xf643('0x3e')](handleError(_0x557c43,null));};exports[_0xf643('0x3f')]=function(_0x20bbe0,_0x4d412f){var _0x4d8a7e={'raw':![],'where':{'id':_0x20bbe0[_0xf643('0x40')]['id']}},_0x1be6e6={};_0x1be6e6[_0xf643('0x2b')]=_[_0xf643('0x2d')](db[_0xf643('0x29')][_0xf643('0x2a')]);_0x1be6e6['query']=_[_0xf643('0x2d')](_0x20bbe0[_0xf643('0x2c')]);_0x1be6e6[_0xf643('0x2e')]=_['intersection'](_0x1be6e6[_0xf643('0x2b')],_0x1be6e6[_0xf643('0x2c')]);_0x4d8a7e[_0xf643('0x30')]=_[_0xf643('0x2f')](_0x1be6e6[_0xf643('0x2b')],qs[_0xf643('0x31')](_0x20bbe0[_0xf643('0x2c')]['fields']));_0x4d8a7e['attributes']=_0x4d8a7e[_0xf643('0x30')][_0xf643('0x41')]?_0x4d8a7e[_0xf643('0x30')]:_0x1be6e6[_0xf643('0x2b')];if(_0x20bbe0[_0xf643('0x2c')][_0xf643('0x3b')]){_0x4d8a7e[_0xf643('0x3c')]=[{'all':!![]}];}_0x4d8a7e=_['merge']({},_0x4d8a7e,_0x20bbe0[_0xf643('0x3a')]);return db[_0xf643('0x29')][_0xf643('0x42')](_0x4d8a7e)['then'](handleEntityNotFound(_0x4d412f,null))[_0xf643('0x23')](respondWithResult(_0x4d412f,null))[_0xf643('0x3e')](handleError(_0x4d412f,null));};exports[_0xf643('0x43')]=function(_0x22235f,_0x550873){return db['VoiceAgentReport'][_0xf643('0x43')](_0x22235f[_0xf643('0x44')],{})['then'](respondWithResult(_0x550873,0xc9))[_0xf643('0x3e')](handleError(_0x550873,null));};exports[_0xf643('0x22')]=function(_0x1a9f1d,_0x1cdf6a){if(_0x1a9f1d[_0xf643('0x44')]['id']){delete _0x1a9f1d['body']['id'];}return db[_0xf643('0x29')][_0xf643('0x42')]({'where':{'id':_0x1a9f1d[_0xf643('0x40')]['id']}})[_0xf643('0x23')](handleEntityNotFound(_0x1cdf6a,null))[_0xf643('0x23')](saveUpdates(_0x1a9f1d['body'],null))[_0xf643('0x23')](respondWithResult(_0x1cdf6a,null))[_0xf643('0x3e')](handleError(_0x1cdf6a,null));};exports[_0xf643('0x24')]=function(_0x185a96,_0x28fc2d){return db[_0xf643('0x29')]['find']({'where':{'id':_0x185a96['params']['id']}})[_0xf643('0x23')](handleEntityNotFound(_0x28fc2d,null))[_0xf643('0x23')](removeEntity(_0x28fc2d,null))['catch'](handleError(_0x28fc2d,null));};exports[_0xf643('0x45')]=function(_0x202715,_0x523f63){return db[_0xf643('0x29')][_0xf643('0x45')]()[_0xf643('0x23')](respondWithResult(_0x523f63,null))[_0xf643('0x3e')](handleError(_0x523f63,null));};