-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic implemntation of session service
Additions: - session interface for mongoose to store session information - session routes to make use of http requests and responses - code for creation of session, joining, and session deletion - implemented jwt validation into joining and deletion requests
- Loading branch information
Showing
11 changed files
with
344 additions
and
26 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,2 @@ | ||
{ | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
63 changes: 63 additions & 0 deletions
63
collaboration-service/src/controller/session-controller.ts
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,63 @@ | ||
import { Request, Response } from 'express'; | ||
import Session from '../model/session-model'; | ||
|
||
export const sessionController = { | ||
createSession: async (req: Request, res: Response) => { | ||
const { | ||
session_id, // assuming session id is passed in the request body | ||
participants, | ||
question, | ||
code, | ||
} = req.body; | ||
|
||
// const sessionId = Math.random().toString(36).substring(2, 8); | ||
const session = new Session({ | ||
session_id: session_id, //sessionId, | ||
date_created: new Date(), | ||
participants, | ||
question, | ||
code, | ||
}); | ||
|
||
await session.save() | ||
.then((data) => { | ||
res.status(201).json(data); | ||
}) | ||
.catch((err) => { | ||
res.status(500).json({ message: (err as Error).message }); | ||
}); | ||
}, | ||
joinSession: async (req: Request, res: Response) => { | ||
const { sessionId, userId } = req.body | ||
|
||
try { | ||
// Find a session that the user is a participant of | ||
const session = await Session.findOne({ participants: userId }); | ||
|
||
if (!session) { | ||
return res.status(404).json({ message: 'Session not found' }); | ||
} | ||
|
||
res.status(200).json(session); | ||
} catch (err) { | ||
res.status(500).json({ message: (err as Error).message }); | ||
} | ||
}, | ||
terminateSession: async (req: Request, res: Response) => { | ||
const { sessionId } = req.body; | ||
|
||
try { | ||
const session = await Session.findOne({ session_id: sessionId }); | ||
|
||
if (!session) { | ||
return res.status(404).json({ message: 'Session not found' }); | ||
} | ||
|
||
await Session.deleteOne({ session_id: sessionId }); | ||
|
||
res.status(200).json({ message: 'Session terminated successfully' }); | ||
} catch (err) { | ||
res.status(500).json({ message: (err as Error).message }); | ||
} | ||
} | ||
}; |
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.