Skip to content

Commit

Permalink
feat: remove need for studentId from excuse creation
Browse files Browse the repository at this point in the history
  • Loading branch information
ShenyiCui committed Jun 9, 2024
1 parent e6230eb commit e47f9db
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
4 changes: 0 additions & 4 deletions src/product/general/excuses/dtos/create-excuse.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,4 @@ export class CreateExcuseDto {
@IsNumber()
@IsNotEmpty()
windowId: number;

@IsNumber()
@IsNotEmpty()
studentId: number;
}
7 changes: 5 additions & 2 deletions src/product/general/excuses/excuses.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ export class ExcusesController {

@Post('/create')
@UseFilters(BadRequestExceptionFilter)
createExcuse(@Body() dto: CreateExcuseDto): Promise<number> {
createExcuse(
@Body() dto: CreateExcuseDto,
@GetUserRest() user: User,
): Promise<number> {
this.logger.log('POST /excuses/create', ExcusesController.name);

return this.excusesService.createExcuse(dto);
return this.excusesService.createExcuse(dto, user);
}

@Put(':id')
Expand Down
11 changes: 10 additions & 1 deletion src/product/general/excuses/excuses.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,18 @@ export class ExcusesService {
return excuses.map((excuse) => makeExcuseBase(excuse));
}

async createExcuse(excuse: CreateExcuseDto): Promise<number> {
async createExcuse(excuse: CreateExcuseDto, user: User): Promise<number> {
const student = await this.prismaService.student.findFirst({
where: { userId: user.id },
});

if (!student) {
throw new Error('Student not found');
}

const createExcuseData = {
...excuse,
studentId: student.id,
excuseStatus: ExcuseStatus.PENDING,
};

Expand Down

0 comments on commit e47f9db

Please sign in to comment.