Skip to content

Commit b44c388

Browse files
Merge branch 'develop' into feature/DEVSU-2656-email-notification
2 parents 970e89f + 55ae893 commit b44c388

2 files changed

Lines changed: 46 additions & 34 deletions

File tree

app/routes/report/observedVariantAnnotations.js

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const HTTP_STATUS = require('http-status-codes');
1+
const {StatusCodes} = require('http-status-codes');
22
const express = require('express');
33

44
const router = express.Router({mergeParams: true});
@@ -33,12 +33,16 @@ router.param('observedVariantAnnotation', async (req, res, next, ident) => {
3333
});
3434
} catch (error) {
3535
logger.error(`Error while getting observed variant annotation ${error}`);
36-
return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({error: {message: 'Error while getting observed variant annotation'}});
36+
return res
37+
.status(StatusCodes.INTERNAL_SERVER_ERROR)
38+
.json({error: {message: 'Error while getting observed variant annotation'}});
3739
}
3840

3941
if (!result) {
4042
logger.error(`Unable to find observed variant annotation, ident: ${ident}`);
41-
return res.status(HTTP_STATUS.NOT_FOUND).json({error: {message: `Unable to find observed variant annotation, ident: ${ident}`}});
43+
return res
44+
.status(StatusCodes.NOT_FOUND)
45+
.json({error: {message: `Unable to find observed variant annotation, ident: ${ident}`}});
4246
}
4347

4448
// Add observed variant annotation to request
@@ -56,7 +60,7 @@ router.route('/')
5660
} catch (error) {
5761
const message = `Error checking variant type ${error}`;
5862
logger.error(message);
59-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
63+
return res.status(StatusCodes.BAD_REQUEST).json({error: {message}});
6064
}
6165

6266
// Check that the variant is in the db
@@ -68,13 +72,13 @@ router.route('/')
6872
} catch (error) {
6973
const message = `Error while checking that linked variant exists ${error}`;
7074
logger.error(message);
71-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
75+
return res.status(StatusCodes.BAD_REQUEST).json({error: {message}});
7276
}
7377

7478
if (!(variant)) {
7579
const message = 'Variant not found';
7680
logger.error(message);
77-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
81+
return res.status(StatusCodes.BAD_REQUEST).json({error: {message}});
7882
}
7983

8084
// add the variant id and remove the ident
@@ -87,7 +91,7 @@ router.route('/')
8791
} catch (error) {
8892
const message = `Error while validating observed variant annotation create request ${error}`;
8993
logger.error(message);
90-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
94+
return res.status(StatusCodes.BAD_REQUEST).json({error: {message}});
9195
}
9296

9397
// check whether there is already a record for this variant id; don't make another one
@@ -103,12 +107,20 @@ router.route('/')
103107
} catch (error) {
104108
const message = `Error while checking for preexisting annotation record ${error}`;
105109
logger.error(message);
106-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
110+
return res.status(StatusCodes.BAD_REQUEST).json({error: {message}});
107111
}
108112
if (annotation) {
109113
const message = 'Annotation record already exists for this variant';
110114
logger.error(message);
111-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
115+
return res.status(StatusCodes.CONFLICT).json({
116+
error: {message},
117+
data: {
118+
ident: annotation.ident,
119+
variantId: req.body.variantId,
120+
variantType: req.body.variantType,
121+
reportId: req.report.id,
122+
},
123+
});
112124
}
113125

114126
// Create new entry in db
@@ -117,10 +129,10 @@ router.route('/')
117129
...req.body,
118130
reportId: req.report.id,
119131
});
120-
return res.status(HTTP_STATUS.CREATED).json(result.view('public'));
132+
return res.status(StatusCodes.CREATED).json(result.view('public'));
121133
} catch (error) {
122134
logger.error(`Unable to create mutation burden ${error}`);
123-
return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
135+
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
124136
error: {message: 'Unable to create mutation burden'},
125137
});
126138
}
@@ -135,15 +147,15 @@ router.route('/:observedVariantAnnotation([A-z0-9-]{36})')
135147
} catch (error) {
136148
const message = `Error while validating observed variant annotation update request ${error}`;
137149
logger.error(message);
138-
return res.status(HTTP_STATUS.BAD_REQUEST).json({error: {message}});
150+
return res.status(StatusCodes.BAD_REQUEST).json({error: {message}});
139151
}
140152

