From ee27fc893f66ed811f0d45fa7ecd3a7d0063823e Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Tue, 14 May 2024 14:49:40 +0530 Subject: [PATCH] avniproject/avni-webapp#1225 - status endpoint. log error when running rules. --- Makefile | 11 +++++++++++ package-lock.json | 6 +++--- routes/index.js | 5 +++-- src/controllers/rulesController.js | 8 +++++++- src/services/AuthService.js | 12 +++++++----- 5 files changed, 31 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index bede0c4..e4e0398 100644 --- a/Makefile +++ b/Makefile @@ -8,6 +8,17 @@ start: npm start #ENV='UTC' npm start +start-live-dev: +ifndef user + @echo "Provde the user variable" + exit 1 +endif +ifndef password + @echo "Provde the password variable" + exit 1 +endif + OPENCHS_UPLOAD_USER_USER_NAME=$(user) OPENCHS_UPLOAD_USER_PASSWORD=$(password) npm start + tests: npm test diff --git a/package-lock.json b/package-lock.json index 33373e8..8bf98b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11617,9 +11617,9 @@ } }, "openchs-models": { - "version": "1.31.6", - "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.6.tgz", - "integrity": "sha512-gcosVBegsDRNbQor4pwknXvrppzNVsbIIGwt8DHCB1yIoJYe1nT6LORMmBDVBht3hgEC5jZUhNig/ccjjQV3yg==", + "version": "1.31.48", + "resolved": "https://registry.npmjs.org/openchs-models/-/openchs-models-1.31.48.tgz", + "integrity": "sha512-9eIF+CYPZu+9Ayxqfes2021/58sv/74iZLmzYkyJYadtmvNkxuVW3oTK+8Uj08cgeAiyv0RpQlBXpvZX/3YN3g==", "requires": { "uuid": "^9.0.1" }, diff --git a/routes/index.js b/routes/index.js index 3a96684..35535df 100644 --- a/routes/index.js +++ b/routes/index.js @@ -3,8 +3,8 @@ import { cleanRulesCache, summary, buildObservationAndRunRules, encounterEligibility, - schedule, - message, messagingResponse + messagingResponse, + getStatus } from "../src/controllers/rulesController"; const express = require('express'); @@ -16,5 +16,6 @@ router.post('/api/summaryRule', summary); router.post('/api/encounterEligibility', encounterEligibility); router.post('/api/upload', buildObservationAndRunRules); router.post('/api/messagingRule', messagingResponse); +router.get('/api/status', getStatus); module.exports = router; diff --git a/src/controllers/rulesController.js b/src/controllers/rulesController.js index 19301cb..7ff1e25 100644 --- a/src/controllers/rulesController.js +++ b/src/controllers/rulesController.js @@ -62,6 +62,7 @@ export const buildObservationAndRunRules = async (req, res, next) => { const responseContract = await BuildObservations(req.body); res.status(200).json(responseContract); } catch (err) { + console.log(err); res.status(222) .json({ errors: [`Error in rule server. Message: "${get(err, 'message')}", Stack: "${get(err, 'stack')}"`] @@ -69,7 +70,12 @@ export const buildObservationAndRunRules = async (req, res, next) => { } }; +export const getStatus = async function(req, res, next) { + console.debug("Getting status"); + res.status(200).send('Rule server is up and running with upload user as: ' + process.env.OPENCHS_UPLOAD_USER_USER_NAME); +} + export const rulesController = delegateTo(executeRule); export const summary = delegateTo(executeSummaryRule); export const messagingResponse = delegateTo(executeMessagingRule); -export const encounterEligibility = delegateTo(executeEligibilityCheckRule); \ No newline at end of file +export const encounterEligibility = delegateTo(executeEligibilityCheckRule); diff --git a/src/services/AuthService.js b/src/services/AuthService.js index 551c83c..5cc440b 100644 --- a/src/services/AuthService.js +++ b/src/services/AuthService.js @@ -1,6 +1,7 @@ import cognitoDetails from "./CognitoDetails"; import api from "./api"; import {Auth} from 'aws-amplify'; +import _ from 'lodash'; // During CSV upload token sent by the java server might expire so we use upload-user for // communicating the java server @@ -26,19 +27,20 @@ const setupUploadUser = async () => { const currentUser = await Auth.currentUserInfo(); console.log("Current user info ", currentUser); if (_.isEmpty(currentUser) || currentUser.username !== 'upload-user') { - await sigIn(); + await signIn(); } }; -const sigIn = async () => { +const signIn = async function () { + console.debug("Signing in for upload user: ", process.env.OPENCHS_UPLOAD_USER_USER_NAME); await Auth.signIn(process.env.OPENCHS_UPLOAD_USER_USER_NAME, process.env.OPENCHS_UPLOAD_USER_PASSWORD); }; export const getUploadUserToken = async () => { - if(cognitoDetails.isDummy()) return null; - console.log("Getting upload user token"); + if (cognitoDetails.isDummy()) return null; + console.debug("Getting upload user token"); const currentSession = await Auth.currentSession(); const jwtToken = currentSession.idToken.jwtToken; - console.log("Upload user token ", jwtToken); + console.debug("Upload user token ", jwtToken); return jwtToken; };