Built motion from commit (unavailable).|2.5.3
[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 _0xae60=['keys','filters','intersection','attributes','fields','length','hasOwnProperty','where','pick','filter','merge','options','includeAll','include','rows','catch','show','params','rawAttributes','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','error','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','find','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','mustache','util','sox','to-csv','ejs','lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../config/environment','../../mysqldb','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','then','destroy','get','Metrics','UserProfileResource','stack','name','send','index','map','AnalyticMetric','fieldName','type','key','model','query'];(function(_0x2c8b68,_0x4d405b){var _0x426dad=function(_0x176e07){while(--_0x176e07){_0x2c8b68['push'](_0x2c8b68['shift']());}};_0x426dad(++_0x4d405b);}(_0xae60,0x1c7));var _0x0ae6=function(_0x2c91e9,_0x2fb965){_0x2c91e9=_0x2c91e9-0x0;var _0x13f0ff=_0xae60[_0x2c91e9];return _0x13f0ff;};'use strict';var pdf=require(_0x0ae6('0x0'));var emlformat=require(_0x0ae6('0x1'));var rimraf=require(_0x0ae6('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x0ae6('0x3'));var rp=require(_0x0ae6('0x4'));var moment=require(_0x0ae6('0x5'));var BPromise=require('bluebird');var Mustache=require(_0x0ae6('0x6'));var util=require(_0x0ae6('0x7'));var path=require('path');var sox=require(_0x0ae6('0x8'));var csv=require(_0x0ae6('0x9'));var ejs=require(_0x0ae6('0xa'));var fs=require('fs');var _=require(_0x0ae6('0xb'));var squel=require(_0x0ae6('0xc'));var crypto=require(_0x0ae6('0xd'));var jsforce=require(_0x0ae6('0xe'));var deskjs=require(_0x0ae6('0xf'));var toCsv=require('to-csv');var querystring=require(_0x0ae6('0x10'));var Papa=require(_0x0ae6('0x11'));var Redis=require(_0x0ae6('0x12'));var authService=require(_0x0ae6('0x13'));var qs=require('../../components/parsers/qs');var as=require(_0x0ae6('0x14'));var hardwareService=require(_0x0ae6('0x15'));var logger=require(_0x0ae6('0x16'))(_0x0ae6('0x17'));var utils=require(_0x0ae6('0x18'));var config=require(_0x0ae6('0x19'));var db=require(_0x0ae6('0x1a'))['db'];function respondWithStatusCode(_0x1473ea,_0x3b05a4){_0x3b05a4=_0x3b05a4||0xcc;return function(_0x30f8f9){if(_0x30f8f9){return _0x1473ea[_0x0ae6('0x1b')](_0x3b05a4);}return _0x1473ea[_0x0ae6('0x1c')](_0x3b05a4)[_0x0ae6('0x1d')]();};}function respondWithResult(_0xf311f7,_0x4d2da8){_0x4d2da8=_0x4d2da8||0xc8;return function(_0x3809c6){if(_0x3809c6){return _0xf311f7[_0x0ae6('0x1c')](_0x4d2da8)[_0x0ae6('0x1e')](_0x3809c6);}};}function respondWithFilteredResult(_0x20e866,_0xce3e23){return function(_0x3a1e26){if(_0x3a1e26){var _0x151144=_0x3a1e26[_0x0ae6('0x1f')],_0x3b64ac=_0xce3e23[_0x0ae6('0x20')],_0xa797bb=_0xce3e23[_0x0ae6('0x20')]+_0xce3e23[_0x0ae6('0x21')],_0x13ba83;if(_0xa797bb>=_0x151144){_0xa797bb=_0x151144;_0x13ba83=0xc8;}else{_0x13ba83=0xce;}_0x20e866[_0x0ae6('0x1c')](_0x13ba83);return _0x20e866[_0x0ae6('0x22')](_0x0ae6('0x23'),_0x3b64ac+'-'+_0xa797bb+'/'+_0x151144)[_0x0ae6('0x1e')](_0x3a1e26);}return null;};}function patchUpdates(_0x2ca2a3){return function(_0x9e2c46){try{jsonpatch[_0x0ae6('0x24')](_0x9e2c46,_0x2ca2a3,!![]);}catch(_0x191eaf){return BPromise['reject'](_0x191eaf);}return _0x9e2c46[_0x0ae6('0x25')]();};}function saveUpdates(_0x6fab99,_0x140a3b){return function(_0x1027c2){if(_0x1027c2){return _0x1027c2[_0x0ae6('0x26')](_0x6fab99)[_0x0ae6('0x27')](function(_0x210ca4){return _0x210ca4;});}return null;};}function removeEntity(_0x829039,_0x515f3d){return function(_0x39b22e){if(_0x39b22e){return _0x39b22e[_0x0ae6('0x28')]()[_0x0ae6('0x27')](function(){var _0x2f4688=_0x39b22e[_0x0ae6('0x29')]({'plain':!![]});var _0x4eba72=_0x0ae6('0x2a');return db[_0x0ae6('0x2b')][_0x0ae6('0x28')]({'where':{'type':_0x4eba72,'resourceId':_0x2f4688['id']}})[_0x0ae6('0x27')](function(){return _0x39b22e;});})[_0x0ae6('0x27')](function(){_0x829039[_0x0ae6('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3630e6,_0x2dcdb7){return function(_0x519f17){if(!_0x519f17){_0x3630e6['sendStatus'](0x194);}return _0x519f17;};}function handleError(_0x44eb95,_0x3255a7){_0x3255a7=_0x3255a7||0x1f4;return function(_0x17360e){logger['error'](_0x17360e[_0x0ae6('0x2c')]);if(_0x17360e[_0x0ae6('0x2d')]){delete _0x17360e[_0x0ae6('0x2d')];}_0x44eb95['status'](_0x3255a7)[_0x0ae6('0x2e')](_0x17360e);};}exports[_0x0ae6('0x2f')]=function(_0x449c33,_0x232fbd){var _0x14eed5={},_0x257af5={},_0x4fc7bd={'count':0x0,'rows':[]};var _0x5b2ad6=_[_0x0ae6('0x30')](db[_0x0ae6('0x31')]['rawAttributes'],function(_0x4a06f1){return{'name':_0x4a06f1[_0x0ae6('0x32')],'type':_0x4a06f1[_0x0ae6('0x33')][_0x0ae6('0x34')]};});_0x257af5[_0x0ae6('0x35')]=_['map'](_0x5b2ad6,_0x0ae6('0x2d'));_0x257af5[_0x0ae6('0x36')]=_[_0x0ae6('0x37')](_0x449c33['query']);_0x257af5[_0x0ae6('0x38')]=_[_0x0ae6('0x39')](_0x257af5[_0x0ae6('0x35')],_0x257af5[_0x0ae6('0x36')]);_0x14eed5[_0x0ae6('0x3a')]=_[_0x0ae6('0x39')](_0x257af5[_0x0ae6('0x35')],qs[_0x0ae6('0x3b')](_0x449c33[_0x0ae6('0x36')][_0x0ae6('0x3b')]));_0x14eed5['attributes']=_0x14eed5[_0x0ae6('0x3a')][_0x0ae6('0x3c')]?_0x14eed5['attributes']:_0x257af5[_0x0ae6('0x35')];if(!_0x449c33[_0x0ae6('0x36')][_0x0ae6('0x3d')]('nolimit')){_0x14eed5[_0x0ae6('0x21')]=qs['limit'](_0x449c33['query'][_0x0ae6('0x21')]);_0x14eed5[_0x0ae6('0x20')]=qs[_0x0ae6('0x20')](_0x449c33[_0x0ae6('0x36')][_0x0ae6('0x20')]);}_0x14eed5['order']=qs['sort'](_0x449c33[_0x0ae6('0x36')]['sort']);_0x14eed5[_0x0ae6('0x3e')]=qs['filters'](_[_0x0ae6('0x3f')](_0x449c33['query'],_0x257af5[_0x0ae6('0x38')]),_0x5b2ad6);if(_0x449c33[_0x0ae6('0x36')][_0x0ae6('0x40')]){_0x14eed5[_0x0ae6('0x3e')]=_['merge'](_0x14eed5['where'],{'$or':_[_0x0ae6('0x30')](_0x5b2ad6,function(_0x34b547){if(_0x34b547[_0x0ae6('0x33')]!=='VIRTUAL'){var _0xaeb354={};_0xaeb354[_0x34b547['name']]={'$like':'%'+_0x449c33[_0x0ae6('0x36')][_0x0ae6('0x40')]+'%'};return _0xaeb354;}})});}_0x14eed5=_[_0x0ae6('0x41')]({},_0x14eed5,_0x449c33[_0x0ae6('0x42')]);var _0x450f00={'where':_0x14eed5[_0x0ae6('0x3e')]};return db['AnalyticMetric'][_0x0ae6('0x1f')](_0x450f00)[_0x0ae6('0x27')](function(_0x24d9ec){_0x4fc7bd[_0x0ae6('0x1f')]=_0x24d9ec;if(_0x449c33[_0x0ae6('0x36')][_0x0ae6('0x43')]){_0x14eed5[_0x0ae6('0x44')]=[{'all':!![]}];}return db[_0x0ae6('0x31')]['findAll'](_0x14eed5);})[_0x0ae6('0x27')](function(_0xba3183){_0x4fc7bd[_0x0ae6('0x45')]=_0xba3183;return _0x4fc7bd;})[_0x0ae6('0x27')](respondWithFilteredResult(_0x232fbd,_0x14eed5))[_0x0ae6('0x46')](handleError(_0x232fbd,null));};exports[_0x0ae6('0x47')]=function(_0x24c021,_0x21431e){var _0xb38cbb={'raw':!![],'where':{'id':_0x24c021[_0x0ae6('0x48')]['id']}},_0x156841={};_0x156841[_0x0ae6('0x35')]=_[_0x0ae6('0x37')](db[_0x0ae6('0x31')][_0x0ae6('0x49')]);_0x156841[_0x0ae6('0x36')]=_[_0x0ae6('0x37')](_0x24c021[_0x0ae6('0x36')]);_0x156841['filters']=_[_0x0ae6('0x39')](_0x156841[_0x0ae6('0x35')],_0x156841[_0x0ae6('0x36')]);_0xb38cbb[_0x0ae6('0x3a')]=_[_0x0ae6('0x39')](_0x156841[_0x0ae6('0x35')],qs['fields'](_0x24c021[_0x0ae6('0x36')][_0x0ae6('0x3b')]));_0xb38cbb[_0x0ae6('0x3a')]=_0xb38cbb[_0x0ae6('0x3a')]['length']?_0xb38cbb['attributes']:_0x156841['model'];if(_0x24c021[_0x0ae6('0x36')][_0x0ae6('0x43')]){_0xb38cbb[_0x0ae6('0x44')]=[{'all':!![]}];}_0xb38cbb=_['merge']({},_0xb38cbb,_0x24c021[_0x0ae6('0x42')]);return db[_0x0ae6('0x31')]['find'](_0xb38cbb)[_0x0ae6('0x27')](handleEntityNotFound(_0x21431e,null))[_0x0ae6('0x27')](respondWithResult(_0x21431e,null))['catch'](handleError(_0x21431e,null));};exports[_0x0ae6('0x4a')]=function(_0x3d1e75,_0x587ab4){return db[_0x0ae6('0x31')][_0x0ae6('0x4a')](_0x3d1e75[_0x0ae6('0x4b')],{})['then'](function(_0x2f586b){var _0x21de54=_0x3d1e75[_0x0ae6('0x4c')][_0x0ae6('0x29')]({'plain':!![]});if(!_0x21de54)throw new Error(_0x0ae6('0x4d'));if(_0x21de54[_0x0ae6('0x4e')]===_0x0ae6('0x4c')){var _0x5ababa=_0x2f586b['get']({'plain':!![]});var _0x2727f0=_0x0ae6('0x2a');return db[_0x0ae6('0x4f')]['find']({'where':{'name':_0x2727f0,'userProfileId':_0x21de54[_0x0ae6('0x50')]},'raw':!![]})['then'](function(_0x582a5e){if(_0x582a5e&&_0x582a5e[_0x0ae6('0x51')]===0x0){return db[_0x0ae6('0x2b')][_0x0ae6('0x4a')]({'name':_0x5ababa['name'],'resourceId':_0x5ababa['id'],'type':_0x582a5e[_0x0ae6('0x2d')],'sectionId':_0x582a5e['id']},{})[_0x0ae6('0x27')](function(){return _0x2f586b;});}else{return _0x2f586b;}})[_0x0ae6('0x46')](function(_0x327b55){logger[_0x0ae6('0x52')](_0x0ae6('0x53'),_0x327b55);throw _0x327b55;});}return _0x2f586b;})[_0x0ae6('0x27')](respondWithResult(_0x587ab4,0xc9))[_0x0ae6('0x46')](handleError(_0x587ab4,null));};exports[_0x0ae6('0x26')]=function(_0x117d24,_0x1cc515){if(_0x117d24[_0x0ae6('0x4b')]['id']){delete _0x117d24[_0x0ae6('0x4b')]['id'];}return db[_0x0ae6('0x31')][_0x0ae6('0x54')]({'where':{'id':_0x117d24['params']['id']}})['then'](handleEntityNotFound(_0x1cc515,null))[_0x0ae6('0x27')](saveUpdates(_0x117d24[_0x0ae6('0x4b')],null))[_0x0ae6('0x27')](respondWithResult(_0x1cc515,null))[_0x0ae6('0x46')](handleError(_0x1cc515,null));};exports[_0x0ae6('0x28')]=function(_0x437845,_0x3fa2ba){return db[_0x0ae6('0x31')][_0x0ae6('0x54')]({'where':{'id':_0x437845[_0x0ae6('0x48')]['id']}})[_0x0ae6('0x27')](handleEntityNotFound(_0x3fa2ba,null))[_0x0ae6('0x27')](removeEntity(_0x3fa2ba,null))[_0x0ae6('0x46')](handleError(_0x3fa2ba,null));};