]>
Commit | Line | Data |
---|---|---|
0c9668f7 C |
1 | import express from 'express' |
2 | import { param } from 'express-validator' | |
3 | import { isIdValid } from '@server/helpers/custom-validators/misc' | |
4 | import { RunnerRegistrationTokenModel } from '@server/models/runner/runner-registration-token' | |
5 | import { forceNumber } from '@shared/core-utils' | |
6 | import { HttpStatusCode } from '@shared/models' | |
7 | import { areValidationErrors } from '../shared/utils' | |
8 | ||
9 | const tags = [ 'runner' ] | |
10 | ||
11 | const deleteRegistrationTokenValidator = [ | |
12 | param('id').custom(isIdValid), | |
13 | ||
14 | async (req: express.Request, res: express.Response, next: express.NextFunction) => { | |
15 | if (areValidationErrors(req, res, { tags })) return | |
16 | ||
17 | const registrationToken = await RunnerRegistrationTokenModel.load(forceNumber(req.params.id)) | |
18 | ||
19 | if (!registrationToken) { | |
20 | return res.fail({ | |
21 | status: HttpStatusCode.NOT_FOUND_404, | |
22 | message: 'Registration token not found', | |
23 | tags | |
24 | }) | |
25 | } | |
26 | ||
27 | res.locals.runnerRegistrationToken = registrationToken | |
28 | ||
29 | return next() | |
30 | } | |
31 | ] | |
32 | ||
33 | // --------------------------------------------------------------------------- | |
34 | ||
35 | export { | |
36 | deleteRegistrationTokenValidator | |
37 | } |