141153
try {
142154
await req.observedVariantAnnotation.update(req.body, {userId: req.user.id});
143155
return res.json(req.observedVariantAnnotation.view('public'));
144156
} catch (error) {
145157
logger.error(`Unable to create update observed variant annotation ${error}`);
146-
return res.status(HTTP_STATUS.INTERNAL_SERVER_ERROR).json({
158+
return res.status(StatusCodes.INTERNAL_SERVER_ERROR).json({
147159
error: {message: 'Unable to create observed variant annotation'},
148160
});
149161
}

test/routes/report/observedVariantAnnotations.test.js

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const HTTP_STATUS = require('http-status-codes');
1+
const {StatusCodes} = require('http-status-codes');
22

33
const supertest = require('supertest');
44
const getPort = require('get-port');
@@ -34,7 +34,7 @@ const getVariantByIdent = async (ident, reportIdent) => {
3434
.query()
3535
.auth(username, password)
3636
.type('json')
37-
.expect(HTTP_STATUS.OK);
37+
.expect(StatusCodes.OK);
3838

3939
const checkVar = allVars.body.filter((item) => {
4040
return item.ident === ident;
@@ -86,7 +86,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
8686
.query({rapidTable: 'therapeuticAssociation'})
8787
.auth(username, password)
8888
.type('json')
89-
.expect(HTTP_STATUS.OK);
89+
.expect(StatusCodes.OK);
9090

9191
const allvars = res.body.filter((variant) => {
9292
return variant.variantType === 'cnv'; // choose a random nontherapeutic example
@@ -102,7 +102,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
102102
variantIdent: variant.ident,
103103
annotations: {rapidReportTableTag: 'cancerRelevance'},
104104
})
105-
.expect(HTTP_STATUS.CREATED);
105+
.expect(StatusCodes.CREATED);
106106

107107
const checkVar = await getVariantByIdent(variant.ident, rapidReportIdent.ident);
108108
const annotation = checkVar.observedVariantAnnotation;
@@ -120,7 +120,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
120120
variantIdent: 'hello',
121121
annotations: {rapidReportTableTag: 'therapeutic'},
122122
})
123-
.expect(HTTP_STATUS.BAD_REQUEST);
123+
.expect(StatusCodes.BAD_REQUEST);
124124
});
125125

126126
test('Does not create new annotation with fake variant type- OK', async () => {
@@ -133,7 +133,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
133133
variantIdent: 'hello',
134134
annotations: {rapidReportTableTag: 'therapeutic'},
135135
})
136-
.expect(HTTP_STATUS.BAD_REQUEST);
136+
.expect(StatusCodes.BAD_REQUEST);
137137
});
138138

139139
test('Does not create new annotation when variant already has one - OK', async () => {
@@ -142,7 +142,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
142142
.query({rapidTable: 'unknownSignificance'})
143143
.auth(username, password)
144144
.type('json')
145-
.expect(HTTP_STATUS.OK);
145+
.expect(StatusCodes.OK);
146146

147147
const allvars = res.body.filter((variant) => {
148148
return variant.variantType === 'mut';
@@ -158,7 +158,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
158158
variantIdent: variant.ident,
159159
annotations: {rapidReportTableTag: 'therapeutic'},
160160
})
161-
.expect(HTTP_STATUS.CREATED);
161+
.expect(StatusCodes.CREATED);
162162

163163
await request
164164
.post(`/api/reports/${rapidReportIdent.ident}/observed-variant-annotations`)
@@ -169,7 +169,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
169169
variantIdent: variant.ident,
170170
annotations: {rapidReportTableTag: 'cancerRelevance'},
171171
})
172-
.expect(HTTP_STATUS.BAD_REQUEST);
172+
.expect(StatusCodes.CONFLICT);
173173
});
174174
});
175175

