feat: allow sitters to mark jobs as completed with notification

This commit is contained in:
2026-01-12 23:16:23 +01:00
parent 3600ba665d
commit 22183a8d59
6 changed files with 93 additions and 19 deletions

View File

@@ -82,3 +82,35 @@ export async function deleteBooking(bookingId: number, planId: string, lang: str
revalidatePath(`/${lang}/dashboard/${planId}`)
}
export async function completeBooking(bookingId: number, planId: string, lang: string = "en") {
const dict = await getDictionary(lang as any)
const booking = await prisma.booking.findUnique({
where: { id: bookingId },
include: { plan: true }
})
if (!booking) return
await prisma.booking.update({
where: { id: bookingId },
data: { completedAt: new Date() }
})
if (booking.plan.webhookUrl) {
const host = (await headers()).get("host")
const protocol = host?.includes("localhost") ? "http" : "https"
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
const dateStr = booking.date.toLocaleDateString(lang)
const message = dict.notifications.completed
.replace("{name}", booking.sitterName || "Someone")
.replace("{date}", dateStr)
.replace("{url}", planUrl)
await sendNotification(booking.plan.webhookUrl, message)
}
revalidatePath(`/${lang}/dashboard/${planId}`)
}