-
Notifications
You must be signed in to change notification settings - Fork 0
feat: Participant management #45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@@ -0,0 +1,7 @@ | |||
export interface Participant { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will move this to shared/src/api
in #43
@Post('/:id/participants') | ||
public async joinSession( | ||
@Param('id') id: string | ||
): Promise<Participant | undefined> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to have return type as Promise<Participant>
If for some reason we can't provide a 'Participant', we should throw the appropriate HTTP error
): Promise<Participant> { | ||
assert(await this.hasSession(session), 'Unknown session!'); | ||
|
||
assert( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got that the previous check (hasSession) is basically an assert, whether the consumer found a living session,
but this one is rather an error check IMHO.
The consumer (SessionController) can't verify whether the found living session is in good state or not, therefore it's the responsibility of the SessionService.
As a result, it's not a presumption, but a requirement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will call it verify
to reflect the above.
|
||
// Save updated session | ||
session.participants.push(participant); | ||
await this.sessionDAO.save(session); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a rather theoretical question, but what happens if the save of the participant is done, but for some reason session save has failed? We got a fractured/inconsistent state.
My point is here, that we don't express the part-whole connection between them, plus we don't have any transaction-like mechanism.
We should talk about this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public async join( | ||
session: Session, | ||
options?: JoinSessionOptions | ||
): Promise<Participant> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IDK whether we can solve it, but this method violates CQS principle.
Maybe an ideal solution from the consumer:
const session = this.sessionService.find(sessionId);
const participant = this.sessionService.createParticipant(participantOptions);
session.join(participant);
this.sessionService.save(session);
Closes #24