Skip to content

Commit 825629c

Browse files
committed
#3867 first round of changes
1 parent 60755b9 commit 825629c

15 files changed

Lines changed: 201 additions & 138 deletions

File tree

src/backend/src/controllers/projects.controllers.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -216,17 +216,17 @@ export default class ProjectsController {
216216
name,
217217
status,
218218
materialTypeName,
219+
linkUrl,
220+
wbsNum,
221+
req.organization,
219222
manufacturerName,
220223
manufacturerPartNumber,
221224
quantity,
222225
price,
223226
subtotal,
224-
linkUrl,
225-
wbsNum,
226-
req.organization,
227227
notes,
228228
assemblyId,
229-
pdmFileName === '' ? undefined : pdmFileName,
229+
pdmFileName,
230230
unitName,
231231
reimbursementRequestId
232232
);
@@ -379,17 +379,17 @@ export default class ProjectsController {
379379
name,
380380
status,
381381
materialTypeName,
382+
linkUrl,
383+
req.organization,
382384
manufacturerName,
383385
manufacturerPartNumber,
384386
quantity,
385387
price,
386388
subtotal,
387-
linkUrl,
388-
req.organization,
389389
notes,
390390
unitName,
391391
assemblyId,
392-
pdmFileName === '' ? undefined : pdmFileName,
392+
pdmFileName,
393393
reimbursementRequestId
394394
);
395395
res.status(200).json(updatedMaterial);

src/backend/src/prisma-query-args/bom.query-args.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const getMaterialQueryArgs = (organizationId: string) =>
2525
materialType: true,
2626
unit: true,
2727
manufacturer: true,
28+
reimbursementProduct: false,
2829
reimbursementRequest: getReimbursementRequestQueryArgs(organizationId)
2930
}
3031
});
@@ -37,6 +38,7 @@ export const getMaterialPreviewQueryArgs = (organizationId: string) =>
3738
unit: true,
3839
manufacturer: true,
3940
materialType: true,
41+
reimbursementProduct: false,
4042
reimbursementRequest: getReimbursementRequestQueryArgs(organizationId)
4143
}
4244
});

