Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions src/repository/rpkm/rpkmRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,48 @@ export class RpkmRepository {
);
}
}

async getWorkshopParticipantCountsByTypeAndTime(
workshopType: WorkshopType,
workshopTime: number
): Promise<number> {
try {
const count = await prisma.rPKMworkshop.count({
where: {
workshopType: workshopType,
workshopTime: workshopTime,
},
});
return count;
} catch (error) {
console.log(
`Error getting participant counts of RPKM workshops by type ${workshopType} and time ${workshopTime}: `,
error
);
throw new Error(
`Failed to get participant counts of RPKM workshops by type ${workshopType} and time ${workshopTime}.`
);
}
}

async getWorkshopParticipantCountsByType(
workshopType: WorkshopType
): Promise<number> {
try {
const count = await prisma.rPKMworkshop.count({
where: {
workshopType: workshopType,
},
});
return count;
} catch (error) {
console.log(
`Error getting participant counts of RPKM workshops by type ${workshopType}: `,
error
);
throw new Error(
`Failed to get participant counts of RPKM workshops by type ${workshopType}.`
);
}
}
}
22 changes: 22 additions & 0 deletions src/usecase/rpkm/rpkmUsecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,28 @@ export class RpkmUsecase {
);
}

// max 100 participants per workshop time slot
const timeSlotParticipantCount =
await this.rpkmRepository.getWorkshopParticipantCountsByTypeAndTime(
body.workshopType,
body.workshopTime
);
if (timeSlotParticipantCount >= 100) {
throw new AppError(
`Workshop ${body.workshopType} at time slot ${body.workshopTime} is full.`,
400
);
}

// max 600 participants per workshop type
const workshopParticipantCount =
await this.rpkmRepository.getWorkshopParticipantCountsByType(
body.workshopType
);
if (workshopParticipantCount >= 600) {
throw new AppError(`Workshop ${body.workshopType} is full.`, 400);
}

const registrationResult =
await this.rpkmRepository.userRegisterNewWorkshop(body, userId);
return registrationResult;
Expand Down