Skip to content

Commit

Permalink
add put endpt for kb matched statements
Browse files Browse the repository at this point in the history
  • Loading branch information
elewis2 committed Jan 29, 2025
1 parent 90e990b commit 598eb61
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions app/routes/report/kbMatch/kbMatchedStatements.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ const router = express.Router({mergeParams: true});
const db = require('../../../models');
const logger = require('../../../log');

const schemaGenerator = require('../../../schemas/schemaGenerator');
const validateAgainstSchema = require('../../../libs/validateAgainstSchema');
const {REPORT_UPDATE_BASE_URI} = require('../../../constants');

const updateSchema = schemaGenerator(db.models.kbMatchedStatements, {
baseUri: REPORT_UPDATE_BASE_URI,
nothingRequired: true,
});

// Middleware for kbMatchedStatements
router.param('kbMatchedStatement', async (req, res, next, kbMatchedStatementIdent) => {
let result;
Expand Down Expand Up @@ -43,6 +52,22 @@ router.route('/:kbMatchedStatement([A-z0-9-]{36})')
.get((req, res) => {
return res.json(req.returnStatement);
})
.put(async (req, res) => {
try {
validateAgainstSchema(updateSchema, req.body, false);
} catch (error) {
const message = `Error while validating patient information update request ${error}`;
logger.error(message);
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
}
try {
await req.kbMatchedStatement.update(req.body, {userId: req.user.id});
return res.json(req.kbMatchedStatement.view('public'));
} catch (error) {
logger.error(`Unable to update kbMatchedStatement ${error}`);
return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({error: {message: 'Unable to update kbMatchedStatement'}});
}
})
.delete(async (req, res) => {
// Soft delete the entry
try {
Expand Down

0 comments on commit 598eb61

Please sign in to comment.