Skip to content

Commit 32292b8

Browse files
committed
#1526 - move some things around/ make it one migration
1 parent ebabe35 commit 32292b8

5 files changed

Lines changed: 32 additions & 34 deletions

File tree

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,14 +167,14 @@ export default class ProjectsController {
167167
manufacturerName,
168168
manufacturerPartNumber,
169169
quantity,
170-
unitName,
171170
price,
172171
subtotal,
173172
linkUrl,
174173
notes,
175174
wbsNum,
176175
assemblyId,
177-
pdmFileName
176+
pdmFileName,
177+
unitName
178178
);
179179
return res.status(200).json(material);
180180
} catch (error: unknown) {
@@ -222,6 +222,7 @@ export default class ProjectsController {
222222
name,
223223
assemblyId,
224224
status,
225+
materialTypeName,
225226
manufacturerName,
226227
manufacturerPartNumber,
227228
pdmFileName,
@@ -237,6 +238,7 @@ export default class ProjectsController {
237238
materialId,
238239
name,
239240
status,
241+
materialTypeName,
240242
manufacturerName,
241243
manufacturerPartNumber,
242244
quantity,

src/backend/src/prisma/migrations/20231116035430_material_name_prop_edit/migration.sql

Lines changed: 0 additions & 2 deletions
This file was deleted.

src/backend/src/prisma/migrations/20231024124220_add_bom/migration.sql renamed to src/backend/src/prisma/migrations/20231119042617_add_bom/migration.sql

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ CREATE TABLE "Manufacturer" (
6868
-- CreateIndex
6969
CREATE UNIQUE INDEX "Assembly_name_key" ON "Assembly"("name");
7070

71-
-- CreateIndex
72-
CREATE UNIQUE INDEX "Material_name_key" ON "Material"("name");
73-
7471
-- AddForeignKey
7572
ALTER TABLE "Assembly" ADD CONSTRAINT "Assembly_userDeletedId_fkey" FOREIGN KEY ("userDeletedId") REFERENCES "User"("userId") ON DELETE SET NULL ON UPDATE CASCADE;
7673

src/backend/src/services/projects.services.ts

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -617,14 +617,14 @@ export default class ProjectsService {
617617
* @param manufacturerName the name of the material's manufacturer
618618
* @param manufacturerPartNumber the manufacturer part number for the material
619619
* @param quantity the quantity of material as a number
620-
* @param unitName the name of the Quantity Unit the quantity is measured in
621620
* @param price the price of the material in whole cents
622621
* @param subtotal the subtotal of the price for the material in whole cents
623622
* @param linkUrl the url for the material's link as a string
624623
* @param notes any notes about the material as a string
625624
* @param wbsNumber the WBS number of the project associated with this material
626625
* @param assemblyId the id of the Assembly for the material
627626
* @param pdmFileName the name of the pdm file for the material
627+
* @param unitName the name of the Quantity Unit the quantity is measured in
628628
* @returns the created material
629629
*/
630630
static async createMaterial(
@@ -635,14 +635,14 @@ export default class ProjectsService {
635635
manufacturerName: string,
636636
manufacturerPartNumber: string,
637637
quantity: number,
638-
unitName: string,
639638
price: number,
640639
subtotal: number,
641640
linkUrl: string,
642641
notes: string,
643642
wbsNumber: WbsNumber,
644643
assemblyId?: string,
645-
pdmFileName?: string
644+
pdmFileName?: string,
645+
unitName?: string
646646
): Promise<Material> {
647647
const project = await prisma.project.findFirst({
648648
where: {
@@ -657,7 +657,7 @@ export default class ProjectsService {
657657

658658
if (!project) throw new NotFoundException('Project', wbsPipe(wbsNumber));
659659

660-
await checkMaterialInputs(manufacturerName, unitName, assemblyId, materialTypeName);
660+
await checkMaterialInputs(manufacturerName, materialTypeName, unitName, assemblyId);
661661

662662
const perms = isLeadership(creator.role) || isUserPartOfTeams(project.teams, creator);
663663

@@ -816,19 +816,20 @@ export default class ProjectsService {
816816
/**
817817
* Update a material
818818
* @param submitter the submitter of the request
819-
* @param materialId the material id of the new material
820-
* @param name the name of the new material
821-
* @param status the status of the new material
822-
* @param manufacturerName the manufacturerName of the new material
823-
* @param manufacturerPartNumber the manufacturerPartNumber of the new material
824-
* @param quantity the quantity of the new material
825-
* @param price the price of the new material
826-
* @param subtotal the subtotal of the new material
827-
* @param linkUrl the linkUrl of the new material
828-
* @param notes the notes of the new material
829-
* @param unitName the unit name of the new material
830-
* @param assemblyId the assembly id of the new material
831-
* @param pdmFileName the pdm file name of the new material
819+
* @param materialId the material id of the material being edited
820+
* @param name the name of the edited material
821+
* @param status the status of the edited material
822+
* @param materialTypeName the material type of the edited material
823+
* @param manufacturerName the manufacturerName of the edited material
824+
* @param manufacturerPartNumber the manufacturerPartNumber of the edited material
825+
* @param quantity the quantity of the edited material
826+
* @param price the price of the edited material
827+
* @param subtotal the subtotal of the edited material
828+
* @param linkUrl the linkUrl of the edited material
829+
* @param notes the notes of the edited material
830+
* @param unitName the unit name of the edited material
831+
* @param assemblyId the assembly id of the edited material
832+
* @param pdmFileName the pdm file name of the edited material
832833
* @throws if permission denied or material's wbsElement is undefined/deleted
833834
* @returns the updated material
834835
*/
@@ -837,6 +838,7 @@ export default class ProjectsService {
837838
materialId: string,
838839
name: string,
839840
status: Material_Status,
841+
materialTypeName: string,
840842
manufacturerName: string,
841843
manufacturerPartNumber: string,
842844
quantity: number,
@@ -867,7 +869,7 @@ export default class ProjectsService {
867869
if (!project) throw new NotFoundException('Project', material.wbsElementId);
868870
if (project.wbsElement.dateDeleted) throw new DeletedException('Project', project.projectId);
869871

870-
await checkMaterialInputs(manufacturerName, unitName, assemblyId);
872+
await checkMaterialInputs(manufacturerName, materialTypeName, unitName, assemblyId);
871873

872874
const perms = isLeadership(submitter.role) || isUserPartOfTeams(project.teams, submitter);
873875

@@ -878,6 +880,7 @@ export default class ProjectsService {
878880
data: {
879881
name,
880882
status,
883+
materialTypeName,
881884
manufacturerName,
882885
manufacturerPartNumber,
883886
quantity,

src/backend/src/utils/projects.utils.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,26 @@ export const getUserFullName = async (userId: number | null): Promise<string | n
6464
/**
6565
* Check if given assembly, material type, manufacturer, and unit exist in the app database
6666
* @param manufacturerName the manufacure of the material to check if it exists
67+
* @param materialTypeName the material type of the material to check if it exists
6768
* @param unitName the unit of the material to check if it exists
6869
* @param assemblyId the assembly of the material to check if it exists
69-
* @param materialTypeName the material type of the material to check if it exists
7070
* @throws if any of these properties of the material does not exist in the db
7171
*/
7272
export const checkMaterialInputs = async (
7373
manufacturerName: string,
74+
materialTypeName: string,
7475
unitName?: string,
75-
assemblyId?: string,
76-
materialTypeName?: string
76+
assemblyId?: string
7777
) => {
7878
if (!!assemblyId) {
7979
const assembly = await prisma.assembly.findFirst({ where: { assemblyId } });
8080
if (!assembly) throw new NotFoundException('Assembly', assemblyId);
8181
}
8282

83-
if (!!materialTypeName) {
84-
const materialType = await prisma.material_Type.findFirst({
85-
where: { name: materialTypeName }
86-
});
87-
if (!materialType) throw new NotFoundException('Material Type', materialTypeName);
88-
}
83+
const materialType = await prisma.material_Type.findFirst({
84+
where: { name: materialTypeName }
85+
});
86+
if (!materialType) throw new NotFoundException('Material Type', materialTypeName);
8987

9088
const manufacturer = await prisma.manufacturer.findFirst({
9189
where: { name: manufacturerName }

0 commit comments

Comments
 (0)