course.controller.js 631 Bytes
Newer Older
Yoon, Daeki's avatar
Yoon, Daeki 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
27
28
29
30
31
import dbErrorHandler from "../helpers/dbErrorHandler.js"
import Course from "./course.model.js"

const create = async (req, res) => {
  try {
    const course = new Course(req.body)
    await course.save()
    return res.json(course)
  } catch (error) {
    return res.status(400).json({
      error: dbErrorHandler.getErrorMessage(error)
    })
  }
}

const list = async (req, res) => {
  try {
    const courses = await Course.find({}).exec()
    return res.json(courses)
  } catch (error) {
    return res.status(400).json({
      error: dbErrorHandler.getErrorMessage(error)
    })
  }

}

export default {
  create,
  list,
}