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 2 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
42 changes: 40 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,46 @@ 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,
status,
contacts,
tier,
value,
joinDate,
activeYears,
taxExempt,
dueDate,
notifyDate,
assignToUserId
} = req.body;
const createdVendor = await ReimbursementRequestService.createVendor(
req.currentUser,
name,
req.organization,
username,
password,
discountCode,
twoFactorContact,
notes,
addedByUserId,
status,
contacts,
tier,
value,
joinDate,
activeYears,
taxExempt,
dueDate,
notifyDate,
assignToUserId
);
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,79 @@
-- CreateEnum
CREATE TYPE "Sponsor_Status" AS ENUM ('ACTIVE', 'INACTIVE');

-- AlterTable
ALTER TABLE "Material" ADD COLUMN "reimbursementNumber" TEXT NOT NULL;

-- AlterTable
ALTER TABLE "Vendor" ADD COLUMN "activeYears" INTEGER NOT NULL DEFAULT 0,
ADD COLUMN "addedByUserId" TEXT NOT NULL DEFAULT '',
ADD COLUMN "assignToUserId" TEXT NOT NULL DEFAULT '',
ADD COLUMN "contacts" TEXT NOT NULL DEFAULT '',
ADD COLUMN "discountCode" TEXT NOT NULL DEFAULT '',
ADD COLUMN "dueDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN "joinDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN "notes" TEXT NOT NULL DEFAULT '',
ADD COLUMN "notifyDate" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
ADD COLUMN "password" TEXT NOT NULL DEFAULT '',
ADD COLUMN "sponsor_TierId" TEXT NOT NULL DEFAULT '',
ADD COLUMN "status" "Sponsor_Status" NOT NULL DEFAULT 'ACTIVE',
ADD COLUMN "taxExempt" BOOLEAN NOT NULL DEFAULT TRUE,
ADD COLUMN "twoFactorContact" TEXT NOT NULL DEFAULT '',
ADD COLUMN "username" TEXT NOT NULL DEFAULT '',
ADD COLUMN "value" INTEGER NOT NULL DEFAULT 0;

-- CreateTable
CREATE TABLE "Sponsor_Tier" (
"id" TEXT NOT NULL,
"name" TEXT NOT NULL,

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

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

-- 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_addedByUserId_fkey" FOREIGN KEY ("addedByUserId") REFERENCES "User"("userId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Vendor" ADD CONSTRAINT "Vendor_sponsor_TierId_fkey" FOREIGN KEY ("sponsor_TierId") REFERENCES "Sponsor_Tier"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Vendor" ADD CONSTRAINT "Vendor_assignToUserId_fkey" FOREIGN KEY ("assignToUserId") REFERENCES "User"("userId") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Material" ADD CONSTRAINT "Material_reimbursementNumber_fkey" FOREIGN KEY ("reimbursementNumber") REFERENCES "Reimbursement_Request"("reimbursementRequestId") 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"
83 changes: 60 additions & 23 deletions src/backend/src/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ enum Special_Permission {
FINANCE_ONLY
}

enum Sponsor_Status {
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
ACTIVE
INACTIVE
}

model User {
userId String @id @default(uuid())
firstName String
Expand Down Expand Up @@ -230,6 +235,8 @@ model User {
deletedTeamTypes Team_Type[] @relation(name: "teamTypeDeleter")
unreadAnnouncements Announcement[] @relation(name: "receivedAnnouncements")
unreadPopUps PopUp[] @relation(name: "userPopUps")
vendorsAdded Vendor[] @relation(name: "vendorsCreator")
vendorsAssigned Vendor[] @relation(name: "assignedVendors")
}

model Role {
Expand Down Expand Up @@ -432,18 +439,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 +604,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,13 +632,32 @@ 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
requests Reimbursement_Request[]
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
organizationId String
organization Organization @relation(fields: [organizationId], references: [organizationId])
username String
password String
discountCode String
twoFactorContact String
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
notes String
addedBy User @relation(fields: [addedByUserId], references: [userId], name: "vendorsCreator")
addedByUserId String
status Sponsor_Status
contacts String
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
tier Sponsor_Tier @relation(fields: [sponsor_TierId], references: [id])
sponsor_TierId String
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
value Int
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
joinDate DateTime
activeYears Int
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
taxExempt Boolean
dueDate DateTime
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
notifyDate DateTime
assignTo User @relation(fields: [assignToUserId], references: [userId], name: "assignedVendors")
assignToUserId String

@@unique([name, organizationId], name: "uniqueVendor")
}
Expand Down Expand Up @@ -700,32 +729,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: [reimbursementNumber], references: [reimbursementRequestId])
reimbursementNumber String
wavehassman marked this conversation as resolved.
Show resolved Hide resolved
}

