Skip to content

Commit

Permalink
add submission context and review page
Browse files Browse the repository at this point in the history
  • Loading branch information
KjartanE committed Dec 9, 2023
1 parent a07f86a commit ace08d2
Show file tree
Hide file tree
Showing 18 changed files with 654 additions and 136 deletions.
22 changes: 22 additions & 0 deletions api/src/openapi/root-api-doc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,28 @@ export const rootAPIDoc = {
}
},
additionalProperties: false
},
feature: {
type: 'object',
required: ['submission_feature_id', 'submission_id', 'feature_type', 'data', 'parent_submission_feature_id'],
properties: {
submission_feature_id: {
type: 'number'
},
submission_id: {
type: 'number'
},
feature_type: {
type: 'string'
},
data: {
type: 'object'
},
parent_submission_feature_id: {
type: 'number',
nullable: true
}
}
}
}
}
Expand Down
77 changes: 0 additions & 77 deletions api/src/paths/dataset/{datasetId}/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import { ValidationService } from '../../services/validation-service';
import { getKeycloakSource } from '../../utils/keycloak-utils';
import { getLogger } from '../../utils/logger';

const defaultLog = getLogger('paths/dataset/intake');
const defaultLog = getLogger('paths/submission/intake');

/*
TODO: UPDATED PATH TO SUBMISSION/INTAKE NEED TO UPDATE SIMS TO USE THIS PATH
*/

export const POST: Operation = [
authorizeRequestHandler(() => {
Expand All @@ -23,12 +27,12 @@ export const POST: Operation = [
]
};
}),
datasetIntake()
submissionIntake()
];

POST.apiDoc = {
description: 'Submit dataset to BioHub',
tags: ['dataset'],
description: 'Submit submission to BioHub',
tags: ['submission'],
security: [
{
Bearer: []
Expand All @@ -48,7 +52,7 @@ POST.apiDoc = {
},
type: {
type: 'string',
enum: ['dataset']
enum: ['submission']
},
properties: {
title: 'Dataset properties',
Expand Down Expand Up @@ -89,7 +93,7 @@ POST.apiDoc = {
}
};

export function datasetIntake(): RequestHandler {
export function submissionIntake(): RequestHandler {
return async (req, res) => {
const sourceSystem = getKeycloakSource(req['keycloak_token']);

Expand All @@ -99,7 +103,7 @@ export function datasetIntake(): RequestHandler {
]);
}

const dataset = {
const submission = {
...req.body,
properties: { ...req.body.properties, additionalInformation: req.body.properties.additionalInformation }
};
Expand All @@ -113,21 +117,21 @@ export function datasetIntake(): RequestHandler {
const submissionService = new SubmissionService(connection);
const validationService = new ValidationService(connection);

// validate the dataset submission
if (!(await validationService.validateDatasetSubmission(dataset))) {
throw new HTTP400('Invalid dataset submission');
// validate the submission submission
if (!(await validationService.validateDatasetSubmission(submission))) {
throw new HTTP400('Invalid submission submission');
}

// insert the submission record
const response = await submissionService.insertSubmissionRecordWithPotentialConflict(id);

// insert each submission feature record
await submissionService.insertSubmissionFeatureRecords(response.submission_id, dataset.features);
await submissionService.insertSubmissionFeatureRecords(response.submission_id, submission.features);

await connection.commit();
res.status(200).json(response);
} catch (error) {
defaultLog.error({ label: 'datasetIntake', message: 'error', error });
defaultLog.error({ label: 'submissionIntake', message: 'error', error });
await connection.rollback();
throw error;
} finally {
Expand Down
126 changes: 126 additions & 0 deletions api/src/paths/submission/{submissionUUID}/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { RequestHandler } from 'express';
import { Operation } from 'express-openapi';
import { getAPIUserDBConnection, getDBConnection } from '../../../database/db';
import { defaultErrorResponses } from '../../../openapi/schemas/http-responses';
import { SubmissionService } from '../../../services/submission-service';
import { getLogger } from '../../../utils/logger';

const defaultLog = getLogger('paths/submission/{submissionUUID}}');

export const GET: Operation = [getSubmissionInformation()];

GET.apiDoc = {
description: 'retrieves submission data from the submission table',
tags: ['eml'],
security: [
{
OptionalBearer: []
}
],
parameters: [
{
description: 'submission uuid',
in: 'path',
name: 'submissionUUID',
schema: {
type: 'string',
format: 'uuid'
},
required: true
}
],
responses: {
200: {
description: 'Dataset metadata response object.',
content: {
'application/json': {
schema: {
type: 'object',
required: ['submission', 'features'],
properties: {
submission: {
type: 'object',
required: ['submission_id', 'uuid', 'security_review_timestamp'],
properties: {
submission_id: {
type: 'number'
},
uuid: {
type: 'string',
format: 'uuid'
},
security_review_timestamp: {
type: 'string',
format: 'date-time',
nullable: true
}
}
},
features: {
required: ['dataset', 'sampleSites', 'animals', 'observations'],
properties: {
dataset: {
type: 'array',
items: {
$ref: '#/components/schemas/feature'
}
},
sampleSites: {
type: 'array',
items: {
$ref: '#/components/schemas/feature'
}
},
animals: {
type: 'array',
items: {
$ref: '#/components/schemas/feature'
}
},
observations: {
type: 'array',
items: {
$ref: '#/components/schemas/feature'
}
}
}
}
}
}
}
}
},
...defaultErrorResponses
}
};

/**
* Retrieves submission data from the submission table.
*
* @returns {RequestHandler}
*/
export function getSubmissionInformation(): RequestHandler {
return async (req, res) => {
const connection = req['keycloak_token'] ? getDBConnection(req['keycloak_token']) : getAPIUserDBConnection();

const submissionUUID = String(req.params.submissionUUID);

try {
await connection.open();

const submissionService = new SubmissionService(connection);

const result = await submissionService.getSubmissionAndFeaturesBySubmissionUUID(submissionUUID);

await connection.commit();

res.status(200).json(result);
} catch (error) {
defaultLog.error({ label: 'getSubmissionInformation', message: 'error', error });
await connection.rollback();
throw error;
} finally {
connection.release();
}
};
}
Loading

0 comments on commit ace08d2

Please sign in to comment.