Skip to content

Commit 85f9531

Browse files
authored
Merge pull request #3732 from Northeastern-Electric-Racing/3731-maintenence---link-types-cannot-be-edited
#3731 link type edit works
2 parents 48efad2 + 0c9ccb7 commit 85f9531

5 files changed

Lines changed: 26 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -437,13 +437,14 @@ export default class ProjectsController {
437437
static async editLinkType(req: Request, res: Response, next: NextFunction) {
438438
try {
439439
const { linkTypeName } = req.params;
440-
const { iconName, required } = req.body;
440+
const { name: newName, iconName, required } = req.body;
441441
const linkTypeUpdated = await ProjectsService.editLinkType(
442442
linkTypeName,
443443
iconName,
444444
required,
445445
req.currentUser,
446-
req.organization
446+
req.organization,
447+
newName
447448
);
448449
res.status(200).json(linkTypeUpdated);
449450
} catch (error: unknown) {

src/backend/src/routes/projects.routes.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ projectRouter.post(
2929
);
3030
projectRouter.post(
3131
'/link-types/:linkTypeName/edit',
32+
nonEmptyString(body('name').optional()),
3233
nonEmptyString(body('iconName')),
3334
body('required').isBoolean(),
3435
validateInputs,

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,8 @@ export default class ProjectsService {
621621
iconName: string,
622622
required: boolean,
623623
submitter: User,
624-
organization: Organization
624+
organization: Organization,
625+
newName?: string
625626
): Promise<LinkType> {
626627
if (!(await userHasPermission(submitter.userId, organization.organizationId, isAdmin)))
627628
throw new AccessDeniedException('Only an admin can update the linkType');
@@ -638,11 +639,25 @@ export default class ProjectsService {
638639

639640
if (!linkType) throw new NotFoundException('Link Type', linkName);
640641

642+
// If attempting to rename, ensure new name does not conflict with an existing LinkType
643+
if (newName && newName !== linkName) {
644+
const existingWithNewName = await prisma.link_Type.findUnique({
645+
where: {
646+
uniqueLinkType: {
647+
name: newName,
648+
organizationId: organization.organizationId
649+
}
650+
}
651+
});
652+
653+
if (existingWithNewName) throw new HttpException(400, 'LinkType with that name already exists in this organization.');
654+
}
655+
641656
// update the LinkType
642657
const linkTypeUpdated = await prisma.link_Type.update({
643658
where: { id: linkType.id },
644659
data: {
645-
name: linkName,
660+
name: newName && newName ? newName : linkName,
646661
iconName,
647662
required
648663
}

src/frontend/src/pages/AdminToolsPage/ProjectsConfig/LinkTypes/LinkTypeFormModal.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ const LinkTypeFormModal = ({ open, handleClose, defaultValues, onSubmit, linkTyp
6363
}
6464
handleClose();
6565
};
66+
6667
const tooltipMessage = (
6768
<Typography sx={{ fontSize: 14 }}>
6869
Click to view possible icon names. For names with multiple words, seperate them with an _. AttachMoney = attach_money
@@ -73,7 +74,7 @@ const LinkTypeFormModal = ({ open, handleClose, defaultValues, onSubmit, linkTyp
7374
open={open}
7475
onHide={handleClose}
7576
title={!!defaultValues ? 'Edit LinkType' : 'Create LinkType'}
76-
reset={() => reset({ name: '' })}
77+
reset={reset}
7778
handleUseFormSubmit={handleSubmit}
7879
onFormSubmit={onFormSubmit}
7980
formId={!!defaultValues ? 'edit-LinkType-form' : 'create-LinkType-form'}
@@ -83,7 +84,7 @@ const LinkTypeFormModal = ({ open, handleClose, defaultValues, onSubmit, linkTyp
8384
<Grid item xs={6}>
8485
<FormControl fullWidth>
8586
<FormLabel>LinkType Name</FormLabel>
86-
<ReactHookTextField name="name" control={control} disabled={!creatingNew} />
87+
<ReactHookTextField name="name" control={control} />
8788
<FormHelperText error>{errors.name?.message}</FormHelperText>
8889
</FormControl>
8990
</Grid>

src/frontend/src/pages/SettingsPage/UserScheduleSettings/UserScheduleSettingsView.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ const UserScheduleSettingsView = ({
5757
return (
5858
<Grid container rowSpacing={1} columnSpacing={4}>
5959
<SingleAvailabilityModal
60-
open={availabilityOpen}
60+
open={confirmAvailabilityOpen}
6161
onHide={() => setAvailabilityOpen(false)}
6262
header={'Availability'}
6363
availabilites={scheduleSettings.availabilities}
6464
/>
6565
<AvailabilityEditModal
66-
open={confirmAvailabilityOpen}
66+
open={availabilityOpen}
6767
onHide={() => setConfirmAvailabilityOpen(false)}
6868
header={confirmModalTitle}
6969
confirmedAvailabilities={confirmedAvailabilities}

0 commit comments

Comments
 (0)