]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/helpers/middlewares/abuses.ts
Refactor server errors handler
[github/Chocobozzz/PeerTube.git] / server / helpers / middlewares / abuses.ts
CommitLineData
453e83ea 1import { Response } from 'express'
d95d1559 2import { AbuseModel } from '../../models/abuse/abuse'
2d53be02 3import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
453e83ea 4
57f6896f 5async function doesAbuseExist (abuseId: number | string, res: Response) {
94148c90 6 const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10))
d95d1559 7
57f6896f 8 if (!abuse) {
76148b27
RK
9 res.fail({
10 status: HttpStatusCode.NOT_FOUND_404,
11 message: 'Abuse not found'
12 })
57f6896f
C
13
14 return false
15 }
16
17 res.locals.abuse = abuse
18 return true
d95d1559
C
19}
20
453e83ea
C
21// ---------------------------------------------------------------------------
22
23export {
7a4ea932 24 doesAbuseExist
453e83ea 25}