All files / src/routes get.ts

100% Statements 18/18
100% Branches 2/2
100% Functions 4/4
100% Lines 14/14

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 223x 3x 3x   3x   3x   3x 1x 1x     4x 4x 3x 3x 2x     3x  
import { BadRequestError, NotFoundError } from '@next-k8s/common'
import express, { Request, Response } from 'express'
import { isValidObjectId } from 'mongoose'
 
import Ticket from '../models/ticket'
 
const router = express.Router()
 
router.get('/api/tickets', async (req: Request, res: Response) => {
  const tickets = await Ticket.find({})
  res.send({ tickets })
})
 
router.get('/api/tickets/:id', async (req: Request, res: Response) => {
  if (!isValidObjectId(req.params.id)) throw new BadRequestError('Invalid Ticket ID')
  const ticket = await Ticket.findById(req.params.id)
  if (!ticket) throw new NotFoundError()
  res.json({ ticket })
})
 
export default router