Skip to content

Commit 764bcb9

Browse files
authored
Merge pull request #1445 from rit-construct-makerspace/main
Only change hobbs time on instance edit if necessary. Don't require an access controller to set hobbs time
2 parents c108d62 + ef3d927 commit 764bcb9

2 files changed

Lines changed: 23 additions & 19 deletions

File tree

client/src/pages/makerspace_page/equipment_pages/EquipmentInstanceRow.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,10 @@ export default function EquipmentInstanceRow(props: EquipmentInstanceRowProps) {
5757

5858
async function handleSave() {
5959
setAllowEdit(false);
60-
await updateInstanceHobbsTime({ variables: { id: props.instance.id, hobbsTime: hobbsTime } })
60+
61+
if (hobbsTime != props.instance.hobbsTime){
62+
await updateInstanceHobbsTime({ variables: { id: props.instance.id, hobbsTime: hobbsTime } })
63+
}
6164
await updateInstance({ variables: { id: props.instance.id, name: name, status: status } })
6265
await updatePairing({ variables: { id: Number(props.instance.id), accessControllerID: pairedController?.id } })
6366
}

server/src/graphql/resolvers/equipmentInstanceResolver.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,34 +151,35 @@ const EquipmentInstanceResolver = {
151151
const equipment = await EquipmentRepo.getEquipmentByID(instance.equipmentID);
152152
if (!equipment) throw new GraphQLError("Instance does not have associated Machine");
153153

154-
const room = await RoomRepo.getRoomByID(equipment.roomID)
154+
const room = await RoomRepo.getRoomByID(equipment.roomID)
155155
if (!room) throw new GraphQLError("Instance does not have associated Room");
156-
157-
if (!instance.accessControllerID) throw new GraphQLError("Instance has no associated access controller")
158-
159-
const accessController = await ACRepo.getAccessControllerByID(instance.accessControllerID)
160-
if (!accessController) throw new GraphQLError("Instance has no associated access controller")
161-
162-
163156
const newInstance = await InstanceRepo.updateInstanceHobbsTime(args.id, args.hobbsTime);
164157

165-
ACSOrchestrator.handleSendCoreCommand(accessController.deviceID, {
166-
hobbsTime: [{channelID: accessController.channelID, hobbsTime: args.hobbsTime}]
167-
})
158+
if (instance.accessControllerID) {
159+
const accessController = await ACRepo.getAccessControllerByID(instance.accessControllerID)
160+
161+
if (accessController) {
162+
ACSOrchestrator.handleSendCoreCommand(accessController.deviceID, {
163+
hobbsTime: [{ channelID: accessController.channelID, hobbsTime: args.hobbsTime }]
164+
})
165+
} else {
166+
throw new GraphQLError("Could not find AccessController to update");
167+
}
168+
}
168169

169170
await createAuditLog(`{user} set hobbs time of instance '${instance?.name}' of equipment {equipment} to ${args.hobbsTime} seconds from ${instance.hobbsTime} seconds`, 'admin', room.makerspaceID ?? undefined, { id: user.id, label: getUsersFullName(user) }, { id: equipment.id, label: equipment.name });
170171

171172
return newInstance;
172173
}),
173174

174175

175-
/**
176-
* Update the status field of an Equipment Instance
177-
* @argument id ID of equipment instance to modify
178-
* @argument status New Instance status
179-
* @returns updated equipment instance
180-
* @throws GraphQLError if not MENTOR or STAFF or is on hold or equipment instance does not exist
181-
*/
176+
/**
177+
* Update the status field of an Equipment Instance
178+
* @argument id ID of equipment instance to modify
179+
* @argument status New Instance status
180+
* @returns updated equipment instance
181+
* @throws GraphQLError if not MENTOR or STAFF or is on hold or equipment instance does not exist
182+
*/
182183
setInstanceStatus: async (
183184
_parent: any,
184185
args: { id: number, status: string },

0 commit comments

Comments
 (0)