backend/api/routes/availabilityRoute.js

38 lines
921 B
JavaScript

const express = require('express');
const router = express.Router();
const { authenticate } = require('../../middlewares/authenticate');
const Availability = require('../models/availabilityModel');
router.post('/', authenticate, async (req, res) => {
const data = { ...req.body };
try {
const [availability] = await Availability.addAvailability(data);
res.status(201).json(availability);
} catch (error) {
res.status(500).json({
message: 'Failed to add a new availability.',
error,
});
}
});
router.delete('/:id', authenticate, async (req, res) => {
const id = req.params.id;
try {
const availability = await Availability.deleteAvailability(id);
res.status(200).json({
message: `Availability with id ${id} successfully deleted.`,
});
} catch (error) {
res.status(500).json({
message: `Failed to delete availability with id ${id}.`,
error,
});
}
});
module.exports = router;