-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
473aa1b
commit 1511582
Showing
4 changed files
with
168 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const Meeting = require('../models/meetingModel'); | ||
|
||
const getAllMeetings = async (req, res) =>{ | ||
try { | ||
const meetings = await Meeting.find(); | ||
res.status(200).json(meetings); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error retrieving meetings', error }); | ||
} | ||
} | ||
|
||
const getMeetingById = async (req, res)=> { | ||
try { | ||
const meeting = await Meeting.findById(req.params.id); | ||
if (!meeting) { | ||
return res.status(404).json({ message: 'Meeting not found' }); | ||
} | ||
res.status(200).json(meeting); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error retrieving meeting', error }); | ||
} | ||
} | ||
|
||
const createMeeting = async(req, res)=> { | ||
try { | ||
console.log(req.body); | ||
const { title, description, host_id, start_time, end_time, participants } = req.body; | ||
const newMeeting = new Meeting({ title, description, host_id, start_time, end_time, participants }); | ||
const savedMeeting = await newMeeting.save(); | ||
res.status(201).json(savedMeeting); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error creating meeting', error }); | ||
} | ||
} | ||
|
||
const updateMeeting = async(req, res) => { | ||
try { | ||
const { title, description, host_id, start_time, end_time, participants, status } = req.body; | ||
const updatedMeeting = await Meeting.findByIdAndUpdate( | ||
req.params.id, | ||
{ title, description, host_id, start_time, end_time, participants, status }, | ||
{ new: true } | ||
); | ||
if (!updatedMeeting) { | ||
return res.status(404).json({ message: 'Meeting not found' }); | ||
} | ||
res.status(200).json(updatedMeeting); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error updating meeting', error }); | ||
} | ||
} | ||
|
||
const deleteMeeting = async(req, res) => { | ||
try { | ||
const deletedMeeting = await Meeting.findByIdAndDelete(req.params.id); | ||
if (!deletedMeeting) { | ||
return res.status(404).json({ message: 'Meeting not found' }); | ||
} | ||
res.status(200).json({ message: 'Meeting deleted successfully' }); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error deleting meeting', error }); | ||
} | ||
} | ||
|
||
const joinMeeting = async (req, res) => { | ||
try { | ||
const meeting = await Meeting.findById(req.params.id); | ||
if (!meeting) { | ||
return res.status(404).json({ message: 'Meeting not found' }); | ||
} | ||
if (!meeting.participants.includes(req.body.user_id)) { | ||
meeting.participants.push(req.body.user_id); | ||
await meeting.save(); | ||
} | ||
res.status(200).json({ message: 'Successfully joined meeting' }); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error joining meeting', error }); | ||
} | ||
} | ||
|
||
const inviteParticipants = async (req, res) => { | ||
try { | ||
const { meeting_id, participants } = req.body; | ||
const meeting = await Meeting.findById(meeting_id); | ||
if (!meeting) { | ||
return res.status(404).json({ message: 'Meeting not found' }); | ||
} | ||
// Assuming you have a function to send emails or notifications | ||
await sendInvitations(participants, meeting); | ||
res.status(200).json({ message: 'Invitations sent successfully' }); | ||
} catch (error) { | ||
res.status(500).json({ message: 'Error inviting participants', error }); | ||
} | ||
} | ||
|
||
// Mock function to send invitations | ||
const sendInvitations = async (participants, meeting) => { | ||
// Implement your email or notification sending logic here | ||
console.log(`Sending invitations to: ${participants.join(', ')} for meeting: ${meeting.title}`); | ||
} | ||
|
||
module.exports = {inviteParticipants, joinMeeting, deleteMeeting, updateMeeting, createMeeting, getMeetingById, getAllMeetings }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
const mongoose = require('mongoose'); | ||
|
||
const meetingSchema = new mongoose.Schema({ | ||
title: { | ||
type: String, | ||
required: true | ||
}, | ||
description: { | ||
type: String, | ||
required: true | ||
}, | ||
host_id: { | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User', | ||
required: true | ||
}, | ||
start_time: { | ||
type: Date, | ||
required: true | ||
}, | ||
end_time: { | ||
type: Date, | ||
required: true | ||
}, | ||
participants: [{ | ||
type: mongoose.Schema.Types.ObjectId, | ||
ref: 'User' | ||
}], | ||
status: { | ||
type: String, | ||
enum: ['scheduled', 'ongoing', 'completed', 'cancelled'], | ||
default: 'scheduled' | ||
} | ||
}); | ||
|
||
const Meeting = mongoose.model('Meeting', meetingSchema); | ||
|
||
module.exports = Meeting; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const express = require('express'); | ||
const router = express.Router(); | ||
const {inviteParticipants, joinMeeting, deleteMeeting, updateMeeting, createMeeting, getMeetingById, getAllMeetings} = require('../controllers/meetingController'); // Adjust the path based on your folder structure | ||
|
||
// Route to get all meetings | ||
router.get('/', getAllMeetings); | ||
|
||
// Route to get a meeting by ID | ||
router.get('/:id', getMeetingById); | ||
|
||
// Route to create a new meeting | ||
router.post('/', createMeeting); | ||
|
||
// Route to update an existing meeting | ||
router.put('/:id', updateMeeting); | ||
|
||
// Route to delete a meeting | ||
router.delete('/:id',deleteMeeting); | ||
|
||
// Route to join a meeting | ||
router.post('/:id/join', joinMeeting); | ||
|
||
// Route to invite participants to a meeting | ||
router.post('/:id/invite', inviteParticipants); | ||
|
||
module.exports = router; |