Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
fix: add unique constraints on survey-taget table
Browse files Browse the repository at this point in the history
  • Loading branch information
jspark2000 committed Mar 14, 2024
1 parent 7762466 commit dc4754f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions backend/app/src/survey/survey.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { RosterService } from '@/roster/roster.service'
import { Service } from '@libs/decorator'
import {
BusinessException,
ConflictFoundException,
EntityNotExistException,
UnexpectedException
} from '@libs/exception'
Expand Down Expand Up @@ -287,11 +288,11 @@ export class SurveyService {
if (error instanceof BusinessException) {
throw error
}
if (
error instanceof Prisma.PrismaClientKnownRequestError &&
error.code === 'P2025'
) {
throw new EntityNotExistException('출석조사 대상이 아닙니다')
if (error instanceof Prisma.PrismaClientKnownRequestError) {
if (error.code === 'P2003')
throw new ConflictFoundException('이미 제출하였습니다')
if (error.code === 'P2025')
throw new EntityNotExistException('출석조사 대상이 아닙니다')
}
throw new UnexpectedException(error)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,7 @@ CREATE TABLE "surveyGroup" (
CREATE TABLE "surveyTarget" (
"roster_id" INTEGER NOT NULL,
"survey_group_id" INTEGER NOT NULL,
"submit" BOOLEAN NOT NULL DEFAULT false,

CONSTRAINT "surveyTarget_pkey" PRIMARY KEY ("roster_id","survey_group_id")
"submit" BOOLEAN NOT NULL DEFAULT false
);

-- CreateTable
Expand Down Expand Up @@ -174,6 +172,9 @@ CREATE UNIQUE INDEX "user_email_key" ON "user"("email");
-- CreateIndex
CREATE UNIQUE INDEX "roster_student_id_key" ON "roster"("student_id");

-- CreateIndex
CREATE UNIQUE INDEX "surveyTarget_roster_id_survey_group_id_key" ON "surveyTarget"("roster_id", "survey_group_id");

-- AddForeignKey
ALTER TABLE "roster" ADD CONSTRAINT "roster_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE SET NULL ON UPDATE CASCADE;

Expand Down
2 changes: 1 addition & 1 deletion backend/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ model SurveyTarget {
Roster Roster @relation(fields: [rosterId], references: [id], onDelete: Cascade)
SurveyGroup SurveyGroup @relation(fields: [surveyGroupId], references: [id], onDelete: Cascade)
@@id([rosterId, surveyGroupId])
@@unique([rosterId, surveyGroupId])
@@map("surveyTarget")
}

Expand Down

0 comments on commit dc4754f

Please sign in to comment.