Skip to content

Commit

Permalink
fix(be): integrate problem exposeTIme isVisible
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-to committed Apr 29, 2024
1 parent d249bbc commit 9754226
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 28 deletions.
12 changes: 4 additions & 8 deletions apps/backend/apps/admin/src/problem/mock/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,8 @@ export const problems: Problem[] = [
acceptedRate: 0.5,
createTime: faker.date.past(),
updateTime: faker.date.past(),
exposeTime: faker.date.anytime(),
exposeTime: new Date(),
samples: [],
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand All @@ -77,9 +76,8 @@ export const problems: Problem[] = [
acceptedRate: 0.5,
createTime: faker.date.past(),
updateTime: faker.date.past(),
exposeTime: faker.date.anytime(),
exposeTime: new Date(),
samples: [],
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand Down Expand Up @@ -136,9 +134,8 @@ export const importedProblems: Problem[] = [
acceptedRate: 0.5,
createTime: faker.date.past(),
updateTime: faker.date.past(),
exposeTime: faker.date.anytime(),
exposeTime: new Date(),
samples: [],
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand Down Expand Up @@ -181,9 +178,8 @@ export const importedProblems: Problem[] = [
acceptedRate: 0.5,
createTime: faker.date.past(),
updateTime: faker.date.past(),
exposeTime: faker.date.anytime(),
exposeTime: new Date(),
samples: [],
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ export const ImportedProblemHeader: string[] = [
'AnswerDetail',
'AnswerYn'
]

export const maxDate: Date = new Date('2999-12-31T00:00:00.000Z')
24 changes: 22 additions & 2 deletions apps/backend/apps/admin/src/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
import { PrismaService } from '@libs/prisma'
import { StorageService } from '@admin/storage/storage.service'
import { ImportedProblemHeader } from './model/problem.constants'
import { maxDate } from './model/problem.constants'
import type {
CreateProblemInput,
UploadFileInput,
Expand Down Expand Up @@ -49,7 +50,15 @@ export class ProblemService {
userId: number,
groupId: number
) {
const { languages, template, tagIds, samples, testcases, ...data } = input
const {
languages,
template,
tagIds,
samples,
testcases,
isVisible,
...data
} = input
if (!languages.length) {
throw new UnprocessableDataException(
'A problem should support at least one language'
Expand All @@ -66,6 +75,7 @@ export class ProblemService {
const problem = await this.prisma.problem.create({
data: {
...data,
exposeTime: isVisible ? new Date() : maxDate,
samples: {
create: samples
},
Expand Down Expand Up @@ -324,7 +334,16 @@ export class ProblemService {
}

async updateProblem(input: UpdateProblemInput, groupId: number) {
const { id, languages, template, tags, testcases, samples, ...data } = input
const {
id,
languages,
template,
tags,
testcases,
samples,
isVisible,
...data
} = input
const problem = await this.getProblem(id, groupId)

if (languages && !languages.length) {
Expand Down Expand Up @@ -359,6 +378,7 @@ export class ProblemService {
}
})
},
...(isVisible && { exposeTime: isVisible ? new Date() : maxDate }),
...(languages && { languages }),
...(template && { template: [JSON.stringify(template)] }),
problemTag
Expand Down
2 changes: 0 additions & 2 deletions apps/backend/apps/client/src/problem/mock/problem.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export const problems: Problem[] = [
createTime: faker.date.past(),
updateTime: faker.date.past(),
template: [],
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand Down Expand Up @@ -58,7 +57,6 @@ export const problems: Problem[] = [
createTime: faker.date.past(),
updateTime: faker.date.past(),
template: [],
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand Down
34 changes: 23 additions & 11 deletions apps/backend/apps/client/src/problem/problem.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ export class ProblemRepository {
},
exposeTime: {
lte: new Date()
},
isVisible: true
}
},
select: {
...this.problemsSelectOption,
Expand All @@ -135,8 +134,7 @@ export class ProblemRepository {
},
exposeTime: {
lte: new Date()
},
isVisible: true
}
}
})
}
Expand Down Expand Up @@ -167,7 +165,9 @@ export class ProblemRepository {
where: {
id: problemId,
groupId,
isVisible: true
exposeTime: {
lte: new Date()
}
},
select: this.problemSelectOption
})
Expand Down Expand Up @@ -207,7 +207,9 @@ export class ProblemRepository {
where: {
contestId,
problem: {
isVisible: true
exposeTime: {
lte: new Date()
}
}
},
select: {
Expand All @@ -224,7 +226,9 @@ export class ProblemRepository {
where: {
contestId,
problem: {
isVisible: true
exposeTime: {
lte: new Date()
}
}
}
})
Expand All @@ -239,7 +243,9 @@ export class ProblemRepository {
problemId
},
problem: {
isVisible: true
exposeTime: {
lte: new Date()
}
}
},
select: {
Expand Down Expand Up @@ -270,7 +276,9 @@ export class ProblemRepository {
where: {
workbookId,
problem: {
isVisible: true
exposeTime: {
lte: new Date()
}
}
},
select: {
Expand All @@ -287,7 +295,9 @@ export class ProblemRepository {
where: {
workbookId,
problem: {
isVisible: true
exposeTime: {
lte: new Date()
}
}
}
})
Expand All @@ -302,7 +312,9 @@ export class ProblemRepository {
problemId
},
problem: {
isVisible: true
exposeTime: {
lte: new Date()
}
}
},
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ export const problems: Problem[] = [
exposeTime: new Date(),
createTime: faker.date.past(),
updateTime: faker.date.past(),
isVisible: true,
engTitle: null,
engDescription: null,
engHint: null,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
Warnings:
- You are about to drop the column `is_visible` on the `problem` table. All the data in the column will be lost.
*/
-- AlterTable
ALTER TABLE "problem" DROP COLUMN "is_visible";
1 change: 0 additions & 1 deletion apps/backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ model Problem {
/// "locked": boolean
/// }[]
/// }
isVisible Boolean @default(true) @map("is_visible")
template Json[]
languages Language[]
timeLimit Int @map("time_limit") // unit: MilliSeconds
Expand Down
6 changes: 3 additions & 3 deletions apps/backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ const fixturePath = join(__dirname, '__fixtures__')

let superAdminUser: User
let managerUser: User
const users: User[] = []
let publicGroup: Group
let privateGroup: Group
const users: User[] = []
const problems: Problem[] = []
const problemTestcases: ProblemTestcase[] = []
const contests: Contest[] = []
Expand Down Expand Up @@ -895,7 +895,7 @@ const createProblems = async () => {
}
]
},
isVisible: false
exposeTime: new Date('2999-12-31T00:00:00.000Z')
}
})
)
Expand Down Expand Up @@ -928,7 +928,7 @@ const createProblems = async () => {
}
]
},
isVisible: false
exposeTime: new Date('2999-12-31T00:00:00.000Z')
}
})
)
Expand Down

0 comments on commit 9754226

Please sign in to comment.