From 67cc99a61806d06968f3cfb165327a03555f6cc8 Mon Sep 17 00:00:00 2001 From: Jurre Brandsen Date: Fri, 22 Mar 2024 13:29:23 +0100 Subject: [PATCH] updated selected visibility for selected answer --- .gitignore | 4 +- .../20240322122417_init/migration.sql | 162 ++++++++++++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/seed.ts | 2 +- src/components/survey-questions.tsx | 2 +- 5 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 prisma/migrations/20240322122417_init/migration.sql create mode 100644 prisma/migrations/migration_lock.toml diff --git a/.gitignore b/.gitignore index b9d14df..71cbeb2 100644 --- a/.gitignore +++ b/.gitignore @@ -41,6 +41,4 @@ yarn-error.log* # typescript *.tsbuildinfo -/import - -/prisma/migrations \ No newline at end of file +/import \ No newline at end of file diff --git a/prisma/migrations/20240322122417_init/migration.sql b/prisma/migrations/20240322122417_init/migration.sql new file mode 100644 index 0000000..0e06454 --- /dev/null +++ b/prisma/migrations/20240322122417_init/migration.sql @@ -0,0 +1,162 @@ +-- CreateTable +CREATE TABLE "Survey" ( + "id" TEXT NOT NULL, + "surveyName" TEXT NOT NULL, + + CONSTRAINT "Survey_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Role" ( + "id" TEXT NOT NULL, + "role" TEXT NOT NULL, + "default" BOOLEAN NOT NULL DEFAULT false, + + CONSTRAINT "Role_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Question" ( + "id" TEXT NOT NULL, + "surveyId" TEXT NOT NULL, + "questionText" TEXT NOT NULL, + + CONSTRAINT "Question_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "AnswerOption" ( + "id" TEXT NOT NULL, + "option" INTEGER NOT NULL, + + CONSTRAINT "AnswerOption_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "QuestionResult" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "questionId" TEXT NOT NULL, + "answerId" TEXT NOT NULL, + + CONSTRAINT "QuestionResult_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL, + "name" TEXT, + "email" TEXT, + "emailVerified" TIMESTAMP(3), + "image" TEXT, + + CONSTRAINT "User_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "access_token" TEXT, + "expires_at" INTEGER, + "ext_expires_in" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT, + + CONSTRAINT "Account_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL, + "sessionToken" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "expires" TIMESTAMP(3) NOT NULL, + + CONSTRAINT "Session_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" TIMESTAMP(3) NOT NULL +); + +-- CreateTable +CREATE TABLE "_UserRole" ( + "A" TEXT NOT NULL, + "B" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "_QuestionToRole" ( + "A" TEXT NOT NULL, + "B" TEXT NOT NULL +); + +-- CreateIndex +CREATE UNIQUE INDEX "Survey_surveyName_key" ON "Survey"("surveyName"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); + +-- CreateIndex +CREATE UNIQUE INDEX "_UserRole_AB_unique" ON "_UserRole"("A", "B"); + +-- CreateIndex +CREATE INDEX "_UserRole_B_index" ON "_UserRole"("B"); + +-- CreateIndex +CREATE UNIQUE INDEX "_QuestionToRole_AB_unique" ON "_QuestionToRole"("A", "B"); + +-- CreateIndex +CREATE INDEX "_QuestionToRole_B_index" ON "_QuestionToRole"("B"); + +-- AddForeignKey +ALTER TABLE "Question" ADD CONSTRAINT "Question_surveyId_fkey" FOREIGN KEY ("surveyId") REFERENCES "Survey"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "QuestionResult" ADD CONSTRAINT "QuestionResult_answerId_fkey" FOREIGN KEY ("answerId") REFERENCES "AnswerOption"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "QuestionResult" ADD CONSTRAINT "QuestionResult_questionId_fkey" FOREIGN KEY ("questionId") REFERENCES "Question"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "QuestionResult" ADD CONSTRAINT "QuestionResult_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_UserRole" ADD CONSTRAINT "_UserRole_A_fkey" FOREIGN KEY ("A") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_UserRole" ADD CONSTRAINT "_UserRole_B_fkey" FOREIGN KEY ("B") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_QuestionToRole" ADD CONSTRAINT "_QuestionToRole_A_fkey" FOREIGN KEY ("A") REFERENCES "Question"("id") ON DELETE CASCADE ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "_QuestionToRole" ADD CONSTRAINT "_QuestionToRole_B_fkey" FOREIGN KEY ("B") REFERENCES "Role"("id") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..fbffa92 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "postgresql" \ No newline at end of file diff --git a/prisma/seed.ts b/prisma/seed.ts index 81256b0..9d85c14 100644 --- a/prisma/seed.ts +++ b/prisma/seed.ts @@ -104,7 +104,7 @@ async function main() { const newRole = await prisma.role.create({ data: { role: role, - default: false, + default: role === "General" ? true : false, }, }); roleObjects.push(newRole); diff --git a/src/components/survey-questions.tsx b/src/components/survey-questions.tsx index 1e9ac4c..8d50fc4 100644 --- a/src/components/survey-questions.tsx +++ b/src/components/survey-questions.tsx @@ -193,7 +193,7 @@ export function SurveyQuestions({ className={`${ field.value === option.id || responses[question.id] === option.id - ? "rounded-lg border border-custom-selectedLight dark:border-custom-selected " + ? "rounded-lg border-2 border-custom-selected " : "" }flex h-[40px] cursor-pointer items-center justify-center`} >