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,
});
}
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")
}
Tt is necessary to verify that the two records comprising its composite ID exist before updating the bridge table. This is to ensure data integrity and to avoid potential errors during the update process.