@@ -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