Skip to content

Commit

Permalink
Implemented meeting backend
Browse files Browse the repository at this point in the history
  • Loading branch information
mehtakevan committed May 24, 2024
1 parent 473aa1b commit 1511582
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
102 changes: 102 additions & 0 deletions services/Meeting/controllers/meetingController.js
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 };
2 changes: 2 additions & 0 deletions services/Meeting/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
const config = require('./config');
const meetingRoutes = require('./routes/meetingRoute');

const app = express();

// Enable CORS
app.use(cors());

app.use(express.json());
app.use('/meeting',meetingRoutes);

const port = config.PORT;
const dbUri = config.DB_URI;
Expand Down
38 changes: 38 additions & 0 deletions services/Meeting/models/meetingModel.js
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;
26 changes: 26 additions & 0 deletions services/Meeting/routes/meetingRoute.js
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;

0 comments on commit 1511582

Please sign in to comment.