From 789dcc15a15bb04993e16dfc51f6e60a9472ddbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20Sch=C3=BCtte?= Date: Tue, 23 Jan 2024 14:04:41 -0500 Subject: [PATCH] Feat/#1094 list programs with exceptions (#1112) * routing renaming and split into individual files * update missing entity route params * add route * add repo call * update swagger * remove duplicate route file. fix status code * fix route import * update swagger --------- Co-authored-by: Ciaran Schutte --- .../missing-entity-exceptions/api.ts | 16 ++++++++-- src/resources/swagger.yaml | 31 +++++++++++++++++-- src/routes/exception/missing-entity.ts | 5 +++ 3 files changed, 48 insertions(+), 4 deletions(-) diff --git a/src/exception/missing-entity-exceptions/api.ts b/src/exception/missing-entity-exceptions/api.ts index 44407f29..75313df1 100644 --- a/src/exception/missing-entity-exceptions/api.ts +++ b/src/exception/missing-entity-exceptions/api.ts @@ -17,13 +17,25 @@ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -import { HasFullWriteAccess } from '../../decorators'; +import { HasFullReadAccess, HasFullWriteAccess } from '../../decorators'; import { Request, Response } from 'express'; import { parseBoolString } from '../../utils/request'; import * as service from './service'; import { z as zod } from 'zod'; +import { listAll } from './repo'; class MissingEntityExceptionController { + @HasFullReadAccess() + async listMissingEntityExceptions(req: Request, res: Response) { + const result = await listAll(); + if (!result.success) { + const { message, errors } = result; + return res.status(500).send({ message, errors }); + } else { + return res.status(200).send(result.exception); + } + } + @HasFullWriteAccess() async createEntityException(req: Request, res: Response) { const createRequestBody = zod.object({ donorSubmitterIds: zod.string().array() }); @@ -51,7 +63,7 @@ class MissingEntityExceptionController { const { message, errors } = result; return res.status(500).send({ message, errors }); } else { - return res.status(201).send(result.exception); + return res.status(200).send(result.exception); } } } diff --git a/src/resources/swagger.yaml b/src/resources/swagger.yaml index 9e34798b..169f4741 100644 --- a/src/resources/swagger.yaml +++ b/src/resources/swagger.yaml @@ -845,7 +845,7 @@ paths: /exception/missing-entity/${programId}: post: tags: - - Exception + - 'Exception - Missing Entity' summary: Add submitter donor ids for exception parameters: - $ref: '#/components/parameters/PathProgramId' @@ -858,7 +858,7 @@ paths: responses: '200': - description: 'successful upload' + description: 'Successfully created or updated missing entity exception.' content: application/json: schema: @@ -870,6 +870,23 @@ paths: '401': $ref: '#/components/responses/UnauthorizedError' + /exception/missing-entity: + get: + tags: + - 'Exception - Missing Entity' + summary: Get programs with missing entity exceptions. Return amount of donor submitter exceptions. + parameters: + - $ref: '#/components/parameters/PathProgramId' + responses: + '200': + description: 'Successfully retrieved list of programs with exceptions.' + content: + application/json: + schema: + $ref: '#/components/responses/MissingEntityListResponse' + '401': + $ref: '#/components/responses/UnauthorizedError' + /clinical/donors/tsv: post: tags: @@ -1896,3 +1913,13 @@ components: donorsUnchangedCount: description: 'Amount of donors left unchanged.' type: integer + + MissingEntityListResponse: + type: array + items: + type: object + properties: + programId: + type: string + donorCount: + type: integer diff --git a/src/routes/exception/missing-entity.ts b/src/routes/exception/missing-entity.ts index 42be6d89..f66ee7ef 100644 --- a/src/routes/exception/missing-entity.ts +++ b/src/routes/exception/missing-entity.ts @@ -27,6 +27,11 @@ import missingEntityExceptionApi from '../../exception/missing-entity-exceptions const missingEntityExceptionRouter = express.Router({ mergeParams: true }); // GET +missingEntityExceptionRouter.get( + '/', + wrapAsync(missingEntityExceptionApi.listMissingEntityExceptions), +); + missingEntityExceptionRouter.get('/:programId', (req, resp) => resp.status(500).send({ msg: 'not implemented yet...' }), );