38 lines
925 B
JavaScript
38 lines
925 B
JavaScript
const express = require('express');
|
|
const router = express.Router();
|
|
|
|
const { authenticate } = require('../../middlewares/authenticate');
|
|
const PossibleDate = require('../models/possibleDateModel');
|
|
|
|
router.post('/', authenticate, 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,
|
|
});
|
|
}
|
|
});
|
|
|
|
router.delete('/:id', authenticate, async (req, res) => {
|
|
const { id } = req.params;
|
|
|
|
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;
|