Skip to content

Commit

Permalink
#3124 minor changes, naming fixes, and migration changes
Browse files Browse the repository at this point in the history
  • Loading branch information
chpy04 committed Jan 24, 2025
1 parent 3071a3f commit 74ccba9
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 48 deletions.
8 changes: 4 additions & 4 deletions src/backend/src/controllers/recruitment.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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")
);
Expand Down Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
19 changes: 8 additions & 11 deletions src/backend/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -994,7 +994,6 @@ model Organization {
announcements Announcement[]
checklists Checklist[]
contacts Contact[]
parts Part[]
partReviewCommonMistakes PartReviewCommonMistake[]
partTags PartTag[]
}
Expand All @@ -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])
}
Expand Down Expand Up @@ -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?
Expand All @@ -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 {
Expand Down Expand Up @@ -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?
}
16 changes: 13 additions & 3 deletions src/backend/src/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1998,9 +1998,19 @@ const performSeed: () => Promise<void> = 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!',
Expand Down
4 changes: 2 additions & 2 deletions src/backend/src/routes/recruitment.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions src/backend/src/services/recruitment.services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
});
Expand Down Expand Up @@ -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');

Expand Down

0 comments on commit 74ccba9

Please sign in to comment.