model Material_Type {
Expand Down Expand Up @@ -1052,3 +1083,9 @@ 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
id String @id @default(uuid())
name String
vendors Vendor[]
}
82 changes: 75 additions & 7 deletions src/backend/src/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1676,9 +1676,76 @@ const performSeed: () => Promise<void> = async () => {
* Reimbursements
*/

const vendor = await ReimbursementRequestService.createVendor(thomasEmrax, 'Tesla', ner);
await ReimbursementRequestService.createVendor(thomasEmrax, 'Amazon', ner);
await ReimbursementRequestService.createVendor(thomasEmrax, 'Google', ner);
const tier = await prisma.sponsor_Tier.create({
data: {
id: '0',
name: 'BRONZE'
}
});

const vendor = await ReimbursementRequestService.createVendor(
thomasEmrax,
'Tesla',
ner,
'[email protected]',
'racecar228!',
'SAVE50!',
'Alex L.',
'Tax exemption status?',
thomasEmrax.userId,
'ACTIVE',
'Jeni Hankon',
tier,
550,
new Date('2023-11-23T00:00:00-04:00'),
3,
true,
new Date('2024-11-23T00:00:00-04:00'),
new Date('2024-01-15T00:00:00-04:00'),
regina.userId
);
await ReimbursementRequestService.createVendor(
thomasEmrax,
'Amazon',
ner,
'[email protected]',
'racecare228!',
'SAVE20!',
'Richard F.',
'They want updates on work',
thomasEmrax.userId,
'INACTIVE',
'Rob',
tier,
1500,
new Date('2023-11-23T00:00:00-04:00'),
5,
true,
new Date('2024-11-23T00:00:00-04:00'),
new Date('2024-01-23T00:00:00-04:00'),
thomasEmrax.userId
);
await ReimbursementRequestService.createVendor(
thomasEmrax,
'Google',
ner,
'[email protected]',
'racecar228!',
'SAVE50!',
'Peyton',
'Tax exemption ID NUMBER',
thomasEmrax.userId,
'ACTIVE',
'Boris P.',
tier,
30000,
new Date('2021-11-25T00:00:00-04:00'),
2,
true,
new Date('2022-11-25T00:00:00-04:00'),
new Date('2023-01-25T00:00:00-04:00'),
thomasEmrax.userId
);

const accountCode = await ReimbursementRequestService.createAccountCode(
thomasEmrax,
Expand All @@ -1689,7 +1756,7 @@ const performSeed: () => Promise<void> = async () => {
ner
);

await ReimbursementRequestService.createReimbursementRequest(
const reimbursement1 = await ReimbursementRequestService.createReimbursementRequest(
thomasEmrax,
vendor.vendorId,
ClubAccount.CASH,
Expand All @@ -1710,7 +1777,7 @@ const performSeed: () => Promise<void> = async () => {
ner
);

await ReimbursementRequestService.createReimbursementRequest(
const reimbursement2 = await ReimbursementRequestService.createReimbursementRequest(
thomasEmrax,
vendor.vendorId,
ClubAccount.BUDGET,
Expand Down Expand Up @@ -1766,6 +1833,7 @@ const performSeed: () => Promise<void> = async () => {
workPackageNumber: 0
},
ner,
reimbursement1.reimbursementRequestId,
'Here are some notes'
);

Expand All @@ -1786,8 +1854,8 @@ const performSeed: () => Promise<void> = async () => {
workPackageNumber: 0
},
ner,
'Here are some more notes',
assembly1.assemblyId
reimbursement2.reimbursementRequestId,
'Here are some more notes'
);

// Need to do this because the design review cannot be scheduled for a past day
Expand Down
Loading
Loading