Skip to content

Commit

Permalink
avniproject/avni-webapp#1225 - status endpoint. log error when runnin…
Browse files Browse the repository at this point in the history
…g rules.
  • Loading branch information
petmongrels committed May 14, 2024
1 parent 5830874 commit ee27fc8
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import {
cleanRulesCache,
summary,
buildObservationAndRunRules, encounterEligibility,
schedule,
message, messagingResponse
messagingResponse,
getStatus
} from "../src/controllers/rulesController";

const express = require('express');
Expand All @@ -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;
8 changes: 7 additions & 1 deletion src/controllers/rulesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,20 @@ 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')}"`]
})
}
};

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);
export const encounterEligibility = delegateTo(executeEligibilityCheckRule);
12 changes: 7 additions & 5 deletions src/services/AuthService.js
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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;
};

0 comments on commit ee27fc8

Please sign in to comment.