backend/api/routes/possibleDateRoute.js

37 lines
822 B
JavaScript
Raw Normal View History

2020-05-05 09:34:30 +00:00
let express = require('express');
let router = express.Router();
let PossibleDate = require('../models/possibleDateModel');
router.post('/', async (req, res) => {
const data = { ...req.body };
try {
const [possibleDate] = await PossibleDate.addPossibleDate(data);
res.status(201).json(possibleDate);
} catch (error) {
res.status(500).json({
message: 'Failed to add a new possible date.',
error,
});
}
});
2020-05-05 14:18:36 +00:00
router.delete('/:id', async (req, res) => {
2020-05-05 09:34:30 +00:00
const id = req.params.id;
try {
const possibleDate = await PossibleDate.deletePossibleDate(id);
res.status(200).json({
message: `Possible date with id ${id} successfully deleted.`,
});
} catch (error) {
res.status(500).json({
message: `Failed to delete possible date with id ${id}.`,
error,
});
}
});
module.exports = router;