@@ -181,7 +181,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
181181
.query({rapidTable: 'unknownSignificance'})
182182
.auth(username, password)
183183
.type('json')
184-
.expect(HTTP_STATUS.OK);
184+
.expect(StatusCodes.OK);
185185

186186
const allvars = res.body.filter((variant) => {
187187
return variant.variantType === 'mut';
@@ -201,7 +201,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
201201
variantIdent: origVariant.ident,
202202
annotations,
203203
})
204-
.expect(HTTP_STATUS.CREATED);
204+
.expect(StatusCodes.CREATED);
205205

206206
// get the created variant annotation and check it's correct
207207
const createdVar = await getVariantByIdent(origVariant.ident, rapidReportIdent.ident);
@@ -219,7 +219,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
219219
.send({
220220
annotations,
221221
})
222-
.expect(HTTP_STATUS.OK);
222+
.expect(StatusCodes.OK);
223223

224224
// get the new variant data
225225
const updatedVar = await getVariantByIdent(origVariant.ident, rapidReportIdent.ident);
@@ -239,7 +239,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
239239
.get(`/api/reports/${reportIdent.ident}/${endpt}`)
240240
.auth(username, password)
241241
.type('json')
242-
.expect(HTTP_STATUS.OK);
242+
.expect(StatusCodes.OK);
243243

244244
let record;
245245
let annotation;
@@ -262,7 +262,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
262262
variantIdent: record.ident,
263263
annotations,
264264
})
265-
.expect(HTTP_STATUS.CREATED);
265+
.expect(StatusCodes.CREATED);
266266

267267
let url = `/api/reports/${reportIdent.ident}/${endpt}/${record.ident}`;
268268
if (variantType === 'tmb') {
@@ -273,7 +273,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
273273
.get(url)
274274
.auth(username, password)
275275
.type('json')
276-
.expect(HTTP_STATUS.OK);
276+
.expect(StatusCodes.OK);
277277
const record2 = res2.body;
278278
expect(record2.observedVariantAnnotation.annotations.testTag).toEqual(annotations.testTag);
279279
});
@@ -283,7 +283,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
283283
.get(`/api/reports/${reportIdent.ident}/variants`)
284284
.auth(username, password)
285285
.type('json')
286-
.expect(HTTP_STATUS.OK);
286+
.expect(StatusCodes.OK);
287287

288288
expect(Array.isArray(res.body)).toBe(true);
289289

@@ -307,13 +307,13 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
307307
variantIdent: record.ident,
308308
annotations,
309309
})
310-
.expect(HTTP_STATUS.CREATED);
310+
.expect(StatusCodes.CREATED);
311311

312312
const res2 = await request
313313
.get(`/api/reports/${reportIdent.ident}/variants`)
314314
.auth(username, password)
315315
.type('json')
316-
.expect(HTTP_STATUS.OK);
316+
.expect(StatusCodes.OK);
317317
const updatedRecord = res2.body.filter((variant) => {
318318
return variant.ident === record.ident;
319319
})[0];
@@ -325,7 +325,7 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
325325
.get(`/api/reports/${rapidReportIdent.ident}/variants`)
326326
.auth(username, password)
327327
.type('json')
328-
.expect(HTTP_STATUS.OK);
328+
.expect(StatusCodes.OK);
329329

330330
expect(Array.isArray(res.body)).toBe(true);
331331

@@ -347,14 +347,14 @@ describe('/reports/{REPORTID}/observed-variant-annotations', () => {
347347
variantIdent: record.ident,
348348
annotations: {rapidReportTableTag: 'cancerRelevance', testTag: 'testValue'},
349349
})
350-
.expect(HTTP_STATUS.CREATED);
350+
.expect(StatusCodes.CREATED);
351351

352352
const res2 = await request
353353
.get(`/api/reports/${rapidReportIdent.ident}/variants`)
354354
.query({rapidTable: 'cancerRelevance'})
355355
.auth(username, password)
356356
.type('json')
357-
.expect(HTTP_STATUS.OK);
357+
.expect(StatusCodes.OK);
358358
const updatedRecord = res2.body.filter((variant) => {
359359
return variant.ident === record.ident;
360360
})[0];

0 commit comments

Comments
 (0)