KinglyEndeavors
KinglyEndeavors
PPrisma
Created by KinglyEndeavors on 7/3/2024 in #help-and-questions
Best Practices for Error Handling When Updating Bridge Table (Composite IDs)
What are the best practices when it comes to going about error handling for a function that is updating a bridge table? Is it necessary to verify to check if the two records that comprises its composite ID (e.g., facilityUuid for the Facility model and workerUuid for the Worker model) before updating it? Or will it check for that on its own as a consequential result? Here's are some snippet examples:
export function updateFacilityWorker(
facilityUuid: FacilityWorker["facilityUuid"],
workerUuid: Worker["uuid"],
data: Omit<Prisma.FacilityWorkerUpdateInput, TimestampFields>
): Promise<UpdatedFacilityWorker> {
return prisma.facilityWorker.update({
select: {
facilityUuid: true,
workerUuid: true,
rating: true,
status: true,
},
where: {
facility_worker_id: { facilityUuid, workerUuid },
},
data,
});
}
export function updateFacilityWorker(
facilityUuid: FacilityWorker["facilityUuid"],
workerUuid: Worker["uuid"],
data: Omit<Prisma.FacilityWorkerUpdateInput, TimestampFields>
): Promise<UpdatedFacilityWorker> {
return prisma.facilityWorker.update({
select: {
facilityUuid: true,
workerUuid: true,
rating: true,
status: true,
},
where: {
facility_worker_id: { facilityUuid, workerUuid },
},
data,
});
}
model FacilityWorker {
facilityUuid String @db.Uuid
facility HealthCareFacility @relation(fields: [facilityUuid], references: [uuid], onDelete: Cascade)

workerUuid String @db.Uuid
worker Worker @relation(fields: [workerUuid], references: [uuid], onDelete: Cascade)

rating Int? @db.SmallInt
status FacilityWorkerStatus @default(Available)

@@id(fields: [facilityUuid, workerUuid], name: "facility_worker_id")
@@index(fields: [facilityUuid, workerUuid, status], name: "worker_status_at_facility")
}
model FacilityWorker {
facilityUuid String @db.Uuid
facility HealthCareFacility @relation(fields: [facilityUuid], references: [uuid], onDelete: Cascade)

workerUuid String @db.Uuid
worker Worker @relation(fields: [workerUuid], references: [uuid], onDelete: Cascade)

rating Int? @db.SmallInt
status FacilityWorkerStatus @default(Available)

@@id(fields: [facilityUuid, workerUuid], name: "facility_worker_id")
@@index(fields: [facilityUuid, workerUuid, status], name: "worker_status_at_facility")
}
16 replies