Skip to content

Commit

Permalink
Merge branch 'main' into t734-implements-test-api
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaehyeon1020 authored Sep 13, 2024
2 parents 8abb661 + 869c65f commit d65be6c
Show file tree
Hide file tree
Showing 50 changed files with 2,113 additions and 1,072 deletions.
6 changes: 1 addition & 5 deletions apps/backend/.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{
"$schema": "https://json.schemastore.org/mocharc",
"extension": "spec.ts",
"require": [
"ts-node/register/transpile-only",
"tsconfig-paths/register",
"./mocha-fixture.ts"
],
"require": ["@swc-node/register", "./mocha-fixture.ts"],
"reporter": "dot"
}
20 changes: 7 additions & 13 deletions apps/backend/.swcrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,19 @@
"jsc": {
"parser": {
"syntax": "typescript",
"decorators": true
},
"transform": {
"legacyDecorator": true,
"decoratorMetadata": true
"decorators": true,
"dynamicImport": true
},
"baseUrl": "./",
"paths": {
"@admin/*": ["./apps/admin/src/*"],
"@client/*": ["./apps/client/src/*"],
"@libs/prisma": ["./libs/prisma/src/index.ts"],
"@libs/cache": ["./libs/cache/src/index.ts"],
"@libs/auth": ["libs/auth/src/index.ts"],
"@libs/exception": ["libs/exception/src/index.ts"],
"@libs/pipe": ["libs/pipe/src/index.ts"],
"@libs/constants": ["libs/constants/src/index.ts"]
"@libs/auth": ["./libs/auth/src/index.ts"],
"@libs/exception": ["./libs/exception/src/index.ts"],
"@libs/pipe": ["./libs/pipe/src/index.ts"],
"@libs/constants": ["./libs/constants/src/index.ts"]
}
},
"module": {
"type": "commonjs",
"noInterop": true
}
}
2 changes: 1 addition & 1 deletion apps/backend/apps/admin/src/problem/problem.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ export class ProblemService {
title,
description,
inputDescription: '',
isVisible: true,
isVisible: false,
outputDescription: '',
hint: '',
template,
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/apps/client/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ValidationPipe } from '@nestjs/common'
import { NestFactory } from '@nestjs/core'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import * as cookieParser from 'cookie-parser'
import cookieParser from 'cookie-parser'
import { Logger, LoggerErrorInterceptor } from 'nestjs-pino'
import { AppModule } from './app.module'
import startMetricsExporter from './metric'
Expand Down
9 changes: 8 additions & 1 deletion apps/backend/nest-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,16 @@
}
],
"watchAssets": true,
"webpack": true,
"deleteOutDir": true,
"plugins": ["@nestjs/swagger"],
"builder": "webpack",
"builder": {
"type": "swc",
"options": {
"swcrcPath": ".swcrc"
}
},
"webpackConfigPath": "webpack.config.js",
"tsConfigPath": "apps/client/tsconfig.app.json"
},
"monorepo": true,
Expand Down
8 changes: 7 additions & 1 deletion apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
"cross-env": "^7.0.3",
"dayjs": "^1.11.13",
"exceljs": "^4.4.0",
"express": "^4.19.2",
"generate-password": "^1.7.1",
"graphql": "^16.9.0",
"graphql-type-json": "^0.3.2",
Expand All @@ -84,6 +85,9 @@
"@nestjs/cli": "^10.4.5",
"@nestjs/schematics": "^10.1.4",
"@nestjs/testing": "^10.4.1",
"@swc-node/register": "^1.10.9",
"@swc/cli": "^0.4.0",
"@swc/core": "^1.7.23",
"@types/cache-manager": "^4.0.6",
"@types/chai": "^4.3.19",
"@types/chai-as-promised": "^7.1.8",
Expand All @@ -104,12 +108,14 @@
"proxyquire": "^2.1.3",
"sinon": "^18.0.0",
"source-map-support": "^0.5.21",
"swc-loader": "^0.2.6",
"swc-node": "^1.0.0",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.5.4"
},
"prisma": {
"seed": "ts-node prisma/seed.ts"
"seed": "swc-node prisma/seed.ts"
}
}
18 changes: 18 additions & 0 deletions apps/backend/webpack.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const swcDefaultConfig =
require('@nestjs/cli/lib/compiler/defaults/swc-defaults').swcDefaultsFactory()
.swcOptions

