Skip to content

Commit

Permalink
#622 return review status of reviewed detection back
Browse files Browse the repository at this point in the history
  • Loading branch information
grindarius committed May 30, 2024
1 parent 86a99bd commit 42289f6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
14 changes: 13 additions & 1 deletion core/detections/bl/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,12 @@ async function createOrUpdate (options) {
throw new EmptyResultError('Detection with given parameters not found')
}
const status = reviewsDao.REVIEW_STATUS_MAPPING[options.status]
return sequelize.transaction(async (transaction) => {
const finalReviewStatus = sequelize.transaction(async (transaction) => {
/**
* @type {Array<{ id: number, status: 'unreviewed' | 'rejected' | 'uncertain' | 'confirmed'}>}
*/
const finalReviewStatuses = []

for (const detection of detections) {
let review = (await reviewsDao.query({ detectionIds: [detection.id], userId }, { fields: ['id'], transaction }))[0]
const exists = !!review
Expand All @@ -54,6 +59,11 @@ async function createOrUpdate (options) {
}

const updatedStatus = await refreshDetectionReviewStatus(detection.id, whereOptionsToUpdate, transaction)
finalReviewStatuses.push({
id: detection.id,
status: DetectionReview.statusMapping[`${updatedStatus}`] === 'null' ? 'unreviewed' : DetectionReview.statusMapping[`${updatedStatus}`]
})

// Update summary if reviewStatus changed
if (updatedStatus !== detection.review_status) {
const updatedStatusLabel = DetectionReview.statusMapping[`${updatedStatus}`] // used for increment
Expand All @@ -71,6 +81,8 @@ async function createOrUpdate (options) {
}
}
}

return finalReviewStatus
})
}

Expand Down
31 changes: 27 additions & 4 deletions core/detections/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,31 @@ const Converter = require('../../common/converter')
* 200:
* description: Success
* content:
* text/plain:
* application/json:
* description: An array of objects with `id` of detection and the `status` that the detection gets changed to.
* schema:
* type: string
* example: 'OK'
* type: array
* items:
* type: object
* properties:
* id:
* description: The id of the detection that gets reviewed
* example: 1218122
* schema:
* type: number
* format: int64
* status:
* description: The status of the detection that gets reviewed
* schema:
* type: string
* enum:
* - "unreviewed"
* - "rejected"
* - "uncertain"
* - "confirmed"
* example: "unreviewed"
* example: [{"id":1218123,"value":"unreviewed"},{"id":1213994,"value":"confirmed"}]
*
* 400:
* description: Invalid query parameters
* 5XX:
Expand All @@ -62,7 +83,9 @@ router.post('/:streamId/detections/:start/review', (req, res) => {
const { status, classification, classifier, classifierJob } = params
return await createOrUpdate({ userId, streamId, start, status, classification, classifier, classifierJob })
})
.then(() => res.sendStatus(200))
.then((status) => {
res.send(status)
})
.catch(httpErrorHandler(req, res, 'Failed reviewing the detection'))
})

Expand Down

0 comments on commit 42289f6

Please sign in to comment.