Skip to content

Commit

Permalink
fix(be): include contest-id or workbook-id to submission if provided (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaehyeon1020 authored Mar 2, 2024
1 parent 9a1dd39 commit 1c77b5c
Showing 1 changed file with 33 additions and 13 deletions.
46 changes: 33 additions & 13 deletions backend/apps/client/src/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@ export class SubmissionService implements OnModuleInit {
}
})

return await this.createSubmission(submissionDto, problem, userId)
return await this.createSubmission(submissionDto, problem, userId, {
contestId
})
}

async submitToWorkbook(
Expand All @@ -172,14 +174,19 @@ export class SubmissionService implements OnModuleInit {
throw new EntityNotExistException('problem')
}

return await this.createSubmission(submissionDto, problem, userId)
return await this.createSubmission(submissionDto, problem, userId, {
workbookId
})
}

async createSubmission(
submissionDto: CreateSubmissionDto,
problem: Problem,
userId: number
userId: number,
idOptions?: { contestId?: number; workbookId?: number }
) {
let submission: Submission

if (!problem.languages.includes(submissionDto.language)) {
throw new ConflictFoundException(
`This problem does not support language ${submissionDto.language}`
Expand All @@ -196,16 +203,29 @@ export class SubmissionService implements OnModuleInit {
throw new ConflictFoundException('Modifying template is not allowed')
}

const submission = await this.prisma.submission.create({
data: {
code: code.map((snippet) => ({ ...snippet })), // convert to plain object
result: ResultStatus.Judging,
userId,
problemId: problem.id,
codeSize: new TextEncoder().encode(code[0].text).length,
...data
}
})
const submissionData = {
code: code.map((snippet) => ({ ...snippet })), // convert to plain object
result: ResultStatus.Judging,
userId,
problemId: problem.id,
codeSize: new TextEncoder().encode(code[0].text).length,
...data
}

if (idOptions && idOptions.contestId) {
submission = await this.prisma.submission.create({
data: { ...submissionData, contestId: idOptions.contestId }
})
} else if (idOptions && idOptions.workbookId) {
submission = await this.prisma.submission.create({
data: { ...submissionData, workbookId: idOptions.workbookId }
})
} else {
submission = await this.prisma.submission.create({
data: submissionData
})
}

await this.publishJudgeRequestMessage(code, submission)

return submission
Expand Down

0 comments on commit 1c77b5c

Please sign in to comment.