module.exports = {
module: {
rules: [
{
test: /\.ts$/,
exclude: /node_modules/,
use: {
loader: 'swc-loader',
options: swcDefaultConfig
}
}
]
}
}
7 changes: 0 additions & 7 deletions apps/frontend/app/(main)/_components/ContestCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { cn, dateFormatter } from '@/lib/utils'
import CalendarIcon from '@/public/20_calendar.svg'
import type { Contest } from '@/types/type'
import Image from 'next/image'
import { CircularProgressbar } from 'react-circular-progressbar'
import 'react-circular-progressbar/dist/styles.css'
import StatusBadge from './StatusBadge'

Expand Down Expand Up @@ -64,12 +63,6 @@ export default function ContestCard({ contest }: Props) {
inContestEditor={false}
/>
</div>
{(contest.status == 'ongoing' ||
contest.status == 'registeredOngoing') && (
<div className="hidden h-12 w-12 min-[400px]:block">
<CircularProgressbar value={60} text="60%" />
</div>
)}
</div>
</div>
)
Expand Down
8 changes: 4 additions & 4 deletions apps/frontend/app/(main)/contest/[contestId]/@tabs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import KatexContent from '@/components/KatexContent'
import { auth } from '@/lib/auth'
import { fetcherWithAuth } from '@/lib/utils'
import { sanitize } from 'isomorphic-dompurify'
import RegisterButton from './_components/RegisterButton'

