Skip to content

Commit

Permalink
Merge branch 'develop' into feature/DEVSU-2543-auto-image-sizing
Browse files Browse the repository at this point in the history
  • Loading branch information
elewis2 authored Jan 30, 2025
2 parents e64c3df + 926629e commit 73f34db
Show file tree
Hide file tree
Showing 2 changed files with 60 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
35 changes: 35 additions & 0 deletions test/routes/report/kbMatch/kbMatchedStatements.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,41 @@ describe('/reports/{REPORTID}/kb-matches/kb-matched-statements', () => {
});
});

describe('PUT', () => {
let statementUpdate;

beforeEach(async () => {
statementUpdate = await db.models.kbMatchedStatements.create(createDataStatement);
await db.models.kbMatchJoin.create({kbMatchId: kbMatch.id, kbMatchedStatementId: statementUpdate.id});
});

afterEach(async () => {
if (statementUpdate) {
await db.models.kbMatchedStatements.destroy({where: {ident: statementUpdate.ident}});
}
});

test('/{kbMatchedStatements} - 200 Successful statement put', async () => {
const UPDATE_DATA = JSON.parse(JSON.stringify(statementUpdate));
UPDATE_DATA.category = 'prognostic';
UPDATE_DATA.kbData = {test: 'test2'};
const popFields = ['createdAt', 'createdBy', 'updatedAt', 'updatedBy', 'deletedAt', 'deletedBy', 'id', 'ident', 'reportId'];
popFields.forEach((item) => {
delete UPDATE_DATA[item];
});

const res = await request
.put(`/api/reports/${report.ident}/kb-matches/kb-matched-statements/${statementUpdate.ident}`)
.send(UPDATE_DATA)
.auth(username, password)
.type('json')
.expect(HTTP_STATUS.OK);

checkStatement(res.body);
expect(res.body).toEqual(expect.objectContaining(UPDATE_DATA));
});
});

describe('DELETE', () => {
let statementDelete;

Expand Down

0 comments on commit 73f34db

Please sign in to comment.