|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
const cors = require('cors')
|
|
|
|
|
const express = require('express')
|
|
|
|
|
const holidays = express.Router()
|
|
|
|
|
const Holiday = require('../models/holidays.js')
|
|
|
|
|
@ -5,13 +6,15 @@ const Holiday = require('../models/holidays.js')
|
|
|
|
|
holidays.post('/', async (req, res) => {
|
|
|
|
|
Holiday.create(req.body, (error, createdHoliday) => {
|
|
|
|
|
if (error) {
|
|
|
|
|
res.status(400).json({ error: error.message })
|
|
|
|
|
}
|
|
|
|
|
console.log(error)
|
|
|
|
|
res.status(418).json({ error: error })
|
|
|
|
|
} else {
|
|
|
|
|
res.status(200).send(createdHoliday) // .json() will send proper headers in response so client knows it's json coming back
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
holidays.get('/', (req, res) => {
|
|
|
|
|
holidays.get('/', cors(), (req, res) => {
|
|
|
|
|
Holiday.find({}, (err, foundHolidays) => {
|
|
|
|
|
if (err) {
|
|
|
|
|
res.status(400).json({ error: err.message })
|
|
|
|
|
|