backend/api/routes/availibilityRoute.js

37 lines
819 B
JavaScript

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,
});
}
});
router.delete('/:id', async (req, res) => {
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;