Skip to content

Commit

Permalink
fix(be): make admin to get all contest submissions (#1652)
Browse files Browse the repository at this point in the history
- 어드민이 모든 제출을 볼 수 있도록 합니다.
- 전 커밋의 계속해서 제출이 보이지 않던 문제를 해결합니다.
  • Loading branch information
Jaehyeon1020 authored Apr 15, 2024
1 parent 3179115 commit 07af7ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ export class ContestSubmissionController {
problemId,
contestId,
userId: req.user.id,
isAdmin: req.user.isAdmin(),
groupId
})
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ describe('SubmissionService', () => {
await service.getContestSubmissions({
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId,
isAdmin: false
userId: submissions[0].userId
})
)
})
Expand All @@ -437,8 +436,7 @@ describe('SubmissionService', () => {
service.getContestSubmissions({
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId,
isAdmin: false
userId: submissions[0].userId
})
).to.be.rejectedWith(NotFoundException)
})
Expand All @@ -453,8 +451,7 @@ describe('SubmissionService', () => {
service.getContestSubmissions({
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId,
isAdmin: false
userId: submissions[0].userId
})
).to.be.rejectedWith(NotFoundException)
})
Expand Down
24 changes: 16 additions & 8 deletions apps/backend/apps/client/src/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -628,30 +628,38 @@ export class SubmissionService implements OnModuleInit {
problemId,
contestId,
userId,
isAdmin,
groupId = OPEN_SPACE_ID,
cursor = null,
take = 10
}: {
problemId: number
contestId: number
userId: number
isAdmin: boolean
groupId?: number
cursor?: number | null
take?: number
}): Promise<Partial<Submission>[]> {
const paginator = this.prisma.getPaginator(cursor)

await this.prisma.contestRecord.findUniqueOrThrow({
const isAdmin = await this.prisma.user.findFirst({
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention
contestId_userId: {
contestId,
userId
}
id: userId,
role: 'Admin'
}
})

if (!isAdmin) {
await this.prisma.contestRecord.findUniqueOrThrow({
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention
contestId_userId: {
contestId,
userId
}
}
})
}

await this.prisma.contestProblem.findFirstOrThrow({
where: {
problem: {
Expand Down

0 comments on commit 07af7ea

Please sign in to comment.