Skip to content

Update scorecard data validation & throw error on not found #21

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

Merged
merged 1 commit into from
Aug 20, 2025
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
8 changes: 8 additions & 0 deletions src/api/scorecard/scorecard.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ export class ScoreCardService {
body: ScorecardRequestDto,
user: JwtUser,
): Promise<ScorecardWithGroupResponseDto> {
const original = await this.prisma.scorecard.findUnique({
where: { id },
});

if (!original) {
throw new NotFoundException({ message: `Scorecard not found.` });
}

const data = await this.prisma.scorecard
.update({
where: { id },
Expand Down
16 changes: 16 additions & 0 deletions src/dto/scorecard.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import {
IsArray,
IsBoolean,
IsEnum,
IsNotEmpty,
IsNumber,
IsOptional,
IsString,
Max,
Min,
ValidateNested,
} from 'class-validator';
Expand Down Expand Up @@ -61,6 +63,7 @@ export class ScorecardQuestionBaseDto {
example: 'What is the challenge?',
})
@IsString()
@IsNotEmpty()
description: string;

@ApiProperty({
Expand All @@ -72,6 +75,8 @@ export class ScorecardQuestionBaseDto {

@ApiProperty({ description: 'The weight of the question', example: 10 })
@IsNumber()
@Min(0)
@Max(100)
weight: number;

@ApiProperty({
Expand Down Expand Up @@ -119,10 +124,13 @@ export class ScorecardSectionBaseDto {
example: 'Technical Skills',
})
@IsString()
@IsNotEmpty()
name: string;

@ApiProperty({ description: 'The weight of the section', example: 20 })
@IsNumber()
@Min(0)
@Max(100)
weight: number;

@ApiProperty({ description: 'Sort order of the section', example: 1 })
Expand Down Expand Up @@ -162,10 +170,13 @@ export class ScorecardGroupBaseDto {

@ApiProperty({ description: 'The name of the group', example: 'Group A' })
@IsString()
@IsNotEmpty()
name: string;

@ApiProperty({ description: 'The weight of the group', example: 30 })
@IsNumber()
@Min(0)
@Max(100)
weight: number;

@ApiProperty({ description: 'Sort order of the group', example: 1 })
Expand Down Expand Up @@ -241,6 +252,7 @@ export class ScorecardBaseDto {

@ApiProperty({ description: 'The maximum score', example: 100 })
@IsNumber()
@Max(100)
@IsGreaterThan('minScore')
maxScore: number;

Expand Down Expand Up @@ -330,18 +342,22 @@ export function mapScorecardRequestForCreate(request: ScorecardRequestDto) {

return {
...request,
id: undefined,
...userFields,
scorecardGroups: {
create: request.scorecardGroups.map((group) => ({
...group,
id: undefined,
...userFields,
sections: {
create: group.sections.map((section) => ({
...section,
id: undefined,
...userFields,
questions: {
create: section.questions.map((question) => ({
...question,
id: undefined,
sortOrder: 1,
...userFields,
})),
Expand Down