Skip to content

Commit

Permalink
Feat/#1094 list programs with exceptions (#1112)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
ciaranschutte and Ciaran Schutte authored Jan 23, 2024
1 parent 7c9849c commit 789dcc1
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
16 changes: 14 additions & 2 deletions src/exception/missing-entity-exceptions/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() });
Expand Down Expand Up @@ -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);
}
}
}
Expand Down
31 changes: 29 additions & 2 deletions src/resources/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -858,7 +858,7 @@ paths:

responses:
'200':
description: 'successful upload'
description: 'Successfully created or updated missing entity exception.'
content:
application/json:
schema:
Expand All @@ -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:
Expand Down Expand Up @@ -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
5 changes: 5 additions & 0 deletions src/routes/exception/missing-entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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...' }),
);
Expand Down

0 comments on commit 789dcc1

Please sign in to comment.