Built motion from commit (unavailable).|2.5.14
[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 _0xf0cf=['../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','sendStatus','status','end','json','count','offset','apply','save','then','destroy','get','Metrics','UserProfileResource','error','name','send','AnalyticMetric','type','key','model','map','query','keys','filters','attributes','intersection','fields','hasOwnProperty','limit','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','rows','catch','show','params','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','UserProfileSection','update','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','crypto','jsforce','desk.js','to-csv','papaparse','../../components/auth/service','../../config/license/hardware','api'];(function(_0xd649c1,_0x328221){var _0x17a73f=function(_0x5aad7e){while(--_0x5aad7e){_0xd649c1['push'](_0xd649c1['shift']());}};_0x17a73f(++_0x328221);}(_0xf0cf,0x1e5));var _0xff0c=function(_0x3a59e6,_0x16069a){_0x3a59e6=_0x3a59e6-0x0;var _0x5550b1=_0xf0cf[_0x3a59e6];return _0x5550b1;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xff0c('0x0'));var rimraf=require(_0xff0c('0x1'));var zipdir=require(_0xff0c('0x2'));var jsonpatch=require(_0xff0c('0x3'));var rp=require(_0xff0c('0x4'));var moment=require(_0xff0c('0x5'));var BPromise=require(_0xff0c('0x6'));var Mustache=require(_0xff0c('0x7'));var util=require(_0xff0c('0x8'));var path=require(_0xff0c('0x9'));var sox=require(_0xff0c('0xa'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require(_0xff0c('0xb'));var jsforce=require(_0xff0c('0xc'));var deskjs=require(_0xff0c('0xd'));var toCsv=require(_0xff0c('0xe'));var querystring=require('querystring');var Papa=require(_0xff0c('0xf'));var Redis=require('ioredis');var authService=require(_0xff0c('0x10'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xff0c('0x11'));var logger=require('../../config/logger')(_0xff0c('0x12'));var utils=require(_0xff0c('0x13'));var config=require(_0xff0c('0x14'));var licenseUtil=require(_0xff0c('0x15'));var db=require(_0xff0c('0x16'))['db'];function respondWithStatusCode(_0x2101e1,_0x3ddbd0){_0x3ddbd0=_0x3ddbd0||0xcc;return function(_0x44068f){if(_0x44068f){return _0x2101e1[_0xff0c('0x17')](_0x3ddbd0);}return _0x2101e1[_0xff0c('0x18')](_0x3ddbd0)[_0xff0c('0x19')]();};}function respondWithResult(_0x64f5da,_0x14d93d){_0x14d93d=_0x14d93d||0xc8;return function(_0x17020a){if(_0x17020a){return _0x64f5da[_0xff0c('0x18')](_0x14d93d)[_0xff0c('0x1a')](_0x17020a);}};}function respondWithFilteredResult(_0x4f537c,_0x4487ba){return function(_0x37d3a1){if(_0x37d3a1){var _0x5d6c6d=_0x37d3a1[_0xff0c('0x1b')],_0xbe055b=_0x4487ba[_0xff0c('0x1c')],_0x2154f2=_0x4487ba['offset']+_0x4487ba['limit'],_0x2d3cd1;if(_0x2154f2>=_0x5d6c6d){_0x2154f2=_0x5d6c6d;_0x2d3cd1=0xc8;}else{_0x2d3cd1=0xce;}_0x4f537c['status'](_0x2d3cd1);return _0x4f537c['set']('Content-Range',_0xbe055b+'-'+_0x2154f2+'/'+_0x5d6c6d)[_0xff0c('0x1a')](_0x37d3a1);}return null;};}function patchUpdates(_0x144574){return function(_0x25aee6){try{jsonpatch[_0xff0c('0x1d')](_0x25aee6,_0x144574,!![]);}catch(_0x234c98){return BPromise['reject'](_0x234c98);}return _0x25aee6[_0xff0c('0x1e')]();};}function saveUpdates(_0x454057,_0x525502){return function(_0x55ffd4){if(_0x55ffd4){return _0x55ffd4['update'](_0x454057)[_0xff0c('0x1f')](function(_0x4ea3a){return _0x4ea3a;});}return null;};}function removeEntity(_0x14ef08,_0x50eb8e){return function(_0x253e18){if(_0x253e18){return _0x253e18[_0xff0c('0x20')]()['then'](function(){var _0x21f60a=_0x253e18[_0xff0c('0x21')]({'plain':!![]});var _0x2f3c7a=_0xff0c('0x22');return db[_0xff0c('0x23')][_0xff0c('0x20')]({'where':{'type':_0x2f3c7a,'resourceId':_0x21f60a['id']}})[_0xff0c('0x1f')](function(){return _0x253e18;});})[_0xff0c('0x1f')](function(){_0x14ef08[_0xff0c('0x18')](0xcc)[_0xff0c('0x19')]();});}};}function handleEntityNotFound(_0x3b0d88,_0x38fac1){return function(_0x113e21){if(!_0x113e21){_0x3b0d88['sendStatus'](0x194);}return _0x113e21;};}function handleError(_0x4782b5,_0x20a520){_0x20a520=_0x20a520||0x1f4;return function(_0x29c376){logger[_0xff0c('0x24')](_0x29c376['stack']);if(_0x29c376[_0xff0c('0x25')]){delete _0x29c376[_0xff0c('0x25')];}_0x4782b5['status'](_0x20a520)[_0xff0c('0x26')](_0x29c376);};}exports['index']=function(_0x2eb28a,_0x28f179){var _0xb680f5={},_0xe61ea7={},_0x25ed74={'count':0x0,'rows':[]};var _0x5f315b=_['map'](db[_0xff0c('0x27')]['rawAttributes'],function(_0x1077da){return{'name':_0x1077da['fieldName'],'type':_0x1077da[_0xff0c('0x28')][_0xff0c('0x29')]};});_0xe61ea7[_0xff0c('0x2a')]=_[_0xff0c('0x2b')](_0x5f315b,_0xff0c('0x25'));_0xe61ea7[_0xff0c('0x2c')]=_[_0xff0c('0x2d')](_0x2eb28a[_0xff0c('0x2c')]);_0xe61ea7[_0xff0c('0x2e')]=_['intersection'](_0xe61ea7[_0xff0c('0x2a')],_0xe61ea7[_0xff0c('0x2c')]);_0xb680f5[_0xff0c('0x2f')]=_[_0xff0c('0x30')](_0xe61ea7[_0xff0c('0x2a')],qs[_0xff0c('0x31')](_0x2eb28a[_0xff0c('0x2c')][_0xff0c('0x31')]));_0xb680f5[_0xff0c('0x2f')]=_0xb680f5[_0xff0c('0x2f')]['length']?_0xb680f5[_0xff0c('0x2f')]:_0xe61ea7[_0xff0c('0x2a')];if(!_0x2eb28a[_0xff0c('0x2c')][_0xff0c('0x32')]('nolimit')){_0xb680f5[_0xff0c('0x33')]=qs[_0xff0c('0x33')](_0x2eb28a[_0xff0c('0x2c')][_0xff0c('0x33')]);_0xb680f5[_0xff0c('0x1c')]=qs[_0xff0c('0x1c')](_0x2eb28a[_0xff0c('0x2c')][_0xff0c('0x1c')]);}_0xb680f5['order']=qs[_0xff0c('0x34')](_0x2eb28a[_0xff0c('0x2c')][_0xff0c('0x34')]);_0xb680f5['where']=qs[_0xff0c('0x2e')](_[_0xff0c('0x35')](_0x2eb28a[_0xff0c('0x2c')],_0xe61ea7[_0xff0c('0x2e')]),_0x5f315b);if(_0x2eb28a['query'][_0xff0c('0x36')]){_0xb680f5[_0xff0c('0x37')]=_[_0xff0c('0x38')](_0xb680f5['where'],{'$or':_[_0xff0c('0x2b')](_0x5f315b,function(_0x52b9fb){if(_0x52b9fb['type']!==_0xff0c('0x39')){var _0x21e5be={};_0x21e5be[_0x52b9fb[_0xff0c('0x25')]]={'$like':'%'+_0x2eb28a['query'][_0xff0c('0x36')]+'%'};return _0x21e5be;}})});}_0xb680f5=_[_0xff0c('0x38')]({},_0xb680f5,_0x2eb28a[_0xff0c('0x3a')]);var _0x4990f8={'where':_0xb680f5['where']};return db[_0xff0c('0x27')]['count'](_0x4990f8)[_0xff0c('0x1f')](function(_0x2ac71){_0x25ed74[_0xff0c('0x1b')]=_0x2ac71;if(_0x2eb28a[_0xff0c('0x2c')][_0xff0c('0x3b')]){_0xb680f5[_0xff0c('0x3c')]=[{'all':!![]}];}return db[_0xff0c('0x27')]['findAll'](_0xb680f5);})[_0xff0c('0x1f')](function(_0x273bd5){_0x25ed74[_0xff0c('0x3d')]=_0x273bd5;return _0x25ed74;})[_0xff0c('0x1f')](respondWithFilteredResult(_0x28f179,_0xb680f5))[_0xff0c('0x3e')](handleError(_0x28f179,null));};exports[_0xff0c('0x3f')]=function(_0x89f244,_0x45a729){var _0x28679f={'raw':!![],'where':{'id':_0x89f244[_0xff0c('0x40')]['id']}},_0x4be10b={};_0x4be10b['model']=_[_0xff0c('0x2d')](db[_0xff0c('0x27')]['rawAttributes']);_0x4be10b['query']=_[_0xff0c('0x2d')](_0x89f244[_0xff0c('0x2c')]);_0x4be10b[_0xff0c('0x2e')]=_[_0xff0c('0x30')](_0x4be10b[_0xff0c('0x2a')],_0x4be10b[_0xff0c('0x2c')]);_0x28679f[_0xff0c('0x2f')]=_[_0xff0c('0x30')](_0x4be10b[_0xff0c('0x2a')],qs['fields'](_0x89f244[_0xff0c('0x2c')]['fields']));_0x28679f['attributes']=_0x28679f[_0xff0c('0x2f')]['length']?_0x28679f[_0xff0c('0x2f')]:_0x4be10b['model'];if(_0x89f244[_0xff0c('0x2c')][_0xff0c('0x3b')]){_0x28679f[_0xff0c('0x3c')]=[{'all':!![]}];}_0x28679f=_[_0xff0c('0x38')]({},_0x28679f,_0x89f244[_0xff0c('0x3a')]);return db[_0xff0c('0x27')][_0xff0c('0x41')](_0x28679f)[_0xff0c('0x1f')](handleEntityNotFound(_0x45a729,null))[_0xff0c('0x1f')](respondWithResult(_0x45a729,null))['catch'](handleError(_0x45a729,null));};exports[_0xff0c('0x42')]=function(_0x5b9bb6,_0x1ee54d){return db[_0xff0c('0x27')][_0xff0c('0x42')](_0x5b9bb6[_0xff0c('0x43')],{})[_0xff0c('0x1f')](function(_0x408c96){var _0x4a96db=_0x5b9bb6[_0xff0c('0x44')][_0xff0c('0x21')]({'plain':!![]});if(!_0x4a96db)throw new Error(_0xff0c('0x45'));if(_0x4a96db['role']===_0xff0c('0x44')){var _0x43a432=_0x408c96[_0xff0c('0x21')]({'plain':!![]});var _0x130b60=_0xff0c('0x22');return db[_0xff0c('0x46')][_0xff0c('0x41')]({'where':{'name':_0x130b60,'userProfileId':_0x4a96db['userProfileId']},'raw':!![]})[_0xff0c('0x1f')](function(_0x319deb){if(_0x319deb&&_0x319deb['autoAssociation']===0x0){return db[_0xff0c('0x23')][_0xff0c('0x42')]({'name':_0x43a432[_0xff0c('0x25')],'resourceId':_0x43a432['id'],'type':_0x319deb[_0xff0c('0x25')],'sectionId':_0x319deb['id']},{})[_0xff0c('0x1f')](function(){return _0x408c96;});}else{return _0x408c96;}})[_0xff0c('0x3e')](function(_0x20be36){logger[_0xff0c('0x24')]('Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s',_0x20be36);throw _0x20be36;});}return _0x408c96;})[_0xff0c('0x1f')](respondWithResult(_0x1ee54d,0xc9))[_0xff0c('0x3e')](handleError(_0x1ee54d,null));};exports[_0xff0c('0x47')]=function(_0x23610c,_0x44743c){if(_0x23610c[_0xff0c('0x43')]['id']){delete _0x23610c[_0xff0c('0x43')]['id'];}return db[_0xff0c('0x27')][_0xff0c('0x41')]({'where':{'id':_0x23610c[_0xff0c('0x40')]['id']}})['then'](handleEntityNotFound(_0x44743c,null))['then'](saveUpdates(_0x23610c[_0xff0c('0x43')],null))[_0xff0c('0x1f')](respondWithResult(_0x44743c,null))['catch'](handleError(_0x44743c,null));};exports[_0xff0c('0x20')]=function(_0x59d9fa,_0x184108){return db[_0xff0c('0x27')]['find']({'where':{'id':_0x59d9fa['params']['id']}})[_0xff0c('0x1f')](handleEntityNotFound(_0x184108,null))['then'](removeEntity(_0x184108,null))[_0xff0c('0x3e')](handleError(_0x184108,null));};