Built motion from commit (unavailable).|2.5.13
[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 _0x681f=['querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','../../config/utils','../../mysqldb','sendStatus','status','json','count','set','Content-Range','apply','save','update','destroy','then','get','Metrics','UserProfileResource','end','error','stack','name','send','index','map','rawAttributes','fieldName','type','key','model','query','intersection','attributes','fields','length','hasOwnProperty','nolimit','limit','offset','order','sort','where','filters','pick','merge','VIRTUAL','filter','options','AnalyticMetric','include','rows','catch','keys','includeAll','find','create','body','user','Unable\x20to\x20retrieve\x20the\x20current\x20user','role','UserProfileSection','userProfileId','autoAssociation','Unable\x20to\x20associate\x20the\x20resource\x20to\x20the\x20User\x20Profile:\x20%s','params','eml-format','rimraf','zip-dir','fast-json-patch','moment','bluebird','mustache','util','path','sox','to-csv','ejs','squel','crypto','jsforce','desk.js'];(function(_0x55e0f7,_0x2d49c7){var _0x2f0aed=function(_0x1b3a7a){while(--_0x1b3a7a){_0x55e0f7['push'](_0x55e0f7['shift']());}};_0x2f0aed(++_0x2d49c7);}(_0x681f,0x9e));var _0xf681=function(_0x449ff8,_0x4b1972){_0x449ff8=_0x449ff8-0x0;var _0x1ceab2=_0x681f[_0x449ff8];return _0x1ceab2;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0xf681('0x0'));var rimraf=require(_0xf681('0x1'));var zipdir=require(_0xf681('0x2'));var jsonpatch=require(_0xf681('0x3'));var rp=require('request-promise');var moment=require(_0xf681('0x4'));var BPromise=require(_0xf681('0x5'));var Mustache=require(_0xf681('0x6'));var util=require(_0xf681('0x7'));var path=require(_0xf681('0x8'));var sox=require(_0xf681('0x9'));var csv=require(_0xf681('0xa'));var ejs=require(_0xf681('0xb'));var fs=require('fs');var _=require('lodash');var squel=require(_0xf681('0xc'));var crypto=require(_0xf681('0xd'));var jsforce=require(_0xf681('0xe'));var deskjs=require(_0xf681('0xf'));var toCsv=require(_0xf681('0xa'));var querystring=require(_0xf681('0x10'));var Papa=require(_0xf681('0x11'));var Redis=require(_0xf681('0x12'));var authService=require(_0xf681('0x13'));var qs=require(_0xf681('0x14'));var as=require(_0xf681('0x15'));var hardwareService=require(_0xf681('0x16'));var logger=require(_0xf681('0x17'))('api');var utils=require(_0xf681('0x18'));var config=require('../../config/environment');var licenseUtil=require('../../config/license/util');var db=require(_0xf681('0x19'))['db'];function respondWithStatusCode(_0x30879f,_0x7f53fd){_0x7f53fd=_0x7f53fd||0xcc;return function(_0x218e7b){if(_0x218e7b){return _0x30879f[_0xf681('0x1a')](_0x7f53fd);}return _0x30879f[_0xf681('0x1b')](_0x7f53fd)['end']();};}function respondWithResult(_0x25c14e,_0x3301a5){_0x3301a5=_0x3301a5||0xc8;return function(_0x1a604c){if(_0x1a604c){return _0x25c14e[_0xf681('0x1b')](_0x3301a5)[_0xf681('0x1c')](_0x1a604c);}};}function respondWithFilteredResult(_0x1542be,_0x13636c){return function(_0x5b7aa1){if(_0x5b7aa1){var _0x3adb5b=_0x5b7aa1[_0xf681('0x1d')],_0x532569=_0x13636c['offset'],_0x2be3c2=_0x13636c['offset']+_0x13636c['limit'],_0x3cddb9;if(_0x2be3c2>=_0x3adb5b){_0x2be3c2=_0x3adb5b;_0x3cddb9=0xc8;}else{_0x3cddb9=0xce;}_0x1542be[_0xf681('0x1b')](_0x3cddb9);return _0x1542be[_0xf681('0x1e')](_0xf681('0x1f'),_0x532569+'-'+_0x2be3c2+'/'+_0x3adb5b)[_0xf681('0x1c')](_0x5b7aa1);}return null;};}function patchUpdates(_0x21dc85){return function(_0x46471c){try{jsonpatch[_0xf681('0x20')](_0x46471c,_0x21dc85,!![]);}catch(_0x3c958a){return BPromise['reject'](_0x3c958a);}return _0x46471c[_0xf681('0x21')]();};}function saveUpdates(_0x4bc05a,_0x4a7b13){return function(_0x484482){if(_0x484482){return _0x484482[_0xf681('0x22')](_0x4bc05a)['then'](function(_0x454438){return _0x454438;});}return null;};}function removeEntity(_0x502d6f,_0x24f90c){return function(_0xadaec7){if(_0xadaec7){return _0xadaec7[_0xf681('0x23')]()[_0xf681('0x24')](function(){var _0x1967ec=_0xadaec7[_0xf681('0x25')]({'plain':!![]});var _0x1778b6=_0xf681('0x26');return db[_0xf681('0x27')][_0xf681('0x23')]({'where':{'type':_0x1778b6,'resourceId':_0x1967ec['id']}})[_0xf681('0x24')](function(){return _0xadaec7;});})[_0xf681('0x24')](function(){_0x502d6f[_0xf681('0x1b')](0xcc)[_0xf681('0x28')]();});}};}function handleEntityNotFound(_0x4d6411,_0x3e4c15){return function(_0x54e99e){if(!_0x54e99e){_0x4d6411[_0xf681('0x1a')](0x194);}return _0x54e99e;};}function handleError(_0x210693,_0x1373b0){_0x1373b0=_0x1373b0||0x1f4;return function(_0x5280a4){logger[_0xf681('0x29')](_0x5280a4[_0xf681('0x2a')]);if(_0x5280a4['name']){delete _0x5280a4[_0xf681('0x2b')];}_0x210693[_0xf681('0x1b')](_0x1373b0)[_0xf681('0x2c')](_0x5280a4);};}exports[_0xf681('0x2d')]=function(_0x390e08,_0x5a6417){var _0x345699={},_0x2ddf00={},_0x1e6b1b={'count':0x0,'rows':[]};var _0x528228=_[_0xf681('0x2e')](db['AnalyticMetric'][_0xf681('0x2f')],function(_0x1fcb1e){return{'name':_0x1fcb1e[_0xf681('0x30')],'type':_0x1fcb1e[_0xf681('0x31')][_0xf681('0x32')]};});_0x2ddf00[_0xf681('0x33')]=_[_0xf681('0x2e')](_0x528228,_0xf681('0x2b'));_0x2ddf00[_0xf681('0x34')]=_['keys'](_0x390e08[_0xf681('0x34')]);_0x2ddf00['filters']=_[_0xf681('0x35')](_0x2ddf00[_0xf681('0x33')],_0x2ddf00[_0xf681('0x34')]);_0x345699[_0xf681('0x36')]=_['intersection'](_0x2ddf00[_0xf681('0x33')],qs[_0xf681('0x37')](_0x390e08['query'][_0xf681('0x37')]));_0x345699[_0xf681('0x36')]=_0x345699['attributes'][_0xf681('0x38')]?_0x345699[_0xf681('0x36')]:_0x2ddf00['model'];if(!_0x390e08['query'][_0xf681('0x39')](_0xf681('0x3a'))){_0x345699[_0xf681('0x3b')]=qs[_0xf681('0x3b')](_0x390e08[_0xf681('0x34')]['limit']);_0x345699[_0xf681('0x3c')]=qs['offset'](_0x390e08[_0xf681('0x34')][_0xf681('0x3c')]);}_0x345699[_0xf681('0x3d')]=qs['sort'](_0x390e08[_0xf681('0x34')][_0xf681('0x3e')]);_0x345699[_0xf681('0x3f')]=qs[_0xf681('0x40')](_[_0xf681('0x41')](_0x390e08[_0xf681('0x34')],_0x2ddf00[_0xf681('0x40')]),_0x528228);if(_0x390e08[_0xf681('0x34')]['filter']){_0x345699[_0xf681('0x3f')]=_[_0xf681('0x42')](_0x345699[_0xf681('0x3f')],{'$or':_[_0xf681('0x2e')](_0x528228,function(_0x45c5e4){if(_0x45c5e4[_0xf681('0x31')]!==_0xf681('0x43')){var _0x33ee80={};_0x33ee80[_0x45c5e4[_0xf681('0x2b')]]={'$like':'%'+_0x390e08[_0xf681('0x34')][_0xf681('0x44')]+'%'};return _0x33ee80;}})});}_0x345699=_[_0xf681('0x42')]({},_0x345699,_0x390e08[_0xf681('0x45')]);var _0x443a5b={'where':_0x345699[_0xf681('0x3f')]};return db[_0xf681('0x46')][_0xf681('0x1d')](_0x443a5b)[_0xf681('0x24')](function(_0x372603){_0x1e6b1b['count']=_0x372603;if(_0x390e08[_0xf681('0x34')]['includeAll']){_0x345699[_0xf681('0x47')]=[{'all':!![]}];}return db[_0xf681('0x46')]['findAll'](_0x345699);})['then'](function(_0x316685){_0x1e6b1b[_0xf681('0x48')]=_0x316685;return _0x1e6b1b;})[_0xf681('0x24')](respondWithFilteredResult(_0x5a6417,_0x345699))[_0xf681('0x49')](handleError(_0x5a6417,null));};exports['show']=function(_0x50afa1,_0x176961){var _0x40c94f={'raw':!![],'where':{'id':_0x50afa1['params']['id']}},_0x115569={};_0x115569['model']=_[_0xf681('0x4a')](db[_0xf681('0x46')]['rawAttributes']);_0x115569['query']=_[_0xf681('0x4a')](_0x50afa1[_0xf681('0x34')]);_0x115569[_0xf681('0x40')]=_['intersection'](_0x115569['model'],_0x115569['query']);_0x40c94f[_0xf681('0x36')]=_[_0xf681('0x35')](_0x115569[_0xf681('0x33')],qs[_0xf681('0x37')](_0x50afa1[_0xf681('0x34')]['fields']));_0x40c94f[_0xf681('0x36')]=_0x40c94f[_0xf681('0x36')][_0xf681('0x38')]?_0x40c94f[_0xf681('0x36')]:_0x115569[_0xf681('0x33')];if(_0x50afa1[_0xf681('0x34')][_0xf681('0x4b')]){_0x40c94f[_0xf681('0x47')]=[{'all':!![]}];}_0x40c94f=_[_0xf681('0x42')]({},_0x40c94f,_0x50afa1[_0xf681('0x45')]);return db[_0xf681('0x46')][_0xf681('0x4c')](_0x40c94f)[_0xf681('0x24')](handleEntityNotFound(_0x176961,null))[_0xf681('0x24')](respondWithResult(_0x176961,null))[_0xf681('0x49')](handleError(_0x176961,null));};exports['create']=function(_0xdbcd7d,_0x13bd3d){return db[_0xf681('0x46')][_0xf681('0x4d')](_0xdbcd7d[_0xf681('0x4e')],{})[_0xf681('0x24')](function(_0x123b78){var _0x50b74c=_0xdbcd7d[_0xf681('0x4f')][_0xf681('0x25')]({'plain':!![]});if(!_0x50b74c)throw new Error(_0xf681('0x50'));if(_0x50b74c[_0xf681('0x51')]==='user'){var _0x23ccfc=_0x123b78[_0xf681('0x25')]({'plain':!![]});var _0x594316=_0xf681('0x26');return db[_0xf681('0x52')][_0xf681('0x4c')]({'where':{'name':_0x594316,'userProfileId':_0x50b74c[_0xf681('0x53')]},'raw':!![]})[_0xf681('0x24')](function(_0x4070a0){if(_0x4070a0&&_0x4070a0[_0xf681('0x54')]===0x0){return db['UserProfileResource'][_0xf681('0x4d')]({'name':_0x23ccfc['name'],'resourceId':_0x23ccfc['id'],'type':_0x4070a0[_0xf681('0x2b')],'sectionId':_0x4070a0['id']},{})[_0xf681('0x24')](function(){return _0x123b78;});}else{return _0x123b78;}})[_0xf681('0x49')](function(_0x2e7da2){logger[_0xf681('0x29')](_0xf681('0x55'),_0x2e7da2);throw _0x2e7da2;});}return _0x123b78;})[_0xf681('0x24')](respondWithResult(_0x13bd3d,0xc9))[_0xf681('0x49')](handleError(_0x13bd3d,null));};exports['update']=function(_0x5eb997,_0x5d3d3f){if(_0x5eb997['body']['id']){delete _0x5eb997['body']['id'];}return db['AnalyticMetric'][_0xf681('0x4c')]({'where':{'id':_0x5eb997[_0xf681('0x56')]['id']}})[_0xf681('0x24')](handleEntityNotFound(_0x5d3d3f,null))[_0xf681('0x24')](saveUpdates(_0x5eb997['body'],null))['then'](respondWithResult(_0x5d3d3f,null))[_0xf681('0x49')](handleError(_0x5d3d3f,null));};exports['destroy']=function(_0x158d97,_0x4555f1){return db['AnalyticMetric'][_0xf681('0x4c')]({'where':{'id':_0x158d97[_0xf681('0x56')]['id']}})[_0xf681('0x24')](handleEntityNotFound(_0x4555f1,null))['then'](removeEntity(_0x4555f1,null))['catch'](handleError(_0x4555f1,null));};