feat(api): /request/count endpoint (#682)

pull/683/head
TheCatLady 4 years ago committed by GitHub
parent 70229d12ab
commit 192cfd8a8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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

@ -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';

Loading…
Cancel
Save