From 192cfd8a8ea9ab942d5bb265d42050917a2f5a04 Mon Sep 17 00:00:00 2001 From: TheCatLady <52870424+TheCatLady@users.noreply.github.com> Date: Mon, 18 Jan 2021 19:33:30 -0500 Subject: [PATCH] feat(api): /request/count endpoint (#682) --- overseerr-api.yml | 24 ++++++++++++++++++++++++ server/routes/request.ts | 23 ++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/overseerr-api.yml b/overseerr-api.yml index ff614bbcc..d77b596bd 100644 --- a/overseerr-api.yml +++ b/overseerr-api.yml @@ -2486,6 +2486,30 @@ paths: application/json: schema: $ref: '#/components/schemas/MediaRequest' + /request/count: + get: + summary: Returns request counts + description: | + Returns the number of pending and approved requests. + tags: + - request + responses: + '200': + description: Request counts returned + content: + application/json: + schema: + type: object + properties: + pending: + type: number + example: 0 + approved: + type: number + example: 10 + required: + - pending + - approved /request/{requestId}: get: summary: Requests a specific MediaRequest diff --git a/server/routes/request.ts b/server/routes/request.ts index 2d0455236..baa736164 100644 --- a/server/routes/request.ts +++ b/server/routes/request.ts @@ -221,11 +221,31 @@ requestRoutes.post( next({ status: 500, message: 'Invalid media type' }); } catch (e) { - next({ message: e.message, status: 500 }); + next({ status: 500, message: e.message }); } } ); +requestRoutes.get('/count', async (_req, res, next) => { + const requestRepository = getRepository(MediaRequest); + + try { + const pendingCount = await requestRepository.count({ + status: MediaRequestStatus.PENDING, + }); + const approvedCount = await requestRepository.count({ + status: MediaRequestStatus.APPROVED, + }); + + return res.status(200).json({ + pending: pendingCount, + approved: approvedCount, + }); + } catch (e) { + next({ status: 500, message: e.message }); + } +}); + requestRoutes.get('/:requestId', async (req, res, next) => { const requestRepository = getRepository(MediaRequest); @@ -392,6 +412,7 @@ requestRoutes.post<{ } } ); + requestRoutes.get<{ requestId: string; status: 'pending' | 'approve' | 'decline';