interface ContestTop {
Expand Down Expand Up @@ -37,9 +37,9 @@ export default async function ContestTop({ params }: ContestTopProps) {

return (
<>
<main
className="prose w-full max-w-full border-b-2 border-b-gray-300 p-5 py-12"
dangerouslySetInnerHTML={{ __html: sanitize(data.description) }}
<KatexContent
content={data.description}
classname="prose w-full max-w-full border-b-2 border-b-gray-300 p-5 py-12"
/>
{session && state !== 'Finished' && (
<div className="mt-10 flex justify-center">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default async function ContestProblem({ params }: ContestProblemProps) {
const { contestId } = params
const res = await fetcherWithAuth.get(`contest/${contestId}/problem`, {
searchParams: {
take: 10
take: 20
}
})

Expand Down
11 changes: 8 additions & 3 deletions apps/frontend/app/(main)/contest/[contestId]/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import ContestStatusTimeDiff from '@/components/ContestStatusTimeDiff'
import { auth } from '@/lib/auth'
import { fetcher, fetcherWithAuth } from '@/lib/utils'
import { fetcher, fetcherWithAuth, getStatusWithStartEnd } from '@/lib/utils'
import { dateFormatter } from '@/lib/utils'
import Calendar from '@/public/20_calendar.svg'
import CheckIcon from '@/public/check_blue.svg'
Expand Down Expand Up @@ -40,9 +40,14 @@ export default async function Layout({
)
const isJudgeResultVisible = contest.isJudgeResultVisible
const isRegistered = contest.isRegistered
const contestStatus = getStatusWithStartEnd(
formattedStartTime,
formattedEndTime
)

let totalScore = 0
let totalMaxScore = 0
if (isRegistered && isJudgeResultVisible) {
if (isRegistered && isJudgeResultVisible && contestStatus !== 'upcoming') {
const [score, maxScore] = await calculateContestScore({ contestId })
totalScore = score
totalMaxScore = maxScore
Expand All @@ -56,7 +61,7 @@ export default async function Layout({
{contest?.title}
</h2>
<div className="flex items-center gap-2">
{isRegistered && (
{isRegistered && contestStatus !== 'upcoming' && (
<>
<Image src={CheckIcon} alt="check" width={24} height={24} />
<p className="text-primary-light text-sm font-bold">
Expand Down
9 changes: 5 additions & 4 deletions apps/frontend/app/(main)/contest/_components/ContestTabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default function ContestTabs({ contestId }: { contestId: string }) {
<Link
href={`/contest/${id}` as Route}
className={cn(
'flex w-1/3 justify-center text-lg text-gray-400',
'flex w-1/2 justify-center text-lg text-gray-400',
isCurrentTab('') && 'text-primary'
)}
>
Expand All @@ -29,13 +29,13 @@ export default function ContestTabs({ contestId }: { contestId: string }) {
<Link
href={`/contest/${id}/problem` as Route}
className={cn(
'flex w-1/3 justify-center text-lg text-gray-400',
'flex w-1/2 justify-center text-lg text-gray-400',
isCurrentTab('problem') && 'text-primary'
)}
>
Problem
</Link>
<Link
{/* <Link
href={`/contest/${id}/announcement` as Route}
className={cn(
'flex w-1/3 justify-center text-lg text-gray-400',
Expand All @@ -45,7 +45,7 @@ export default function ContestTabs({ contestId }: { contestId: string }) {
Clarification
</Link>
</div>
{/* <Link
<Link
href={`/contest/${id}/standings` as Route}
className={cn(
'text-lg text-gray-400',
Expand All @@ -54,6 +54,7 @@ export default function ContestTabs({ contestId }: { contestId: string }) {
>
Standings
</Link> */}
</div>
</div>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ export default async function FinishedContestTable({
data={ContestData.data}
columns={columns}
headerStyle={{
title: 'text-left w-2/5 md:w-1/3',
title: 'text-left w-2/5 md:w-1/2',
registered: 'w-1/5 md:w-1/6',
participants: 'w-1/5 md:w-1/6',
totalScore: 'w-1/5 md:w-1/6',
period: 'w-1/5 md:w-1/4'
period: 'w-1/5 md:w-1/3'
}}
linked
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ export const columns: ColumnDef<Contest>[] = [
accessorKey: 'participants',
cell: ({ row }) => row.original.participants
},
{
header: 'Total score',
accessorKey: 'totalScore',
cell: () => '000/000'
},
{
header: 'Period',
accessorKey: 'period',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ export default async function RegisteredContestTable({
data={data}
columns={columns}
headerStyle={{
title: 'text-left w-2/5 md:w-1/3',
title: 'text-left w-2/5 md:w-1/2',
status: 'w-1/5 md:w-1/6',
participants: 'w-1/5 md:w-1/6',
totalScore: 'w-1/5 md:w-1/6',
period: 'w-1/5 md:w-1/4'
period: 'w-1/5 md:w-1/3'
}}
linked
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ export const columns: ColumnDef<Contest>[] = [
accessorKey: 'participants',
cell: ({ row }) => row.original.participants
},
{
header: 'Total score',
accessorKey: 'totalScore',
cell: () => '000/000'
},
{
header: 'Period',
accessorKey: 'period',
Expand Down
34 changes: 19 additions & 15 deletions apps/frontend/app/(main)/contest/utils.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@
import { fetcherWithAuth } from '@/lib/utils'
import { safeFetcherWithAuth } from '@/lib/utils'
import type { ContestProblem } from '@/types/type'

interface ContestProblemsApiRes {
data: ContestProblem[]
}

const calculateContestScore = async ({ contestId }: { contestId: string }) => {
const contestProblems: ContestProblemsApiRes = await fetcherWithAuth
.get(`contest/${contestId}/problem`)
.json()
try {
const contestProblems: ContestProblemsApiRes = await safeFetcherWithAuth
.get(`contest/${contestId}/problem`)
.json()

const { totalScore, totalMaxScore } = contestProblems.data.reduce(
(acc, curr) => {
const score = curr.score ? parseInt(curr.score, 10) : 0
const maxScore = curr.maxScore || 0
const { totalScore, totalMaxScore } = contestProblems.data.reduce(
(acc, curr) => {
const score = curr.score ? parseInt(curr.score, 10) : 0
const maxScore = curr.maxScore || 0

acc.totalScore += score
acc.totalMaxScore += maxScore
acc.totalScore += score
acc.totalMaxScore += maxScore

return acc
},
{ totalScore: 0, totalMaxScore: 0 }
)
return [totalScore, totalMaxScore]
return acc
},
{ totalScore: 0, totalMaxScore: 0 }
)
return [totalScore, totalMaxScore]
} catch (error) {
return [0, 0]
}
}

export { calculateContestScore }
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export const columns = (
<div className="whitespace-nowrap text-center text-xs font-medium">
{row.original.realName}
</div>
)
),
filterFn: 'includesString'
},
{
accessorKey: 'username',
Expand Down
Loading

0 comments on commit d65be6c

Please sign in to comment.