aboutsummaryrefslogblamecommitdiffhomepage
path: root/server/middlewares/validators/shared/abuses.ts
blob: 2c988f9ec57b8db0074c691f9b7a9287cf9f843e (plain) (tree)
1
2
3
4
5
6
7
8
9
                                  
                                                       
                                               
                                                
 
                                                                         
                                                                           
 
               



                                           





                          

 


                                                                              
                
 
import { Response } from 'express'
import { AbuseModel } from '@server/models/abuse/abuse'
import { HttpStatusCode } from '@shared/models'
import { forceNumber } from '@shared/core-utils'

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

  if (!abuse) {
    res.fail({
      status: HttpStatusCode.NOT_FOUND_404,
      message: 'Abuse not found'
    })

    return false
  }

  res.locals.abuse = abuse
  return true
}

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

export {
  doesAbuseExist
}