89 lines
2.2 KiB
JavaScript
89 lines
2.2 KiB
JavaScript
let express = require('express');
|
|
let router = express.Router();
|
|
const { v4: uuidv4 } = require('uuid');
|
|
|
|
let Meeting = require('../models/meetingModel');
|
|
|
|
router.post('/', async (req, res) => {
|
|
id = uuidv4();
|
|
data = {id, ...req.body}
|
|
console.log(data);
|
|
|
|
try {
|
|
const [meeting] = await Meeting.addMeeting(data);
|
|
res.status(201).json(meeting);
|
|
} catch (error) {
|
|
res.status(500).json({ message: 'Failed to add meeting.', error });
|
|
}
|
|
});
|
|
|
|
router.put('/:id', async (req, res) => {
|
|
const data = { ...req.body };
|
|
const id = req.params.id;
|
|
|
|
try {
|
|
const meeting = await Meeting.updateMeeting(data, id);
|
|
res.status(200).json(meeting);
|
|
} catch (error) {
|
|
res.status(500).json({ message: `Failed to update meeting with id ${id}.`, error });
|
|
}
|
|
});
|
|
|
|
router.delete('/:id', async (req, res) => {
|
|
const id = req.params.id;
|
|
|
|
try {
|
|
const meeting = await Meeting.deleteMeeting(id);
|
|
res.status(200).json({message: `Meeting with id ${id} successfully deleted.`});
|
|
} catch (error) {
|
|
res.status(500).json({ message: `Failed to delete meeting with id ${id}.`, error });
|
|
}
|
|
});
|
|
|
|
router.get('/:id', async (req, res) => {
|
|
const id = req.params.id;
|
|
|
|
try {
|
|
const meeting = await Meeting.getMeetingById(id);
|
|
res.status(200).json(meeting);
|
|
} catch (error) {
|
|
res.status(500).json({ message: "Meeting doesn't exist.", error });
|
|
}
|
|
});
|
|
|
|
|
|
router.get('/:id/participants', async (req, res) => {
|
|
const id = req.params.id;
|
|
|
|
try {
|
|
const meeting = await Meeting.getParticipantsByMeetingId(id);
|
|
res.status(200).json(meeting);
|
|
} catch (error) {
|
|
res.status(500).json({ message: "Meeting doesn't exist.", error });
|
|
}
|
|
});
|
|
|
|
router.get('/:id/possible-dates', async (req, res) => {
|
|
const id = req.params.id;
|
|
|
|
try {
|
|
const meeting = await Meeting.getPossibleDatesByMeetingId(id);
|
|
res.status(200).json(meeting);
|
|
} catch (error) {
|
|
res.status(500).json({ message: "Meeting doesn't exist.", error });
|
|
}
|
|
});
|
|
|
|
router.get('/:id/availibility', async (req, res) => {
|
|
const id = req.params.id;
|
|
|
|
try {
|
|
const meeting = await Meeting.getAvailibilityByMeetingId(id);
|
|
res.status(200).json(meeting);
|
|
} catch (error) {
|
|
res.status(500).json({ message: "Meeting doesn't exist.", error });
|
|
}
|
|
});
|
|
|
|
module.exports = router;
|