Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#3128: Schema Changes #3150

Merged
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/backend/src/controllers/reimbursement-requests.controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,18 @@ export default class ReimbursementRequestsController {

static async createVendor(req: Request, res: Response, next: NextFunction) {
try {
const { name } = req.body;
const createdVendor = await ReimbursementRequestService.createVendor(req.currentUser, name, req.organization);
const { name, username, password, discountCode, twoFactorContact, notes, addedByUserId } = req.body;
const createdVendor = await ReimbursementRequestService.createVendor(
req.currentUser,
name,
req.organization,
username,
password,
discountCode,
twoFactorContact,
notes,
addedByUserId
);
res.status(200).json(createdVendor);
} catch (error: unknown) {
next(error);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
-- AlterTable
ALTER TABLE "Material" ADD COLUMN "reimbursementRequestId" TEXT NOT NULL DEFAULT '';

-- AlterTable
ALTER TABLE "Vendor" ADD COLUMN "addedByUserId" TEXT,
ADD COLUMN "discountCode" TEXT,
ADD COLUMN "notes" TEXT,
ADD COLUMN "password" TEXT NOT NULL DEFAULT '',
ADD COLUMN "twoFactorContactId" TEXT,
ADD COLUMN "username" TEXT NOT NULL DEFAULT '';

-- CreateTable
CREATE TABLE "Sponsor" (
"sponsorId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"dateCreated" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"dateDeleted" TIMESTAMP(3),
"activeStatus" BOOLEAN NOT NULL,
"vendorContact" TEXT NOT NULL,
"sponsorTierId" TEXT NOT NULL,
"sponsorValue" INTEGER NOT NULL,
"joinDate" TIMESTAMP(3) NOT NULL,
"discountCode" TEXT,
"activeYears" INTEGER[],
"taxExempt" BOOLEAN NOT NULL,

CONSTRAINT "Sponsor_pkey" PRIMARY KEY ("sponsorId")
);

-- CreateTable
CREATE TABLE "Sponsor_Task" (
"sponsorTaskId" TEXT NOT NULL,
"dueDate" TIMESTAMP(3) NOT NULL,
"notifyDate" TIMESTAMP(3),
"assigneeUserId" TEXT,
"notes" TEXT NOT NULL,
"sponsorId" TEXT NOT NULL,

CONSTRAINT "Sponsor_Task_pkey" PRIMARY KEY ("sponsorTaskId")
);

-- CreateTable
CREATE TABLE "Sponsor_Tier" (
"sponsorTierId" TEXT NOT NULL,
"organizationId" TEXT NOT NULL,
"name" TEXT NOT NULL,
"colorHexCode" TEXT NOT NULL,

CONSTRAINT "Sponsor_Tier_pkey" PRIMARY KEY ("sponsorTierId")
);

-- CreateTable
CREATE TABLE "_ProjectToReimbursement_Request" (
"A" TEXT NOT NULL,
"B" TEXT NOT NULL
);

-- CreateIndex
CREATE UNIQUE INDEX "Sponsor_name_organizationId_key" ON "Sponsor"("name", "organizationId");

-- CreateIndex
CREATE UNIQUE INDEX "_ProjectToReimbursement_Request_AB_unique" ON "_ProjectToReimbursement_Request"("A", "B");

-- CreateIndex
CREATE INDEX "_ProjectToReimbursement_Request_B_index" ON "_ProjectToReimbursement_Request"("B");

-- AddForeignKey
ALTER TABLE "Vendor" ADD CONSTRAINT "Vendor_twoFactorContactId_fkey" FOREIGN KEY ("twoFactorContactId") REFERENCES "User"("userId") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Vendor" ADD CONSTRAINT "Vendor_addedByUserId_fkey" FOREIGN KEY ("addedByUserId") REFERENCES "User"("userId") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Sponsor" ADD CONSTRAINT "Sponsor_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("organizationId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Sponsor" ADD CONSTRAINT "Sponsor_sponsorTierId_fkey" FOREIGN KEY ("sponsorTierId") REFERENCES "Sponsor_Tier"("sponsorTierId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Sponsor_Task" ADD CONSTRAINT "Sponsor_Task_assigneeUserId_fkey" FOREIGN KEY ("assigneeUserId") REFERENCES "User"("userId") ON DELETE SET NULL ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Sponsor_Task" ADD CONSTRAINT "Sponsor_Task_sponsorId_fkey" FOREIGN KEY ("sponsorId") REFERENCES "Sponsor"("sponsorId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Material" ADD CONSTRAINT "Material_reimbursementRequestId_fkey" FOREIGN KEY ("reimbursementRequestId") REFERENCES "Reimbursement_Request"("reimbursementRequestId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Sponsor_Tier" ADD CONSTRAINT "Sponsor_Tier_organizationId_fkey" FOREIGN KEY ("organizationId") REFERENCES "Organization"("organizationId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_ProjectToReimbursement_Request" ADD CONSTRAINT "_ProjectToReimbursement_Request_A_fkey" FOREIGN KEY ("A") REFERENCES "Project"("projectId") ON DELETE CASCADE ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "_ProjectToReimbursement_Request" ADD CONSTRAINT "_ProjectToReimbursement_Request_B_fkey" FOREIGN KEY ("B") REFERENCES "Reimbursement_Request"("reimbursementRequestId") ON DELETE CASCADE ON UPDATE CASCADE;

ALTER TABLE "_ProjectToReimbursement_Request" RENAME COLUMN "A" TO "projectId";

ALTER TABLE "_ProjectToReimbursement_Request" RENAME COLUMN "B" TO "reimbursementRequestId";

INSERT INTO "_ProjectToReimbursement_Request" ("projectId", "reimbursementRequestId")

SELECT DISTINCT Project."projectId" as "projectId", "Reimbursement_Request"."reimbursementRequestId" as "reimbursementRequestId"

FROM "Reimbursement_Request"

JOIN "Reimbursement_Product" reimbursementProduct ON "Reimbursement_Request"."reimbursementRequestId" = reimbursementProduct."reimbursementRequestId"

JOIN "Reimbursement_Product_Reason" reimbursementProductReason ON reimbursementProduct."reimbursementProductReasonId" = reimbursementProductReason."reimbursementProductReasonId"

JOIN "WBS_Element" wbs_element ON reimbursementProductReason."wbsElementId" = wbs_element."wbsElementId"

JOIN "Project" project ON project."wbsElementId" = wbs_element."wbsElementId"
105 changes: 82 additions & 23 deletions src/backend/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,9 @@ model User {
deletedTeamTypes Team_Type[] @relation(name: "teamTypeDeleter")
unreadAnnouncements Announcement[] @relation(name: "receivedAnnouncements")
unreadPopUps PopUp[] @relation(name: "userPopUps")
vendorsAdded Vendor[] @relation(name: "vendorsCreator")
sponsorTasksAssigned Sponsor_Task[] @relation(name: "assignedSponsorTasks")
twoFactorContactVendors Vendor[] @relation(name: "twoFactorContactVendors")
}

model Role {
Expand Down Expand Up @@ -432,18 +435,19 @@ model WBS_Element {
}

model Project {
projectId String @id @default(uuid())
wbsElementId String @unique
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
budget Int @default(0)
projectId String @id @default(uuid())
wbsElementId String @unique
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
budget Int @default(0)
summary String
workPackages Work_Package[]
carId String
car Car @relation(fields: [carId], references: [carId])
teams Team[] @relation(name: "assignedBy")
favoritedBy User[] @relation(name: "favoritedBy")
car Car @relation(fields: [carId], references: [carId])
teams Team[] @relation(name: "assignedBy")
favoritedBy User[] @relation(name: "favoritedBy")
featuredByOrganizationId String?
featuredByOrganization Organization? @relation(fields: [featuredByOrganizationId], references: [organizationId])
featuredByOrganization Organization? @relation(fields: [featuredByOrganizationId], references: [organizationId])
reimbursementRequests Reimbursement_Request[]
}

model Work_Package {
Expand Down Expand Up @@ -596,6 +600,8 @@ model Reimbursement_Request {
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
notificationSlackThreads Message_Info[]
materials Material[]
projects Project[]

@@unique([identifier, organizationId], name: "uniqueReimbursementRequest")
}
Expand All @@ -622,17 +628,57 @@ model Reimbursement_Product {
}

model Vendor {
walker-sean marked this conversation as resolved.
Show resolved Hide resolved
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
vendorId String @id @default(uuid())
dateCreated DateTime @default(now())
dateDeleted DateTime?
name String
requests Reimbursement_Request[]
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
vendorId String @id @default(uuid())
dateCreated DateTime @default(now())
dateDeleted DateTime?
name String
reimbursementRequests Reimbursement_Request[]
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
username String
password String
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
discountCode String?
twoFactorContact User? @relation(fields: [twoFactorContactId], references: [userId], name: "twoFactorContactVendors")
twoFactorContactId String?
notes String?
addedBy User? @relation(fields: [addedByUserId], references: [userId], name: "vendorsCreator")
addedByUserId String?

@@unique([name, organizationId], name: "uniqueVendor")
}

model Sponsor {
sponsorId String @id @default(uuid())
name String
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
dateCreated DateTime @default(now())
dateDeleted DateTime?
activeStatus Boolean
vendorContact String
tier Sponsor_Tier @relation(fields: [sponsorTierId], references: [sponsorTierId])
sponsorTierId String
sponsorValue Int
joinDate DateTime
discountCode String?
activeYears Int[]
taxExempt Boolean
sponsorTasks Sponsor_Task[]

@@unique([name, organizationId], name: "uniqueSponsor")
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
}

model Sponsor_Task {
sponsorTaskId String @id @default(uuid())
dueDate DateTime
notifyDate DateTime?
assignee User? @relation(fields: [assigneeUserId], references: [userId], name: "assignedSponsorTasks")
assigneeUserId String?
notes String
sponosor Sponsor @relation(fields: [sponsorId], references: [sponsorId])
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
sponsorId String
}

model Account_Code {
accountCodeId String @id @default(uuid())
name String
Expand Down Expand Up @@ -700,32 +746,34 @@ model Assembly {
}

model Material {
materialId String @id @default(uuid())
assembly Assembly? @relation(fields: [assemblyId], references: [assemblyId])
materialId String @id @default(uuid())
assembly Assembly? @relation(fields: [assemblyId], references: [assemblyId])
assemblyId String?
name String
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
wbsElement WBS_Element @relation(fields: [wbsElementId], references: [wbsElementId])
wbsElementId String
dateDeleted DateTime?
userDeleted User? @relation(fields: [userDeletedId], references: [userId], name: "materialDeleter")
userDeleted User? @relation(fields: [userDeletedId], references: [userId], name: "materialDeleter")
userDeletedId String?
dateCreated DateTime
userCreated User @relation(fields: [userCreatedId], references: [userId], name: "materialCreator")
userCreated User @relation(fields: [userCreatedId], references: [userId], name: "materialCreator")
userCreatedId String
status Material_Status
materialType Material_Type @relation(fields: [materialTypeId], references: [id])
materialType Material_Type @relation(fields: [materialTypeId], references: [id])
materialTypeId String
manufacturer Manufacturer @relation(fields: [manufacturerId], references: [id])
manufacturer Manufacturer @relation(fields: [manufacturerId], references: [id])
manufacturerId String
manufacturerPartNumber String
pdmFileName String?
quantity Decimal
unit Unit? @relation(fields: [unitId], references: [id])
unit Unit? @relation(fields: [unitId], references: [id])
unitId String?
price Int
subtotal Int
linkUrl String
notes String?
reimbursementRequest Reimbursement_Request @relation(fields: [reimbursementRequestId], references: [reimbursementRequestId])
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
reimbursementRequestId String
}

model Material_Type {
Expand Down Expand Up @@ -959,6 +1007,8 @@ model Organization {
featuredProjects Project[]
popUps PopUp[]
announcements Announcement[]
sponsors Sponsor[]
sponsorTiers Sponsor_Tier[]
}

model FrequentlyAskedQuestion {
Expand Down Expand Up @@ -1052,3 +1102,12 @@ model PopUp {
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
}

model Sponsor_Tier {
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
sponsorTierId String @id @default(uuid())
organization Organization @relation(fields: [organizationId], references: [organizationId])
organizationId String
name String
colorHexCode String
sponsors Sponsor[]
}
Loading
Loading