2020-05-07 12:14:13 +00:00
|
|
|
const express = require('express');
|
|
|
|
const router = express.Router();
|
2020-05-05 09:54:02 +00:00
|
|
|
|
2020-05-10 22:09:16 +00:00
|
|
|
const { authenticate } = require('../../middlewares/authenticate');
|
2020-05-07 12:14:13 +00:00
|
|
|
const Availibility = require('../models/availibilityModel');
|
2020-05-05 09:54:02 +00:00
|
|
|
|
2020-05-10 22:03:48 +00:00
|
|
|
router.post('/', authenticate, async (req, res) => {
|
2020-05-05 09:54:02 +00:00
|
|
|
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-10 22:03:48 +00:00
|
|
|
router.delete('/:id', authenticate, 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;
|