simulations.js 656 Bytes
Newer Older
abergavenny's avatar
abergavenny committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import { validationResult } from 'express-validator'

import { success, warning } from '../helpers/index.js'

import { ResponseCode } from '../ENUMS.js'
import { Simulation } from '../db/index.js'

export const getSimulation = async (req, res) => {
  const validationErrors = validationResult(req)

  if (!validationErrors.isEmpty()) {
    return warning(res, { code: ResponseCode.ValidationError })
  }

  const { id } = req.params

  const result = await Simulation.findById({ _id: id })

  success(res, { data: result })
}

export const getSimulations = async (req, res) => {
  const result = await Simulation.find()

  success(res, { data: result })
}