From 74ccba9dcc2bfd6e9d92839f23ed74f28fbc7e90 Mon Sep 17 00:00:00 2001 From: Chris Pyle Date: Fri, 24 Jan 2025 18:53:36 -0500 Subject: [PATCH] #3124 minor changes, naming fixes, and migration changes --- .../controllers/recruitment.controllers.ts | 8 ++-- .../migration.sql | 40 +++++++------------ src/backend/src/prisma/schema.prisma | 19 ++++----- src/backend/src/prisma/seed.ts | 16 ++++++-- src/backend/src/routes/recruitment.routes.ts | 4 +- .../src/services/recruitment.services.ts | 4 +- 6 files changed, 43 insertions(+), 48 deletions(-) rename src/backend/src/prisma/migrations/{20250124040302_cad_part_file_review => 20250124235046_cad_part_file_review}/migration.sql (89%) diff --git a/src/backend/src/controllers/recruitment.controllers.ts b/src/backend/src/controllers/recruitment.controllers.ts index 3dfdc0eeeb..8bf4f90130 100644 --- a/src/backend/src/controllers/recruitment.controllers.ts +++ b/src/backend/src/controllers/recruitment.controllers.ts @@ -57,19 +57,19 @@ export default class RecruitmentController { } } - static async getAllFaqs(req: Request, res: Response, next: NextFunction) { + static async getAllOrganizationFaqs(req: Request, res: Response, next: NextFunction) { try { - const allFaqs = await RecruitmentServices.getAllFaqs(req.organization); + const allFaqs = await RecruitmentServices.getAllOrganizationFaqs(req.organization); res.status(200).json(allFaqs); } catch (error: unknown) { next(error); } } - static async createFaq(req: Request, res: Response, next: NextFunction) { + static async createOrganizationFaq(req: Request, res: Response, next: NextFunction) { try { const { question, answer } = req.body; - const faq = await RecruitmentServices.createFaq(req.currentUser, question, answer, req.organization); + const faq = await RecruitmentServices.createOrganizationFaq(req.currentUser, question, answer, req.organization); res.status(200).json(faq); } catch (error: unknown) { next(error); diff --git a/src/backend/src/prisma/migrations/20250124040302_cad_part_file_review/migration.sql b/src/backend/src/prisma/migrations/20250124235046_cad_part_file_review/migration.sql similarity index 89% rename from src/backend/src/prisma/migrations/20250124040302_cad_part_file_review/migration.sql rename to src/backend/src/prisma/migrations/20250124235046_cad_part_file_review/migration.sql index 9574dc8887..1b0c29f897 100644 --- a/src/backend/src/prisma/migrations/20250124040302_cad_part_file_review/migration.sql +++ b/src/backend/src/prisma/migrations/20250124235046_cad_part_file_review/migration.sql @@ -9,11 +9,12 @@ CREATE TYPE "Review_Status" AS ENUM ('IN_PROGRESS', 'READY_FOR_REVIEW', 'IN_REVI -- DropForeignKey ALTER TABLE "FrequentlyAskedQuestion" DROP CONSTRAINT "FrequentlyAskedQuestion_organizationId_fkey"; - --- AlterTable -ALTER TABLE "FrequentlyAskedQuestion" DROP COLUMN "organizationId", -ADD COLUMN "partReviewFaqOrgId" TEXT, -ADD COLUMN "regularFaqOrgId" TEXT; +ALTER TABLE "FrequentlyAskedQuestion" RENAME COLUMN "organizationId" TO "regularFaqOrgId"; +ALTER TABLE "FrequentlyAskedQuestion" ADD COLUMN "partReviewFaqOrgId" TEXT; +ALTER TABLE "FrequentlyAskedQuestion" ADD CONSTRAINT "FrequentlyAskedQuestion_regularFaqOrgId_fkey" FOREIGN KEY ("regularFaqOrgId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE "FrequentlyAskedQuestion" ADD CONSTRAINT "FrequentlyAskedQuestion_partReviewFaqOrgId_fkey" FOREIGN KEY ("partReviewFaqOrgId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; +-- Add constriant so every faq is either a reulage faq or a part review faq +ALTER TABLE "FrequentlyAskedQuestion" ADD CONSTRAINT "at_least_one_field_required" CHECK ("regularFaqOrgId" IS NOT NULL OR "partReviewFaqOrgId" IS NOT NULL); -- AlterTable ALTER TABLE "Organization" ADD COLUMN "partReviewSampleImageId" TEXT; @@ -24,7 +25,6 @@ ALTER TABLE "Project" ADD COLUMN "abbreviation" TEXT; -- CreateTable CREATE TABLE "Part" ( "partId" TEXT NOT NULL, - "organizationId" TEXT NOT NULL, "index" INTEGER NOT NULL, "commonName" TEXT NOT NULL, "description" TEXT, @@ -43,14 +43,14 @@ CREATE TABLE "Part" ( -- CreateTable CREATE TABLE "PartTag" ( - "id" TEXT NOT NULL, + "partTagId" TEXT NOT NULL, "name" TEXT NOT NULL, - "color" TEXT NOT NULL, + "colorHexCode" TEXT NOT NULL, "dateCreated" TIMESTAMP(3) NOT NULL, "dateDeleted" TIMESTAMP(3), - "OrganizationId" TEXT, + "organizationId" TEXT, - CONSTRAINT "PartTag_pkey" PRIMARY KEY ("id") + CONSTRAINT "PartTag_pkey" PRIMARY KEY ("partTagId") ); -- CreateTable @@ -110,7 +110,7 @@ CREATE TABLE "PartReviewCommonMistake" ( "userDeletedId" TEXT, "dateCreated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, "dateDeleted" TIMESTAMP(3), - "OrganizationId" TEXT, + "organizationId" TEXT, CONSTRAINT "PartReviewCommonMistake_pkey" PRIMARY KEY ("id") ); @@ -151,18 +151,6 @@ CREATE UNIQUE INDEX "_partReviewers_AB_unique" ON "_partReviewers"("A", "B"); -- CreateIndex CREATE INDEX "_partReviewers_B_index" ON "_partReviewers"("B"); --- AddForeignKey -ALTER TABLE "FrequentlyAskedQuestion" ADD CONSTRAINT "FrequentlyAskedQuestion_regularFaqOrgId_fkey" FOREIGN KEY ("regularFaqOrgId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; - --- AddForeignKey -ALTER TABLE "FrequentlyAskedQuestion" ADD CONSTRAINT "FrequentlyAskedQuestion_partReviewFaqOrgId_fkey" FOREIGN KEY ("partReviewFaqOrgId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; - --- Add Constraint so FAQs must have either a regularFaqOrg or a partReviewFaqOrg -ALTER TABLE "FrequentlyAskedQuestion" ADD CONSTRAINT "at_least_one_field_required" CHECK ("regularFaqOrgId" IS NOT NULL OR "partReviewFaqOrgId" IS NOT NULL); - --- AddForeignKey -ALTER TABLE "Part" ADD CONSTRAINT "Part_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("organizationId") ON DELETE RESTRICT ON UPDATE CASCADE; - -- AddForeignKey ALTER TABLE "Part" ADD CONSTRAINT "Part_projectId_fkey" FOREIGN KEY ("projectId") REFERENCES "Project"("projectId") ON DELETE RESTRICT ON UPDATE CASCADE; @@ -173,7 +161,7 @@ ALTER TABLE "Part" ADD CONSTRAINT "Part_userCreatedId_fkey" FOREIGN KEY ("userCr ALTER TABLE "Part" ADD CONSTRAINT "Part_userDeletedId_fkey" FOREIGN KEY ("userDeletedId") REFERENCES "User"("userId") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "PartTag" ADD CONSTRAINT "PartTag_OrganizationId_fkey" FOREIGN KEY ("OrganizationId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE "PartTag" ADD CONSTRAINT "PartTag_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "PartSubmission" ADD CONSTRAINT "PartSubmission_partId_fkey" FOREIGN KEY ("partId") REFERENCES "Part"("partId") ON DELETE RESTRICT ON UPDATE CASCADE; @@ -203,13 +191,13 @@ ALTER TABLE "PartReviewCommonMistake" ADD CONSTRAINT "PartReviewCommonMistake_us ALTER TABLE "PartReviewCommonMistake" ADD CONSTRAINT "PartReviewCommonMistake_userDeletedId_fkey" FOREIGN KEY ("userDeletedId") REFERENCES "User"("userId") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "PartReviewCommonMistake" ADD CONSTRAINT "PartReviewCommonMistake_OrganizationId_fkey" FOREIGN KEY ("OrganizationId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; +ALTER TABLE "PartReviewCommonMistake" ADD CONSTRAINT "PartReviewCommonMistake_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("organizationId") ON DELETE SET NULL ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "_PartToPartTag" ADD CONSTRAINT "_PartToPartTag_A_fkey" FOREIGN KEY ("A") REFERENCES "Part"("partId") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey -ALTER TABLE "_PartToPartTag" ADD CONSTRAINT "_PartToPartTag_B_fkey" FOREIGN KEY ("B") REFERENCES "PartTag"("id") ON DELETE CASCADE ON UPDATE CASCADE; +ALTER TABLE "_PartToPartTag" ADD CONSTRAINT "_PartToPartTag_B_fkey" FOREIGN KEY ("B") REFERENCES "PartTag"("partTagId") ON DELETE CASCADE ON UPDATE CASCADE; -- AddForeignKey ALTER TABLE "_partAssignees" ADD CONSTRAINT "_partAssignees_A_fkey" FOREIGN KEY ("A") REFERENCES "Part"("partId") ON DELETE CASCADE ON UPDATE CASCADE; diff --git a/src/backend/src/prisma/schema.prisma b/src/backend/src/prisma/schema.prisma index 89a8f7dea4..3d679e977e 100644 --- a/src/backend/src/prisma/schema.prisma +++ b/src/backend/src/prisma/schema.prisma @@ -984,7 +984,7 @@ model Organization { changeRequests Change_Request[] reimbursementReqeusts Reimbursement_Request[] usefulLinks Link[] - frequentlyAskedQuestions FrequentlyAskedQuestion[] @relation(name: "regularFaq") + frequentlyAskedQuestions FrequentlyAskedQuestion[] @relation(name: "organizationFAQ") partReviewFAQ FrequentlyAskedQuestion[] milestones Milestone[] graphCollections Graph_Collection[] @@ -994,7 +994,6 @@ model Organization { announcements Announcement[] checklists Checklist[] contacts Contact[] - parts Part[] partReviewCommonMistakes PartReviewCommonMistake[] partTags PartTag[] } @@ -1010,7 +1009,7 @@ model FrequentlyAskedQuestion { dateCreated DateTime @default(now()) dateDeleted DateTime? regularFaqOrgId String? - regularFaqOrg Organization? @relation(fields: [regularFaqOrgId], references: [organizationId], name: "regularFaq") + regularFaqOrg Organization? @relation(fields: [regularFaqOrgId], references: [organizationId], name: "organizationFAQ") partReviewFaqOrgId String? partReviewFaqOrg Organization? @relation(fields: [partReviewFaqOrgId], references: [organizationId]) } @@ -1129,8 +1128,6 @@ model Contact { model Part { partId String @id @default(uuid()) - organizationId String - organization Organization @relation(fields: [organizationId], references: [organizationId]) index Int commonName String description String? @@ -1153,14 +1150,14 @@ model Part { } model PartTag { - id String @id @default(uuid()) + partTagId String @id @default(uuid()) name String - color String + colorHexCode String dateCreated DateTime dateDeleted DateTime? parts Part[] - Organization Organization? @relation(fields: [OrganizationId], references: [organizationId]) - OrganizationId String? + organization Organization? @relation(fields: [organizationId], references: [organizationId]) + organizationId String? } model PartSubmission { @@ -1221,6 +1218,6 @@ model PartReviewCommonMistake { userDeletedId String? dateCreated DateTime @default(now()) dateDeleted DateTime? - Organization Organization? @relation(fields: [OrganizationId], references: [organizationId]) - OrganizationId String? + organization Organization? @relation(fields: [organizationId], references: [organizationId]) + organizationId String? } diff --git a/src/backend/src/prisma/seed.ts b/src/backend/src/prisma/seed.ts index a4d7975763..9401dad479 100644 --- a/src/backend/src/prisma/seed.ts +++ b/src/backend/src/prisma/seed.ts @@ -1998,9 +1998,19 @@ const performSeed: () => Promise = async () => { await RecruitmentServices.createMilestone(batman, 'Applications Close', '', new Date('11/27/24'), ner); await RecruitmentServices.createMilestone(batman, 'Decision Day!', '', new Date('12/4/24'), ner); - await RecruitmentServices.createFaq(batman, 'Who is the Chief Software Engineer?', 'Peyton McKee', ner); - await RecruitmentServices.createFaq(batman, 'When was FinishLine created?', 'FinishLine was created in 2019', ner); - await RecruitmentServices.createFaq(batman, 'How many developers are working on FinishLine?', '178 as of 2024', ner); + await RecruitmentServices.createOrganizationFaq(batman, 'Who is the Chief Software Engineer?', 'Peyton McKee', ner); + await RecruitmentServices.createOrganizationFaq( + batman, + 'When was FinishLine created?', + 'FinishLine was created in 2019', + ner + ); + await RecruitmentServices.createOrganizationFaq( + batman, + 'How many developers are working on FinishLine?', + '178 as of 2024', + ner + ); await AnnouncementService.createAnnouncement( 'Welcome to Finishline!', diff --git a/src/backend/src/routes/recruitment.routes.ts b/src/backend/src/routes/recruitment.routes.ts index 2b7ae7b201..7a5c932fb5 100644 --- a/src/backend/src/routes/recruitment.routes.ts +++ b/src/backend/src/routes/recruitment.routes.ts @@ -30,14 +30,14 @@ recruitmentRouter.delete('/milestone/:milestoneId/delete', RecruitmentController /* FAQ Section */ -recruitmentRouter.get('/faqs', RecruitmentController.getAllFaqs); +recruitmentRouter.get('/faqs', RecruitmentController.getAllOrganizationFaqs); recruitmentRouter.post( '/faq/create', nonEmptyString(body('question')), nonEmptyString(body('answer')), validateInputs, - RecruitmentController.createFaq + RecruitmentController.createOrganizationFaq ); recruitmentRouter.post( diff --git a/src/backend/src/services/recruitment.services.ts b/src/backend/src/services/recruitment.services.ts index 089e0c1c4b..7fd6975ded 100644 --- a/src/backend/src/services/recruitment.services.ts +++ b/src/backend/src/services/recruitment.services.ts @@ -104,7 +104,7 @@ export default class RecruitmentServices { * @param organizationId organization Id of the faq * @returns all the faqs from the given organization */ - static async getAllFaqs(organization: Organization) { + static async getAllOrganizationFaqs(organization: Organization) { const allFaqs = await prisma.frequentlyAskedQuestion.findMany({ where: { dateDeleted: null, regularFaqOrgId: organization.organizationId } }); @@ -142,7 +142,7 @@ export default class RecruitmentServices { * @param organizationId the organization Id of the FAQ * @returns A newly created FAQ */ - static async createFaq(submitter: User, question: string, answer: string, organization: Organization) { + static async createOrganizationFaq(submitter: User, question: string, answer: string, organization: Organization) { if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin))) throw new AccessDeniedAdminOnlyException('create an faq');