Built motion from commit (unavailable).|2.5.31
[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 _0xbf99=['filters','pick','filter','merge','options','includeAll','include','findAll','rows','catch','find','create','body','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','user','UserProfileSection','userProfileId','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','update','params','rimraf','request-promise','moment','bluebird','mustache','util','path','sox','ejs','fs-extra','squel','crypto','to-csv','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','sendStatus','status','end','undefined','count','offset','limit','Content-Range','apply','reject','save','then','destroy','get','Metrics','stack','name','send','index','map','AnalyticMetric','rawAttributes','fieldName','type','key','query','keys','intersection','model','attributes','fields','length','nolimit','order','sort','where'];(function(_0x36d659,_0x53fea8){var _0x4b171d=function(_0x4f232e){while(--_0x4f232e){_0x36d659['push'](_0x36d659['shift']());}};_0x4b171d(++_0x53fea8);}(_0xbf99,0xb8));var _0x9bf9=function(_0x1a7b2a,_0x3c62bd){_0x1a7b2a=_0x1a7b2a-0x0;var _0x1274e1=_0xbf99[_0x1a7b2a];return _0x1274e1;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x9bf9('0x0'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x9bf9('0x1'));var moment=require(_0x9bf9('0x2'));var BPromise=require(_0x9bf9('0x3'));var Mustache=require(_0x9bf9('0x4'));var util=require(_0x9bf9('0x5'));var path=require(_0x9bf9('0x6'));var sox=require(_0x9bf9('0x7'));var csv=require('to-csv');var ejs=require(_0x9bf9('0x8'));var fs=require('fs');var fs_extra=require(_0x9bf9('0x9'));var _=require('lodash');var squel=require(_0x9bf9('0xa'));var crypto=require(_0x9bf9('0xb'));var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x9bf9('0xc'));var querystring=require(_0x9bf9('0xd'));var Papa=require(_0x9bf9('0xe'));var Redis=require(_0x9bf9('0xf'));var authService=require(_0x9bf9('0x10'));var qs=require(_0x9bf9('0x11'));var as=require(_0x9bf9('0x12'));var hardwareService=require(_0x9bf9('0x13'));var logger=require(_0x9bf9('0x14'))(_0x9bf9('0x15'));var utils=require(_0x9bf9('0x16'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require('../../mysqldb')['db'];function respondWithStatusCode(_0x54c9a1,_0x4effe3){_0x4effe3=_0x4effe3||0xcc;return function(_0x4395d0){if(_0x4395d0){return _0x54c9a1[_0x9bf9('0x17')](_0x4effe3);}return _0x54c9a1[_0x9bf9('0x18')](_0x4effe3)[_0x9bf9('0x19')]();};}function respondWithResult(_0xd01334,_0x960ccd){_0x960ccd=_0x960ccd||0xc8;return function(_0x537059){if(_0x537059){return _0xd01334[_0x9bf9('0x18')](_0x960ccd)['json'](_0x537059);}};}function respondWithFilteredResult(_0xe7ac44,_0x654af){return function(_0x4fc35b){if(_0x4fc35b){var _0x32db0e=typeof _0x654af['offset']===_0x9bf9('0x1a')&&typeof _0x654af['limit']===_0x9bf9('0x1a');var _0x4f6c77=_0x4fc35b[_0x9bf9('0x1b')];var _0x279ead=_0x32db0e?0x0:_0x654af[_0x9bf9('0x1c')];var _0x5a0a25=_0x32db0e?_0x4fc35b['count']:_0x654af[_0x9bf9('0x1c')]+_0x654af[_0x9bf9('0x1d')];var _0xff99b0;if(_0x5a0a25>=_0x4f6c77){_0x5a0a25=_0x4f6c77;_0xff99b0=0xc8;}else{_0xff99b0=0xce;}_0xe7ac44['status'](_0xff99b0);return _0xe7ac44['set'](_0x9bf9('0x1e'),_0x279ead+'-'+_0x5a0a25+'/'+_0x4f6c77)['json'](_0x4fc35b);}return null;};}function patchUpdates(_0x24081b){return function(_0x2f5565){try{jsonpatch[_0x9bf9('0x1f')](_0x2f5565,_0x24081b,!![]);}catch(_0x7bf395){return BPromise[_0x9bf9('0x20')](_0x7bf395);}return _0x2f5565[_0x9bf9('0x21')]();};}function saveUpdates(_0x3e8523,_0x2766be){return function(_0x59aa5a){if(_0x59aa5a){return _0x59aa5a['update'](_0x3e8523)[_0x9bf9('0x22')](function(_0x398fc6){return _0x398fc6;});}return null;};}function removeEntity(_0x1e4282,_0x19ab39){return function(_0x4e0405){if(_0x4e0405){return _0x4e0405[_0x9bf9('0x23')]()[_0x9bf9('0x22')](function(){var _0x574943=_0x4e0405[_0x9bf9('0x24')]({'plain':!![]});var _0x2d0709=_0x9bf9('0x25');return db['UserProfileResource'][_0x9bf9('0x23')]({'where':{'type':_0x2d0709,'resourceId':_0x574943['id']}})[_0x9bf9('0x22')](function(){return _0x4e0405;});})[_0x9bf9('0x22')](function(){_0x1e4282['status'](0xcc)['end']();});}};}function handleEntityNotFound(_0x4dc798,_0x5b4161){return function(_0x433de9){if(!_0x433de9){_0x4dc798[_0x9bf9('0x17')](0x194);}return _0x433de9;};}function handleError(_0x26c7d4,_0x4a13d6){_0x4a13d6=_0x4a13d6||0x1f4;return function(_0x562239){logger['error'](_0x562239[_0x9bf9('0x26')]);if(_0x562239[_0x9bf9('0x27')]){delete _0x562239[_0x9bf9('0x27')];}_0x26c7d4['status'](_0x4a13d6)[_0x9bf9('0x28')](_0x562239);};}exports[_0x9bf9('0x29')]=function(_0x5e6790,_0x4b2afd){var _0x574ee8={},_0x3d10b3={},_0x589de8={'count':0x0,'rows':[]};var _0x2d6be8=_[_0x9bf9('0x2a')](db[_0x9bf9('0x2b')][_0x9bf9('0x2c')],function(_0x2c4ac2){return{'name':_0x2c4ac2[_0x9bf9('0x2d')],'type':_0x2c4ac2[_0x9bf9('0x2e')][_0x9bf9('0x2f')]};});_0x3d10b3['model']=_['map'](_0x2d6be8,'name');_0x3d10b3[_0x9bf9('0x30')]=_[_0x9bf9('0x31')](_0x5e6790[_0x9bf9('0x30')]);_0x3d10b3['filters']=_[_0x9bf9('0x32')](_0x3d10b3[_0x9bf9('0x33')],_0x3d10b3[_0x9bf9('0x30')]);_0x574ee8[_0x9bf9('0x34')]=_[_0x9bf9('0x32')](_0x3d10b3[_0x9bf9('0x33')],qs['fields'](_0x5e6790[_0x9bf9('0x30')][_0x9bf9('0x35')]));_0x574ee8[_0x9bf9('0x34')]=_0x574ee8[_0x9bf9('0x34')][_0x9bf9('0x36')]?_0x574ee8[_0x9bf9('0x34')]:_0x3d10b3[_0x9bf9('0x33')];if(!_0x5e6790[_0x9bf9('0x30')]['hasOwnProperty'](_0x9bf9('0x37'))){_0x574ee8[_0x9bf9('0x1d')]=qs[_0x9bf9('0x1d')](_0x5e6790[_0x9bf9('0x30')][_0x9bf9('0x1d')]);_0x574ee8['offset']=qs[_0x9bf9('0x1c')](_0x5e6790[_0x9bf9('0x30')]['offset']);}_0x574ee8[_0x9bf9('0x38')]=qs[_0x9bf9('0x39')](_0x5e6790[_0x9bf9('0x30')]['sort']);_0x574ee8[_0x9bf9('0x3a')]=qs[_0x9bf9('0x3b')](_[_0x9bf9('0x3c')](_0x5e6790[_0x9bf9('0x30')],_0x3d10b3[_0x9bf9('0x3b')]),_0x2d6be8);if(_0x5e6790[_0x9bf9('0x30')][_0x9bf9('0x3d')]){_0x574ee8[_0x9bf9('0x3a')]=_[_0x9bf9('0x3e')](_0x574ee8[_0x9bf9('0x3a')],{'$or':_[_0x9bf9('0x2a')](_0x2d6be8,function(_0x41cc3a){if(_0x41cc3a[_0x9bf9('0x2e')]!=='VIRTUAL'){var _0x186115={};_0x186115[_0x41cc3a[_0x9bf9('0x27')]]={'$like':'%'+_0x5e6790[_0x9bf9('0x30')]['filter']+'%'};return _0x186115;}})});}_0x574ee8=_[_0x9bf9('0x3e')]({},_0x574ee8,_0x5e6790[_0x9bf9('0x3f')]);var _0x5826f8={'where':_0x574ee8[_0x9bf9('0x3a')]};return db[_0x9bf9('0x2b')][_0x9bf9('0x1b')](_0x5826f8)[_0x9bf9('0x22')](function(_0x1eb760){_0x589de8[_0x9bf9('0x1b')]=_0x1eb760;if(_0x5e6790[_0x9bf9('0x30')][_0x9bf9('0x40')]){_0x574ee8[_0x9bf9('0x41')]=[{'all':!![]}];}return db[_0x9bf9('0x2b')][_0x9bf9('0x42')](_0x574ee8);})['then'](function(_0x2effc1){_0x589de8[_0x9bf9('0x43')]=_0x2effc1;return _0x589de8;})[_0x9bf9('0x22')](respondWithFilteredResult(_0x4b2afd,_0x574ee8))[_0x9bf9('0x44')](handleError(_0x4b2afd,null));};exports['show']=function(_0x324e40,_0x491f92){var _0x22863a={'raw':!![],'where':{'id':_0x324e40['params']['id']}},_0x56c80c={};_0x56c80c['model']=_[_0x9bf9('0x31')](db[_0x9bf9('0x2b')][_0x9bf9('0x2c')]);_0x56c80c[_0x9bf9('0x30')]=_[_0x9bf9('0x31')](_0x324e40[_0x9bf9('0x30')]);_0x56c80c['filters']=_[_0x9bf9('0x32')](_0x56c80c[_0x9bf9('0x33')],_0x56c80c[_0x9bf9('0x30')]);_0x22863a[_0x9bf9('0x34')]=_[_0x9bf9('0x32')](_0x56c80c[_0x9bf9('0x33')],qs[_0x9bf9('0x35')](_0x324e40[_0x9bf9('0x30')]['fields']));_0x22863a[_0x9bf9('0x34')]=_0x22863a[_0x9bf9('0x34')][_0x9bf9('0x36')]?_0x22863a[_0x9bf9('0x34')]:_0x56c80c[_0x9bf9('0x33')];if(_0x324e40[_0x9bf9('0x30')]['includeAll']){_0x22863a[_0x9bf9('0x41')]=[{'all':!![]}];}_0x22863a=_[_0x9bf9('0x3e')]({},_0x22863a,_0x324e40[_0x9bf9('0x3f')]);return db[_0x9bf9('0x2b')][_0x9bf9('0x45')](_0x22863a)['then'](handleEntityNotFound(_0x491f92,null))[_0x9bf9('0x22')](respondWithResult(_0x491f92,null))[_0x9bf9('0x44')](handleError(_0x491f92,null));};exports[_0x9bf9('0x46')]=function(_0xe6e4eb,_0x830107){return db[_0x9bf9('0x2b')][_0x9bf9('0x46')](_0xe6e4eb[_0x9bf9('0x47')],{})[_0x9bf9('0x22')](function(_0x5166c6){var _0x10eb1d=_0xe6e4eb['user'][_0x9bf9('0x24')]({'plain':!![]});if(!_0x10eb1d)throw new Error(_0x9bf9('0x48'));if(_0x10eb1d[_0x9bf9('0x49')]===_0x9bf9('0x4a')){var _0x2b7cfb=_0x5166c6[_0x9bf9('0x24')]({'plain':!![]});var _0x119d47=_0x9bf9('0x25');return db[_0x9bf9('0x4b')][_0x9bf9('0x45')]({'where':{'name':_0x119d47,'userProfileId':_0x10eb1d[_0x9bf9('0x4c')]},'raw':!![]})[_0x9bf9('0x22')](function(_0x2fd307){if(_0x2fd307&&_0x2fd307['autoAssociation']===0x0){return db['UserProfileResource'][_0x9bf9('0x46')]({'name':_0x2b7cfb[_0x9bf9('0x27')],'resourceId':_0x2b7cfb['id'],'type':_0x2fd307[_0x9bf9('0x27')],'sectionId':_0x2fd307['id']},{})[_0x9bf9('0x22')](function(){return _0x5166c6;});}else{return _0x5166c6;}})[_0x9bf9('0x44')](function(_0x5b698d){logger[_0x9bf9('0x4d')](_0x9bf9('0x4e'),_0x5b698d);throw _0x5b698d;});}return _0x5166c6;})['then'](respondWithResult(_0x830107,0xc9))['catch'](handleError(_0x830107,null));};exports[_0x9bf9('0x4f')]=function(_0x4ef643,_0x1f3387){if(_0x4ef643[_0x9bf9('0x47')]['id']){delete _0x4ef643['body']['id'];}return db[_0x9bf9('0x2b')][_0x9bf9('0x45')]({'where':{'id':_0x4ef643[_0x9bf9('0x50')]['id']}})[_0x9bf9('0x22')](handleEntityNotFound(_0x1f3387,null))['then'](saveUpdates(_0x4ef643['body'],null))[_0x9bf9('0x22')](respondWithResult(_0x1f3387,null))[_0x9bf9('0x44')](handleError(_0x1f3387,null));};exports['destroy']=function(_0x1e84f9,_0x51533c){return db[_0x9bf9('0x2b')][_0x9bf9('0x45')]({'where':{'id':_0x1e84f9['params']['id']}})[_0x9bf9('0x22')](handleEntityNotFound(_0x51533c,null))[_0x9bf9('0x22')](removeEntity(_0x51533c,null))[_0x9bf9('0x44')](handleError(_0x51533c,null));};