Built motion from commit (unavailable).|2.5.22
[motion2.git] / server / api / analyticMetric / analyticMetric.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 _0xf587=['options','findAll','rows','catch','show','params','includeAll','include','find','create','body','user','role','userProfileId','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','eml-format','rimraf','fast-json-patch','bluebird','mustache','util','path','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','papaparse','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/license/util','../../mysqldb','sendStatus','status','end','count','offset','limit','set','Content-Range','json','apply','save','update','then','destroy','get','Metrics','UserProfileResource','error','stack','name','send','index','map','AnalyticMetric','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','nolimit','order','sort','pick','where','merge','VIRTUAL'];(function(_0x541260,_0x4c7f2e){var _0x1dd2b5=function(_0x4140de){while(--_0x4140de){_0x541260['push'](_0x541260['shift']());}};_0x1dd2b5(++_0x4c7f2e);}(_0xf587,0xb1));var _0x7f58=function(_0x3b938e,_0x330cf6){_0x3b938e=_0x3b938e-0x0;var _0x4fdbff=_0xf587[_0x3b938e];return _0x4fdbff;};'use strict';var pdf=require(_0x7f58('0x0'));var emlformat=require(_0x7f58('0x1'));var rimraf=require(_0x7f58('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x7f58('0x3'));var rp=require('request-promise');var moment=require('moment');var BPromise=require(_0x7f58('0x4'));var Mustache=require(_0x7f58('0x5'));var util=require(_0x7f58('0x6'));var path=require(_0x7f58('0x7'));var sox=require(_0x7f58('0x8'));var csv=require(_0x7f58('0x9'));var ejs=require(_0x7f58('0xa'));var fs=require('fs');var _=require(_0x7f58('0xb'));var squel=require(_0x7f58('0xc'));var crypto=require(_0x7f58('0xd'));var jsforce=require(_0x7f58('0xe'));var deskjs=require(_0x7f58('0xf'));var toCsv=require(_0x7f58('0x9'));var querystring=require('querystring');var Papa=require(_0x7f58('0x10'));var Redis=require('ioredis');var authService=require('../../components/auth/service');var qs=require(_0x7f58('0x11'));var as=require(_0x7f58('0x12'));var hardwareService=require(_0x7f58('0x13'));var logger=require('../../config/logger')(_0x7f58('0x14'));var utils=require(_0x7f58('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x7f58('0x16'));var db=require(_0x7f58('0x17'))['db'];function respondWithStatusCode(_0x41db56,_0x114913){_0x114913=_0x114913||0xcc;return function(_0x56e747){if(_0x56e747){return _0x41db56[_0x7f58('0x18')](_0x114913);}return _0x41db56[_0x7f58('0x19')](_0x114913)[_0x7f58('0x1a')]();};}function respondWithResult(_0x4e9c70,_0x954d7c){_0x954d7c=_0x954d7c||0xc8;return function(_0x4f3c71){if(_0x4f3c71){return _0x4e9c70[_0x7f58('0x19')](_0x954d7c)['json'](_0x4f3c71);}};}function respondWithFilteredResult(_0x56b57b,_0x48b46f){return function(_0x2931c6){if(_0x2931c6){var _0xd00e1f=_0x2931c6[_0x7f58('0x1b')],_0x1d711b=_0x48b46f[_0x7f58('0x1c')],_0x4ab2ab=_0x48b46f[_0x7f58('0x1c')]+_0x48b46f[_0x7f58('0x1d')],_0x3d3a5e;if(_0x4ab2ab>=_0xd00e1f){_0x4ab2ab=_0xd00e1f;_0x3d3a5e=0xc8;}else{_0x3d3a5e=0xce;}_0x56b57b['status'](_0x3d3a5e);return _0x56b57b[_0x7f58('0x1e')](_0x7f58('0x1f'),_0x1d711b+'-'+_0x4ab2ab+'/'+_0xd00e1f)[_0x7f58('0x20')](_0x2931c6);}return null;};}function patchUpdates(_0x5e6ff9){return function(_0x2fe71b){try{jsonpatch[_0x7f58('0x21')](_0x2fe71b,_0x5e6ff9,!![]);}catch(_0x475a20){return BPromise['reject'](_0x475a20);}return _0x2fe71b[_0x7f58('0x22')]();};}function saveUpdates(_0xf10483,_0x1dfbef){return function(_0x283fb5){if(_0x283fb5){return _0x283fb5[_0x7f58('0x23')](_0xf10483)[_0x7f58('0x24')](function(_0x331a8d){return _0x331a8d;});}return null;};}function removeEntity(_0x48dc42,_0x55eab3){return function(_0x593265){if(_0x593265){return _0x593265[_0x7f58('0x25')]()['then'](function(){var _0x529d60=_0x593265[_0x7f58('0x26')]({'plain':!![]});var _0x4e4ce=_0x7f58('0x27');return db[_0x7f58('0x28')][_0x7f58('0x25')]({'where':{'type':_0x4e4ce,'resourceId':_0x529d60['id']}})[_0x7f58('0x24')](function(){return _0x593265;});})[_0x7f58('0x24')](function(){_0x48dc42[_0x7f58('0x19')](0xcc)['end']();});}};}function handleEntityNotFound(_0x18ddfd,_0x3fcaf5){return function(_0x1cb83f){if(!_0x1cb83f){_0x18ddfd[_0x7f58('0x18')](0x194);}return _0x1cb83f;};}function handleError(_0x176acd,_0x2e37d7){_0x2e37d7=_0x2e37d7||0x1f4;return function(_0x935cb2){logger[_0x7f58('0x29')](_0x935cb2[_0x7f58('0x2a')]);if(_0x935cb2[_0x7f58('0x2b')]){delete _0x935cb2['name'];}_0x176acd[_0x7f58('0x19')](_0x2e37d7)[_0x7f58('0x2c')](_0x935cb2);};}exports[_0x7f58('0x2d')]=function(_0x527de7,_0x23521b){var _0x1a64c9={},_0x648c1c={},_0x3744b9={'count':0x0,'rows':[]};var _0x56d231=_[_0x7f58('0x2e')](db[_0x7f58('0x2f')][_0x7f58('0x30')],function(_0x1d0f48){return{'name':_0x1d0f48[_0x7f58('0x31')],'type':_0x1d0f48[_0x7f58('0x32')][_0x7f58('0x33')]};});_0x648c1c[_0x7f58('0x34')]=_[_0x7f58('0x2e')](_0x56d231,_0x7f58('0x2b'));_0x648c1c[_0x7f58('0x35')]=_[_0x7f58('0x36')](_0x527de7[_0x7f58('0x35')]);_0x648c1c[_0x7f58('0x37')]=_[_0x7f58('0x38')](_0x648c1c['model'],_0x648c1c[_0x7f58('0x35')]);_0x1a64c9['attributes']=_[_0x7f58('0x38')](_0x648c1c[_0x7f58('0x34')],qs['fields'](_0x527de7[_0x7f58('0x35')][_0x7f58('0x39')]));_0x1a64c9['attributes']=_0x1a64c9[_0x7f58('0x3a')]['length']?_0x1a64c9['attributes']:_0x648c1c[_0x7f58('0x34')];if(!_0x527de7[_0x7f58('0x35')]['hasOwnProperty'](_0x7f58('0x3b'))){_0x1a64c9[_0x7f58('0x1d')]=qs[_0x7f58('0x1d')](_0x527de7[_0x7f58('0x35')][_0x7f58('0x1d')]);_0x1a64c9[_0x7f58('0x1c')]=qs[_0x7f58('0x1c')](_0x527de7['query'][_0x7f58('0x1c')]);}_0x1a64c9[_0x7f58('0x3c')]=qs[_0x7f58('0x3d')](_0x527de7['query'][_0x7f58('0x3d')]);_0x1a64c9['where']=qs['filters'](_[_0x7f58('0x3e')](_0x527de7[_0x7f58('0x35')],_0x648c1c[_0x7f58('0x37')]),_0x56d231);if(_0x527de7[_0x7f58('0x35')]['filter']){_0x1a64c9[_0x7f58('0x3f')]=_[_0x7f58('0x40')](_0x1a64c9['where'],{'$or':_['map'](_0x56d231,function(_0x115d3c){if(_0x115d3c[_0x7f58('0x32')]!==_0x7f58('0x41')){var _0x32c75d={};_0x32c75d[_0x115d3c[_0x7f58('0x2b')]]={'$like':'%'+_0x527de7[_0x7f58('0x35')]['filter']+'%'};return _0x32c75d;}})});}_0x1a64c9=_[_0x7f58('0x40')]({},_0x1a64c9,_0x527de7[_0x7f58('0x42')]);var _0x27dcea={'where':_0x1a64c9[_0x7f58('0x3f')]};return db[_0x7f58('0x2f')][_0x7f58('0x1b')](_0x27dcea)[_0x7f58('0x24')](function(_0x52fb83){_0x3744b9['count']=_0x52fb83;if(_0x527de7[_0x7f58('0x35')]['includeAll']){_0x1a64c9['include']=[{'all':!![]}];}return db[_0x7f58('0x2f')][_0x7f58('0x43')](_0x1a64c9);})[_0x7f58('0x24')](function(_0x2e83a3){_0x3744b9[_0x7f58('0x44')]=_0x2e83a3;return _0x3744b9;})[_0x7f58('0x24')](respondWithFilteredResult(_0x23521b,_0x1a64c9))[_0x7f58('0x45')](handleError(_0x23521b,null));};exports[_0x7f58('0x46')]=function(_0x598bf7,_0x55a2fd){var _0x55b461={'raw':!![],'where':{'id':_0x598bf7[_0x7f58('0x47')]['id']}},_0x520bb2={};_0x520bb2[_0x7f58('0x34')]=_[_0x7f58('0x36')](db[_0x7f58('0x2f')][_0x7f58('0x30')]);_0x520bb2['query']=_['keys'](_0x598bf7[_0x7f58('0x35')]);_0x520bb2[_0x7f58('0x37')]=_[_0x7f58('0x38')](_0x520bb2[_0x7f58('0x34')],_0x520bb2[_0x7f58('0x35')]);_0x55b461[_0x7f58('0x3a')]=_[_0x7f58('0x38')](_0x520bb2[_0x7f58('0x34')],qs[_0x7f58('0x39')](_0x598bf7[_0x7f58('0x35')][_0x7f58('0x39')]));_0x55b461[_0x7f58('0x3a')]=_0x55b461[_0x7f58('0x3a')]['length']?_0x55b461[_0x7f58('0x3a')]:_0x520bb2['model'];if(_0x598bf7[_0x7f58('0x35')][_0x7f58('0x48')]){_0x55b461[_0x7f58('0x49')]=[{'all':!![]}];}_0x55b461=_[_0x7f58('0x40')]({},_0x55b461,_0x598bf7[_0x7f58('0x42')]);return db[_0x7f58('0x2f')][_0x7f58('0x4a')](_0x55b461)[_0x7f58('0x24')](handleEntityNotFound(_0x55a2fd,null))[_0x7f58('0x24')](respondWithResult(_0x55a2fd,null))['catch'](handleError(_0x55a2fd,null));};exports[_0x7f58('0x4b')]=function(_0x311863,_0x5bc3a9){return db[_0x7f58('0x2f')][_0x7f58('0x4b')](_0x311863[_0x7f58('0x4c')],{})['then'](function(_0x20b07b){var _0x9f8f4=_0x311863[_0x7f58('0x4d')][_0x7f58('0x26')]({'plain':!![]});if(!_0x9f8f4)throw new Error('Unable\x20to\x20retrieve\x20the\x20current\x20user');if(_0x9f8f4[_0x7f58('0x4e')]===_0x7f58('0x4d')){var _0x391782=_0x20b07b[_0x7f58('0x26')]({'plain':!![]});var _0x3e7b6d=_0x7f58('0x27');return db['UserProfileSection'][_0x7f58('0x4a')]({'where':{'name':_0x3e7b6d,'userProfileId':_0x9f8f4[_0x7f58('0x4f')]},'raw':!![]})[_0x7f58('0x24')](function(_0x291d07){if(_0x291d07&&_0x291d07['autoAssociation']===0x0){return db[_0x7f58('0x28')][_0x7f58('0x4b')]({'name':_0x391782[_0x7f58('0x2b')],'resourceId':_0x391782['id'],'type':_0x291d07['name'],'sectionId':_0x291d07['id']},{})['then'](function(){return _0x20b07b;});}else{return _0x20b07b;}})[_0x7f58('0x45')](function(_0x34a427){logger[_0x7f58('0x29')](_0x7f58('0x50'),_0x34a427);throw _0x34a427;});}return _0x20b07b;})['then'](respondWithResult(_0x5bc3a9,0xc9))['catch'](handleError(_0x5bc3a9,null));};exports[_0x7f58('0x23')]=function(_0x36f1de,_0x47f538){if(_0x36f1de[_0x7f58('0x4c')]['id']){delete _0x36f1de[_0x7f58('0x4c')]['id'];}return db['AnalyticMetric'][_0x7f58('0x4a')]({'where':{'id':_0x36f1de['params']['id']}})[_0x7f58('0x24')](handleEntityNotFound(_0x47f538,null))[_0x7f58('0x24')](saveUpdates(_0x36f1de[_0x7f58('0x4c')],null))[_0x7f58('0x24')](respondWithResult(_0x47f538,null))[_0x7f58('0x45')](handleError(_0x47f538,null));};exports[_0x7f58('0x25')]=function(_0x6366ab,_0x351b2a){return db[_0x7f58('0x2f')][_0x7f58('0x4a')]({'where':{'id':_0x6366ab[_0x7f58('0x47')]['id']}})['then'](handleEntityNotFound(_0x351b2a,null))[_0x7f58('0x24')](removeEntity(_0x351b2a,null))['catch'](handleError(_0x351b2a,null));};