2020-05-05 09:54:02 +00:00
|
|
|
let express = require('express');
|
|
|
|
let router = express.Router();
|
|
|
|
|
|
|
|
let Availibility = require('../models/availibilityModel');
|
|
|
|
|
|
|
|
router.post('/', async (req, res) => {
|
|
|
|
const data = { ...req.body };
|
|
|
|
|
|
|
|
try {
|
|
|
|
const [availibility] = await Availibility.addAvailibility(data);
|
|
|
|
res.status(201).json(availibility);
|
|
|
|
} catch (error) {
|
|
|
|
res.status(500).json({
|
|
|
|
message: 'Failed to add a new availibility.',
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2020-05-05 14:18:36 +00:00
|
|
|
router.delete('/:id', async (req, res) => {
|
2020-05-05 09:54:02 +00:00
|
|
|
const id = req.params.id;
|
|
|
|
|
|
|
|
try {
|
|
|
|
const availibility = await Availibility.deleteAvailibility(id);
|
|
|
|
res.status(200).json({
|
|
|
|
message: `Availibility with id ${id} successfully deleted.`,
|
|
|
|
});
|
|
|
|
} catch (error) {
|
|
|
|
res.status(500).json({
|
|
|
|
message: `Failed to delete availibility with id ${id}.`,
|
|
|
|
error,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = router;
|