Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions app/Controllers/Http/ParticipantController.js
Original file line number Diff line number Diff line change
Expand Up @@ -668,12 +668,21 @@ class ParticipantController {
*/
async fetchJobs ({ params, request, response, transform }) {
const { identifier, studyID } = params
const { from, to } = request.all()
const { from, to, status_id: statusId } = request.all()

if (to && from && to <= from) {
return response.badRequest({ message: 'To cannot be smaller than or equal to From' })
}

if (
statusId !== undefined &&
![1, 2, 3].includes(Number(statusId))
) {
return response.badRequest({
message: 'Invalid job status ID'
})
}

// Fetch the participant first as a separate step so that we have their
// numeric ID available to filter jobResults below. If we tried to do this
// in a single chained query we wouldn't have the ID yet when we need it.
Expand All @@ -690,6 +699,11 @@ class ParticipantController {
if (to) {
query.where('position', '<', to)
}

if (statusId !== undefined) {
query.whereInPivot('status_id', [Number(statusId)])
}

query
.where('study_id', studyID)
.orderBy('position', 'asc')
Expand All @@ -703,7 +717,7 @@ class ParticipantController {
// in-memory relations map. This does NOT hit the database — it simply
// reads what was stored there by the load() call above.
const jobs = participant.getRelated('jobs')
if (jobs.length === 0) {
if (jobs.length === 0 && statusId === undefined) {
return response.notFound(`No jobs were found for study ID ${studyID}`)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,13 +218,16 @@ export default {
this.$set(this.loadingResets, participant.id, true)
try {
const response = await this.$axios.get(
`${API_PREFIX}/participants/${participant.identifier}/${studyId}/jobs`
)
const finishedJobs = response.data.data.filter(
job => job.pivot && job.pivot.status_id === 3
`${API_PREFIX}/participants/${participant.identifier}/${studyId}/jobs`,
{
params: {
status_id: 3
}
}
)

this.dialog.selectedParticipant = participant
this.dialog.finishedJobs = finishedJobs
this.dialog.finishedJobs = response.data.data
this.dialog.resetJobs = true
} catch (e) {
processErrors(e, this.notify)
Expand Down