Skip to content

Commit da8253c

Browse files
committed
#1525 requested changes
1 parent 4072655 commit da8253c

4 files changed

Lines changed: 16 additions & 13 deletions

File tree

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ export default class ProjectsController {
159159
} = req.body;
160160
const creator = await getCurrentUser(res);
161161
const wbsNum = validateWBS(req.params.wbsNum);
162-
const id = await ProjectsService.createMaterial(
162+
const material = await ProjectsService.createMaterial(
163163
creator,
164164
name,
165165
status,
@@ -176,7 +176,7 @@ export default class ProjectsController {
176176
assemblyId,
177177
pdmFileName
178178
);
179-
return res.status(200).json({ message: `Successfully created material with id #${id}` });
179+
return material;
180180
} catch (error: unknown) {
181181
next(error);
182182
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Material_Type, User, Assembly, Material_Status } from '@prisma/client';
1+
import { Material_Type, User, Assembly, Material_Status, Material } from '@prisma/client';
22
import { isAdmin, isGuest, isLeadership, isProject, LinkCreateArgs, LinkType, Project, WbsNumber, wbsPipe } from 'shared';
33
import projectQueryArgs from '../prisma-query-args/projects.query-args';
44
import prisma from '../prisma/prisma';
@@ -609,20 +609,20 @@ export default class ProjectsService {
609609
* Creates a new Material
610610
* @param creator the user creating the material
611611
* @param name the name of the material
612-
* @param assemblyId the id of the Assembly for the material
613612
* @param status the Material Status of the material
614613
* @param materialTypeName the name of the Material Type
615614
* @param manufacturerName the name of the material's manufacturer
616615
* @param manufacturerPartNumber the manufacturer part number for the material
617-
* @param pdmFileName the name of the pdm file for the material
618616
* @param quantity the quantity of material as a number
619617
* @param unitName the name of the Quantity Unit the quantity is measured in
620618
* @param price the price of the material in whole cents
621619
* @param subtotal the subtotal of the price for the material in whole cents
622620
* @param linkUrl the url for the material's link as a string
623621
* @param notes any notes about the material as a string
624622
* @param wbsNumber the WBS number of the project associated with this material
625-
* @returns the id of the created material
623+
* @param assemblyId the id of the Assembly for the material
624+
* @param pdmFileName the name of the pdm file for the material
625+
* @returns the created material
626626
*/
627627
static async createMaterial(
628628
creator: User,
@@ -640,7 +640,7 @@ export default class ProjectsService {
640640
wbsNumber: WbsNumber,
641641
assemblyId?: string,
642642
pdmFileName?: string
643-
): Promise<string> {
643+
): Promise<Material> {
644644
const project = await prisma.project.findFirst({
645645
where: {
646646
wbsElement: {
@@ -699,7 +699,7 @@ export default class ProjectsService {
699699
}
700700
});
701701

702-
return createdMaterial.materialId;
702+
return createdMaterial;
703703
}
704704

705705
/**

src/backend/src/utils/validation.utils.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import { Material_Status } from '@prisma/client';
21
import { ValidationChain } from 'express-validator';
3-
import { ClubAccount } from 'shared';
2+
import { ClubAccount, MaterialStatus } from 'shared';
43
import { TaskPriority, TaskStatus, WorkPackageStage, RoleEnum } from 'shared';
54

65
export const intMinZero = (validationObject: ValidationChain): ValidationChain => {
@@ -47,7 +46,5 @@ export const isAccount = (validationObject: ValidationChain): ValidationChain =>
4746
};
4847

4948
export const isMaterialStatus = (validationObject: ValidationChain): ValidationChain => {
50-
return validationObject
51-
.isString()
52-
.isIn([Material_Status.ORDERED, Material_Status.RECEIVED, Material_Status.SHIPPED, Material_Status.UNORDERED]);
49+
return validationObject.isString().isIn([MaterialStatus.Ordered, MaterialStatus.Received, MaterialStatus.Unordered]);
5350
};

src/shared/src/types/project-types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,3 +95,9 @@ export interface LinkCreateArgs {
9595
linkTypeName: string;
9696
url: string;
9797
}
98+
99+
export enum MaterialStatus {
100+
Ordered = 'ORDERED',
101+
Received = 'RECEIVED',
102+
Unordered = 'UNORDERED'
103+
}

0 commit comments

Comments
 (0)