Built motion from commit (unavailable).|2.5.4
[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 _0xfcbb=['index','map','AnalyticMetric','rawAttributes','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','hasOwnProperty','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','params','length','find','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','user','userProfileId','create','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','html-pdf','eml-format','rimraf','request-promise','moment','bluebird','mustache','util','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','status','json','count','offset','limit','set','Content-Range','reject','then','get','Metrics','UserProfileResource','destroy','end','sendStatus','error','name','send'];(function(_0x4b1371,_0x2f268f){var _0x304631=function(_0x15dc64){while(--_0x15dc64){_0x4b1371['push'](_0x4b1371['shift']());}};_0x304631(++_0x2f268f);}(_0xfcbb,0x10d));var _0xbfcb=function(_0x5d80c9,_0x99256f){_0x5d80c9=_0x5d80c9-0x0;var _0x2dba74=_0xfcbb[_0x5d80c9];return _0x2dba74;};'use strict';var pdf=require(_0xbfcb('0x0'));var emlformat=require(_0xbfcb('0x1'));var rimraf=require(_0xbfcb('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0xbfcb('0x3'));var moment=require(_0xbfcb('0x4'));var BPromise=require(_0xbfcb('0x5'));var Mustache=require(_0xbfcb('0x6'));var util=require(_0xbfcb('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0xbfcb('0x8'));var ejs=require(_0xbfcb('0x9'));var fs=require('fs');var _=require(_0xbfcb('0xa'));var squel=require(_0xbfcb('0xb'));var crypto=require(_0xbfcb('0xc'));var jsforce=require(_0xbfcb('0xd'));var deskjs=require(_0xbfcb('0xe'));var toCsv=require('to-csv');var querystring=require(_0xbfcb('0xf'));var Papa=require(_0xbfcb('0x10'));var Redis=require(_0xbfcb('0x11'));var authService=require('../../components/auth/service');var qs=require(_0xbfcb('0x12'));var as=require(_0xbfcb('0x13'));var hardwareService=require(_0xbfcb('0x14'));var logger=require(_0xbfcb('0x15'))(_0xbfcb('0x16'));var utils=require(_0xbfcb('0x17'));var config=require('../../config/environment');var db=require(_0xbfcb('0x18'))['db'];function respondWithStatusCode(_0x583513,_0xb2f601){_0xb2f601=_0xb2f601||0xcc;return function(_0x2268da){if(_0x2268da){return _0x583513['sendStatus'](_0xb2f601);}return _0x583513[_0xbfcb('0x19')](_0xb2f601)['end']();};}function respondWithResult(_0x211a30,_0x1c52df){_0x1c52df=_0x1c52df||0xc8;return function(_0x44ad6c){if(_0x44ad6c){return _0x211a30[_0xbfcb('0x19')](_0x1c52df)[_0xbfcb('0x1a')](_0x44ad6c);}};}function respondWithFilteredResult(_0xe47707,_0x71304e){return function(_0x2d314a){if(_0x2d314a){var _0x90ed8c=_0x2d314a[_0xbfcb('0x1b')],_0x339347=_0x71304e[_0xbfcb('0x1c')],_0x2c4a85=_0x71304e[_0xbfcb('0x1c')]+_0x71304e[_0xbfcb('0x1d')],_0x3f847f;if(_0x2c4a85>=_0x90ed8c){_0x2c4a85=_0x90ed8c;_0x3f847f=0xc8;}else{_0x3f847f=0xce;}_0xe47707[_0xbfcb('0x19')](_0x3f847f);return _0xe47707[_0xbfcb('0x1e')](_0xbfcb('0x1f'),_0x339347+'-'+_0x2c4a85+'/'+_0x90ed8c)[_0xbfcb('0x1a')](_0x2d314a);}return null;};}function patchUpdates(_0xccd6ff){return function(_0x25afa3){try{jsonpatch['apply'](_0x25afa3,_0xccd6ff,!![]);}catch(_0x26451d){return BPromise[_0xbfcb('0x20')](_0x26451d);}return _0x25afa3['save']();};}function saveUpdates(_0xa3c089,_0x1a7225){return function(_0x48c3c8){if(_0x48c3c8){return _0x48c3c8['update'](_0xa3c089)[_0xbfcb('0x21')](function(_0x45f0a0){return _0x45f0a0;});}return null;};}function removeEntity(_0x2bd235,_0x45661a){return function(_0x1c5924){if(_0x1c5924){return _0x1c5924['destroy']()[_0xbfcb('0x21')](function(){var _0x423bba=_0x1c5924[_0xbfcb('0x22')]({'plain':!![]});var _0xd4d29=_0xbfcb('0x23');return db[_0xbfcb('0x24')][_0xbfcb('0x25')]({'where':{'type':_0xd4d29,'resourceId':_0x423bba['id']}})[_0xbfcb('0x21')](function(){return _0x1c5924;});})[_0xbfcb('0x21')](function(){_0x2bd235[_0xbfcb('0x19')](0xcc)[_0xbfcb('0x26')]();});}};}function handleEntityNotFound(_0xf6dbb7,_0x3ef71c){return function(_0x121a90){if(!_0x121a90){_0xf6dbb7[_0xbfcb('0x27')](0x194);}return _0x121a90;};}function handleError(_0x2a1272,_0x5cd703){_0x5cd703=_0x5cd703||0x1f4;return function(_0x3465f5){logger[_0xbfcb('0x28')](_0x3465f5['stack']);if(_0x3465f5[_0xbfcb('0x29')]){delete _0x3465f5[_0xbfcb('0x29')];}_0x2a1272[_0xbfcb('0x19')](_0x5cd703)[_0xbfcb('0x2a')](_0x3465f5);};}exports[_0xbfcb('0x2b')]=function(_0x3542e9,_0x4069a7){var _0x1a5db2={},_0x434764={},_0x27606f={'count':0x0,'rows':[]};var _0x59719b=_[_0xbfcb('0x2c')](db[_0xbfcb('0x2d')][_0xbfcb('0x2e')],function(_0x43de3c){return{'name':_0x43de3c[_0xbfcb('0x2f')],'type':_0x43de3c[_0xbfcb('0x30')][_0xbfcb('0x31')]};});_0x434764[_0xbfcb('0x32')]=_[_0xbfcb('0x2c')](_0x59719b,'name');_0x434764[_0xbfcb('0x33')]=_[_0xbfcb('0x34')](_0x3542e9[_0xbfcb('0x33')]);_0x434764[_0xbfcb('0x35')]=_['intersection'](_0x434764['model'],_0x434764[_0xbfcb('0x33')]);_0x1a5db2[_0xbfcb('0x36')]=_[_0xbfcb('0x37')](_0x434764[_0xbfcb('0x32')],qs[_0xbfcb('0x38')](_0x3542e9[_0xbfcb('0x33')][_0xbfcb('0x38')]));_0x1a5db2['attributes']=_0x1a5db2['attributes']['length']?_0x1a5db2[_0xbfcb('0x36')]:_0x434764['model'];if(!_0x3542e9[_0xbfcb('0x33')][_0xbfcb('0x39')]('nolimit')){_0x1a5db2['limit']=qs[_0xbfcb('0x1d')](_0x3542e9[_0xbfcb('0x33')][_0xbfcb('0x1d')]);_0x1a5db2[_0xbfcb('0x1c')]=qs['offset'](_0x3542e9[_0xbfcb('0x33')][_0xbfcb('0x1c')]);}_0x1a5db2['order']=qs['sort'](_0x3542e9[_0xbfcb('0x33')]['sort']);_0x1a5db2['where']=qs[_0xbfcb('0x35')](_[_0xbfcb('0x3a')](_0x3542e9[_0xbfcb('0x33')],_0x434764[_0xbfcb('0x35')]),_0x59719b);if(_0x3542e9['query'][_0xbfcb('0x3b')]){_0x1a5db2[_0xbfcb('0x3c')]=_[_0xbfcb('0x3d')](_0x1a5db2[_0xbfcb('0x3c')],{'$or':_[_0xbfcb('0x2c')](_0x59719b,function(_0x1cda6b){if(_0x1cda6b['type']!==_0xbfcb('0x3e')){var _0x4d53fd={};_0x4d53fd[_0x1cda6b[_0xbfcb('0x29')]]={'$like':'%'+_0x3542e9['query'][_0xbfcb('0x3b')]+'%'};return _0x4d53fd;}})});}_0x1a5db2=_[_0xbfcb('0x3d')]({},_0x1a5db2,_0x3542e9[_0xbfcb('0x3f')]);var _0x1d083b={'where':_0x1a5db2[_0xbfcb('0x3c')]};return db[_0xbfcb('0x2d')][_0xbfcb('0x1b')](_0x1d083b)[_0xbfcb('0x21')](function(_0x3a98e0){_0x27606f[_0xbfcb('0x1b')]=_0x3a98e0;if(_0x3542e9['query'][_0xbfcb('0x40')]){_0x1a5db2[_0xbfcb('0x41')]=[{'all':!![]}];}return db['AnalyticMetric'][_0xbfcb('0x42')](_0x1a5db2);})[_0xbfcb('0x21')](function(_0x269102){_0x27606f[_0xbfcb('0x43')]=_0x269102;return _0x27606f;})[_0xbfcb('0x21')](respondWithFilteredResult(_0x4069a7,_0x1a5db2))[_0xbfcb('0x44')](handleError(_0x4069a7,null));};exports['show']=function(_0x96691c,_0x10ffa0){var _0x10ea4f={'raw':!![],'where':{'id':_0x96691c[_0xbfcb('0x45')]['id']}},_0x4a28f2={};_0x4a28f2[_0xbfcb('0x32')]=_[_0xbfcb('0x34')](db['AnalyticMetric'][_0xbfcb('0x2e')]);_0x4a28f2[_0xbfcb('0x33')]=_['keys'](_0x96691c['query']);_0x4a28f2[_0xbfcb('0x35')]=_[_0xbfcb('0x37')](_0x4a28f2['model'],_0x4a28f2[_0xbfcb('0x33')]);_0x10ea4f[_0xbfcb('0x36')]=_['intersection'](_0x4a28f2[_0xbfcb('0x32')],qs[_0xbfcb('0x38')](_0x96691c[_0xbfcb('0x33')][_0xbfcb('0x38')]));_0x10ea4f[_0xbfcb('0x36')]=_0x10ea4f[_0xbfcb('0x36')][_0xbfcb('0x46')]?_0x10ea4f[_0xbfcb('0x36')]:_0x4a28f2[_0xbfcb('0x32')];if(_0x96691c[_0xbfcb('0x33')][_0xbfcb('0x40')]){_0x10ea4f[_0xbfcb('0x41')]=[{'all':!![]}];}_0x10ea4f=_['merge']({},_0x10ea4f,_0x96691c[_0xbfcb('0x3f')]);return db[_0xbfcb('0x2d')][_0xbfcb('0x47')](_0x10ea4f)['then'](handleEntityNotFound(_0x10ffa0,null))[_0xbfcb('0x21')](respondWithResult(_0x10ffa0,null))['catch'](handleError(_0x10ffa0,null));};exports['create']=function(_0x2dcfb3,_0x20918c){return db[_0xbfcb('0x2d')]['create'](_0x2dcfb3[_0xbfcb('0x48')],{})['then'](function(_0x5539d1){var _0x33725a=_0x2dcfb3['user'][_0xbfcb('0x22')]({'plain':!![]});if(!_0x33725a)throw new Error(_0xbfcb('0x49'));if(_0x33725a['role']===_0xbfcb('0x4a')){var _0x5d942f=_0x5539d1[_0xbfcb('0x22')]({'plain':!![]});var _0x4f348b=_0xbfcb('0x23');return db['UserProfileSection'][_0xbfcb('0x47')]({'where':{'name':_0x4f348b,'userProfileId':_0x33725a[_0xbfcb('0x4b')]},'raw':!![]})['then'](function(_0x131af7){if(_0x131af7&&_0x131af7['autoAssociation']===0x0){return db['UserProfileResource'][_0xbfcb('0x4c')]({'name':_0x5d942f[_0xbfcb('0x29')],'resourceId':_0x5d942f['id'],'type':_0x131af7[_0xbfcb('0x29')],'sectionId':_0x131af7['id']},{})['then'](function(){return _0x5539d1;});}else{return _0x5539d1;}})['catch'](function(_0x19dca9){logger[_0xbfcb('0x28')](_0xbfcb('0x4d'),_0x19dca9);throw _0x19dca9;});}return _0x5539d1;})[_0xbfcb('0x21')](respondWithResult(_0x20918c,0xc9))[_0xbfcb('0x44')](handleError(_0x20918c,null));};exports['update']=function(_0x2420d1,_0x37a7e8){if(_0x2420d1[_0xbfcb('0x48')]['id']){delete _0x2420d1[_0xbfcb('0x48')]['id'];}return db['AnalyticMetric']['find']({'where':{'id':_0x2420d1[_0xbfcb('0x45')]['id']}})['then'](handleEntityNotFound(_0x37a7e8,null))[_0xbfcb('0x21')](saveUpdates(_0x2420d1['body'],null))['then'](respondWithResult(_0x37a7e8,null))[_0xbfcb('0x44')](handleError(_0x37a7e8,null));};exports['destroy']=function(_0x5ebfee,_0x27058a){return db['AnalyticMetric'][_0xbfcb('0x47')]({'where':{'id':_0x5ebfee['params']['id']}})[_0xbfcb('0x21')](handleEntityNotFound(_0x27058a,null))[_0xbfcb('0x21')](removeEntity(_0x27058a,null))['catch'](handleError(_0x27058a,null));};