Skip to content

Commit

Permalink
feat: added session registrations service + refactor B.E. #78
Browse files Browse the repository at this point in the history
  • Loading branch information
rbento1096 committed Feb 20, 2024
1 parent 5a3bdda commit 873ee07
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 18 deletions.
6 changes: 2 additions & 4 deletions back-end/src/handlers/registrations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class SessionRegistrations extends ResourceController {
throw new RCError('User not found');
}

if (!this.resourceId) return;
if (!this.resourceId || this.httpMethod === 'POST') return;

try {
this.registration = new SessionRegistration(
Expand Down Expand Up @@ -75,10 +75,8 @@ class SessionRegistrations extends ResourceController {
protected async postResources(): Promise<any> {
// @todo configurations.canSignUpForSessions()

if (!this.body.sessionId) throw new RCError('Missing session ID!');

this.registration = new SessionRegistration({
sessionId: this.body.sessionId,
sessionId: this.resourceId,
userId: this.principalId,
registrationDateInMs: new Date().getTime()
});
Expand Down
34 changes: 20 additions & 14 deletions back-end/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1053,26 +1053,23 @@ paths:
responses:
200:
$ref: '#/components/responses/Registrations'
post:
summary: Create a new session registration
/registrations/{sessionId}:
get:
summary: Get a session registration
tags: [Sessions]
security:
- AuthFunction: []
requestBody:
required: true
description: Registration
content:
application/json:
schema:
type: object
parameters:
- name: sessionId
in: path
required: true
schema:
type: string
responses:
200:
$ref: '#/components/responses/Registration'
400:
$ref: '#/components/responses/BadParameters'
/registrations/{sessionId}:
get:
summary: Get a session registration
post:
summary: Create a new session registration
tags: [Sessions]
security:
- AuthFunction: []
Expand All @@ -1082,9 +1079,18 @@ paths:
required: true
schema:
type: string
requestBody:
required: true
description: Registration
content:
application/json:
schema:
type: object
responses:
200:
$ref: '#/components/responses/Registration'
400:
$ref: '#/components/responses/BadParameters'
delete:
summary: Delete a registration
description: Requires to be Admin or the registered user.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { Injectable } from '@angular/core';
import { IDEAApiService } from '@idea-ionic/common';

import { SessionRegistration } from '@models/sessionRegistration.model';

@Injectable({ providedIn: 'root' })
export class SessionRegistrationsService {
constructor(private api: IDEAApiService) {}

/**
* Get the list of registrations for the user or session.
*/
async getList(sessionId?: string): Promise<SessionRegistration[]> {
return (await this.api.getResource(['registrations'], { params: { sessionId } })).map(
sr => new SessionRegistration(sr)
);
}

/**
* Get the full details of a registration by its id.
*/
async getById(sessionId: string): Promise<SessionRegistration> {
return new SessionRegistration(await this.api.getResource(['registrations', sessionId]));
}

/**
* Insert a new registration.
*/
async insert(sessionId: string): Promise<SessionRegistration> {
return new SessionRegistration(await this.api.postResource(['registrations', sessionId]));
}
/**
* Delete a registration.
*/
async delete(registration: SessionRegistration): Promise<void> {
await this.api.deleteResource(['registrations', registration.sessionId]);
}
}

0 comments on commit 873ee07

Please sign in to comment.