import { Staff } from "@repo/db/types"; import { prisma as db } from "@repo/db/client"; export interface IStorage { getStaff(id: number): Promise; getAllStaff(): Promise; createStaff(staff: Staff): Promise; updateStaff(id: number, updates: Partial): Promise; deleteStaff(id: number): Promise; countAppointmentsByStaffId(staffId: number): Promise; countClaimsByStaffId(staffId: number): Promise; } export const staffStorage: IStorage = { // Staff methods async getStaff(id: number): Promise { const staff = await db.staff.findUnique({ where: { id } }); return staff ?? undefined; }, async getAllStaff(): Promise { const staff = await db.staff.findMany(); return staff; }, async createStaff(staff: Staff): Promise { const createdStaff = await db.staff.create({ data: staff, }); return createdStaff; }, async updateStaff( id: number, updates: Partial ): Promise { const updatedStaff = await db.staff.update({ where: { id }, data: updates, }); return updatedStaff ?? undefined; }, async deleteStaff(id: number): Promise { try { await db.staff.delete({ where: { id } }); return true; } catch (error) { console.error("Error deleting staff:", error); return false; } }, async countAppointmentsByStaffId(staffId: number): Promise { return await db.appointment.count({ where: { staffId } }); }, async countClaimsByStaffId(staffId: number): Promise { return await db.claim.count({ where: { staffId } }); }, };