aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/helpers/middlewares/abuses.ts
blob: c53bd9efd9af211bd45709b4ab771df7c1e39bbe (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import { Response } from 'express'
import { AbuseModel } from '../../models/abuse/abuse'
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'

async function doesAbuseExist (abuseId: number | string, res: Response) {
  const abuse = await AbuseModel.loadByIdWithReporter(parseInt(abuseId + '', 10))

  if (!abuse) {
    res.status(HttpStatusCode.NOT_FOUND_404)
       .json({ error: 'Abuse not found' })

    return false
  }

  res.locals.abuse = abuse
  return true
}

// ---------------------------------------------------------------------------

export {
  doesAbuseExist
}