src/backend/src/prisma-query-args/reimbursement-products.query-args.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export const getReimbursementProductQueryArgs = (organizationId: string) =>
2525
Prisma.validator<Prisma.Reimbursement_ProductDefaultArgs>()({
2626
include: {
2727
refundSources: getRefundSourceQueryArgs(organizationId),
28-
reimbursementProductReason: getReimbursementProductReasonQueryArgs(organizationId)
28+
reimbursementProductReason: getReimbursementProductReasonQueryArgs(organizationId),
29+
material: true
2930
}
3031
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
Warnings:
3+
4+
- A unique constraint covering the columns `[materialId]` on the table `Reimbursement_Product` will be added. If there are existing duplicate values, this will fail.
5+
6+
*/
7+
-- DropForeignKey
8+
ALTER TABLE "Material" DROP CONSTRAINT "Material_manufacturerId_fkey";
9+
10+
-- AlterTable
11+
ALTER TABLE "Material" ALTER COLUMN "manufacturerId" DROP NOT NULL,
12+
ALTER COLUMN "manufacturerPartNumber" DROP NOT NULL,
13+
ALTER COLUMN "quantity" DROP NOT NULL,
14+
ALTER COLUMN "price" DROP NOT NULL,
15+
ALTER COLUMN "subtotal" DROP NOT NULL;
16+
17+
-- AlterTable
18+
ALTER TABLE "Reimbursement_Product" ADD COLUMN "materialId" TEXT;
19+
20+
-- CreateIndex
21+
CREATE UNIQUE INDEX "Reimbursement_Product_materialId_key" ON "Reimbursement_Product"("materialId");
22+
23+
-- CreateIndex
24+
CREATE INDEX "Reimbursement_Product_materialId_idx" ON "Reimbursement_Product"("materialId");
25+
26+
-- AddForeignKey
27+
ALTER TABLE "Reimbursement_Product" ADD CONSTRAINT "Reimbursement_Product_materialId_fkey" FOREIGN KEY ("materialId") REFERENCES "Material"("materialId") ON DELETE SET NULL ON UPDATE CASCADE;
28+
29+
-- AddForeignKey
30+
ALTER TABLE "Material" ADD CONSTRAINT "Material_manufacturerId_fkey" FOREIGN KEY ("manufacturerId") REFERENCES "Manufacturer"("id") ON DELETE SET NULL ON UPDATE CASCADE;

src/backend/src/prisma/schema.prisma

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,8 @@ model Reimbursement_Product {
736736
name String
737737
dateDeleted DateTime?
738738
cost Int
739+
material Material? @relation(fields: [materialId], references: [materialId])
740+
materialId String? @unique
739741
reimbursementProductReasonId String @unique
740742
reimbursementProductReason Reimbursement_Product_Reason @relation(fields: [reimbursementProductReasonId], references: [reimbursementProductReasonId])
741743
reimbursementRequestId String
@@ -744,6 +746,7 @@ model Reimbursement_Product {
744746
745747
@@index([reimbursementRequestId])
746748
@@index([reimbursementProductReasonId])
749+
@@index([materialId])
747750
}
748751

749752
model Refund_Source {
@@ -908,19 +911,20 @@ model Material {
908911
status Material_Status
909912
materialType Material_Type @relation(fields: [materialTypeId], references: [id])
910913
materialTypeId String
911-
manufacturer Manufacturer @relation(fields: [manufacturerId], references: [id])
912-
manufacturerId String
913-
manufacturerPartNumber String
914+
manufacturer Manufacturer? @relation(fields: [manufacturerId], references: [id])
915+
manufacturerId String?
916+
manufacturerPartNumber String?
914917
pdmFileName String?
915-
quantity Decimal
918+
quantity Decimal?
916919
unit Unit? @relation(fields: [unitId], references: [id])
917920
unitId String?
918-
price Int
919-
subtotal Int
921+
price Int?
922+
subtotal Int?
920923
linkUrl String
921924
notes String?
922925
reimbursementRequest Reimbursement_Request? @relation(fields: [reimbursementRequestId], references: [reimbursementRequestId])
923926
reimbursementRequestId String?
927+
reimbursementProduct Reimbursement_Product?
924928
925929
@@index([assemblyId])
926930
@@index([materialTypeId])

src/backend/src/prisma/seed.ts

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,58 +2289,66 @@ const performSeed: () => Promise<void> = async () => {
22892289
'10k Resistor',
22902290
MaterialStatus.Ordered,
22912291
'Resistor',
2292-
'Digikey',
2293-
'abcdef',
2294-
new Decimal(20),
2295-
30,
2296-
600,
22972292
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
22982293
{
22992294
carNumber: 0,
23002295
projectNumber: 1,
23012296
workPackageNumber: 0
23022297
},
23032298
ner,
2304-
'Here are some notes'
2299+
'Digikey',
2300+
'abcdef',
2301+
new Decimal(20),
2302+
30,
2303+
600,
2304+
'Here are some notes',
2305+
assembly1.assemblyId,
2306+
undefined,
2307+
undefined,
2308+
undefined
23052309
);
23062310

23072311
await BillOfMaterialsService.createMaterial(
23082312
thomasEmrax,
23092313
'20k Resistor',
23102314
MaterialStatus.Ordered,
23112315
'Resistor',
2312-
'Digikey',
2313-
'bacfed',
2314-
new Decimal(10),
2315-
7,
2316-
70,
23172316
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
23182317
{
23192318
carNumber: 0,
23202319
projectNumber: 1,
23212320
workPackageNumber: 0
23222321
},
23232322
ner,
2324-
'Here are some more notes'
2323+
'Digikey',
2324+
'bacfed',
2325+
new Decimal(10),
2326+
7,
2327+
70,
2328+
'Here are some more notes',
2329+
undefined,
2330+
undefined,
2331+
undefined,
2332+
undefined
23252333
);
23262334

23272335
await BillOfMaterialsService.createMaterial(
23282336
thomasEmrax,
23292337
'100k Resistor',
23302338
MaterialStatus.ReadyToOrder,
23312339
'Resistor',
2332-
'Digikey',
2333-
'lalsd',
2334-
new Decimal(5),
2335-
10,
2336-
50,
23372340
'https://www.youtube.com/watch?v=dQw4w9WgXcQ',
23382341
{
23392342
carNumber: 0,
23402343
projectNumber: 1,
23412344
workPackageNumber: 0
23422345
},
23432346
ner,
2347+
'Digikey',
2348+
'lalsd',
2349+
new Decimal(5),
2350+
10,
2351+
50,
23442352
undefined,
23452353
undefined,
23462354
undefined,

src/backend/src/services/boms.services.ts

Lines changed: 46 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -49,34 +49,34 @@ export default class BillOfMaterialsService {
4949
* @param name the name of the material
5050
* @param status the Material Status of the material
5151
* @param materialTypeName the name of the Material Type
52-
* @param manufacturerName the name of the material's manufacturer
53-
* @param manufacturerPartNumber the manufacturer part number for the material
54-
* @param quantity the quantity of material as a number
55-
* @param price the price of the material in whole cents
56-
* @param subtotal the subtotal of the price for the material in whole cents
5752
* @param linkUrl the url for the material's link as a string
58-
* @param notes any notes about the material as a string
5953
* @param wbsNumber the WBS number of the project associated with this material
60-
* @param organizationId the id of the organization the user is currently in
61-
* @param assemblyId the id of the Assembly for the material
62-
* @param pdmFileName the name of the pdm file for the material
63-
* @param unitName the name of the Quantity Unit the quantity is measured in
64-
* @param reimbursementRequestId the id of the Reimbursement Request for the material
54+
* @param organization the organization the user is currently in
55+
* @param manufacturerName the name of the material's manufacturer (optional)
56+
* @param manufacturerPartNumber the manufacturer part number for the material (optional)
57+
* @param quantity the quantity of material as a number (optional)
58+
* @param price the price of the material in whole cents (optional)
59+
* @param subtotal the subtotal of the price for the material in whole cents (optional)
60+
* @param notes any notes about the material as a string (optional)
61+
* @param assemblyId the id of the Assembly for the material (optional)
62+
* @param pdmFileName the name of the pdm file for the material (optional)
63+
* @param unitName the name of the Quantity Unit the quantity is measured in (optional)
64+
* @param reimbursementRequestId the id of the Reimbursement Request for the material (optional)
6565
* @returns the created material
6666
*/
6767
static async createMaterial(
6868
creator: User,
6969
name: string,
7070
status: Material_Status,
7171
materialTypeName: string,
72-
manufacturerName: string,
73-
manufacturerPartNumber: string,
74-
quantity: Decimal,
75-
price: number,
76-
subtotal: number,
7772
linkUrl: string,
7873
wbsNumber: WbsNumber,
7974
organization: Organization,
75+
manufacturerName?: string,
76+
manufacturerPartNumber?: string,
77+
quantity?: Decimal,
78+
price?: number,
79+
subtotal?: number,
8080
notes?: string,
8181
assemblyId?: string,
8282
pdmFileName?: string,
@@ -98,11 +98,14 @@ export default class BillOfMaterialsService {
9898
if (!materialType) throw new NotFoundException('Material Type', materialTypeName);
9999
if (materialType.dateDeleted) throw new DeletedException('Material Type', materialTypeName);
100100

101-
const manufacturer = await prisma.manufacturer.findUnique({
102-
where: { uniqueManufacturer: { name: manufacturerName, organizationId: organization.organizationId } }
103-
});
104-
if (!manufacturer) throw new NotFoundException('Manufacturer', manufacturerName);
105-
if (manufacturer.dateDeleted) throw new DeletedException('Manufacturer', manufacturerName);
101+
let manufacturer = null;
102+
if (manufacturerName) {
103+
manufacturer = await prisma.manufacturer.findUnique({
104+
where: { uniqueManufacturer: { name: manufacturerName, organizationId: organization.organizationId } }
105+
});
106+
if (!manufacturer) throw new NotFoundException('Manufacturer', manufacturerName);
107+
if (manufacturer.dateDeleted) throw new DeletedException('Manufacturer', manufacturerName);
108+
}
106109

107110
let unit = null;
108111
if (unitName) {
@@ -135,7 +138,7 @@ export default class BillOfMaterialsService {
135138
assemblyId,
136139
status,
137140
materialTypeId: materialType.id,
138-
manufacturerId: manufacturer.id,
141+
manufacturerId: manufacturer ? manufacturer.id : null,
139142
manufacturerPartNumber,
140143
pdmFileName,
141144
quantity,
@@ -542,18 +545,18 @@ export default class BillOfMaterialsService {
542545
* @param name the name of the edited material
543546
* @param status the status of the edited material
544547
* @param materialTypeName the material type of the edited material
545-
* @param manufacturerName the manufacturerName of the edited material
546-
* @param manufacturerPartNumber the manufacturerPartNumber of the edited material
547-
* @param quantity the quantity of the edited material
548-
* @param price the price of the edited material
549-
* @param subtotal the subtotal of the edited material
550548
* @param linkUrl the linkUrl of the edited material
551-
* @param organizationId the organization the user is currently in
552-
* @param notes the notes of the edited material
553-
* @param unitName the unit name of the edited material
554-
* @param assemblyId the assembly id of the edited material
555-
* @param pdmFileName the pdm file name of the edited material
556-
* @param reimbursementRequestId the id of the Reimbursement Request for the material
549+
* @param organization the organization the user is currently in
550+
* @param manufacturerName the manufacturerName of the edited material (optional)
551+
* @param manufacturerPartNumber the manufacturerPartNumber of the edited material (optional)
552+
* @param quantity the quantity of the edited material (optional)
553+
* @param price the price of the edited material (optional)
554+
* @param subtotal the subtotal of the edited material (optional)
555+
* @param notes the notes of the edited material (optional)
556+
* @param unitName the unit name of the edited material (optional)
557+
* @param assemblyId the assembly id of the edited material (optional)
558+
* @param pdmFileName the pdm file name of the edited material (optional)
559+
* @param reimbursementRequestId the id of the Reimbursement Request for the material (optional)
557560
* @throws if permission denied or material's wbsElement is undefined/deleted
558561
* @returns the updated material
559562
*/
@@ -563,13 +566,13 @@ export default class BillOfMaterialsService {
563566
name: string,
564567
status: Material_Status,
565568
materialTypeName: string,
566-
manufacturerName: string,
567-
manufacturerPartNumber: string,
568-
quantity: Decimal,
569-
price: number,
570-
subtotal: number,
571569
linkUrl: string,
572570
organization: Organization,
571+
manufacturerName?: string,
572+
manufacturerPartNumber?: string,
573+
quantity?: Decimal,
574+
price?: number,
575+
subtotal?: number,
573576
notes?: string,
574577
unitName?: string,
575578
assemblyId?: string,
@@ -614,15 +617,18 @@ export default class BillOfMaterialsService {
614617
}
615618
}
616619

617-
const manufacturer = await BillOfMaterialsService.getSingleManufacturerWithQueryArgs(manufacturerName, organization);
620+
let manufacturer = null;
621+
if (manufacturerName) {
622+
manufacturer = await BillOfMaterialsService.getSingleManufacturerWithQueryArgs(manufacturerName, organization);
623+
}
618624

619625
const updatedMaterial = await prisma.material.update({
620626
where: { materialId },
621627
data: {
622628
name,
623629
status,
624630
materialTypeId: materialType.id,
625-
manufacturerId: manufacturer.id,
631+
manufacturerId: manufacturer ? manufacturer.id : null,
626632
manufacturerPartNumber,
627633
quantity,
628634
unitId: unit ? unit.id : null,

0 commit comments

Comments
 (0)