feat: allow sitters to mark jobs as completed with notification
This commit is contained in:
@@ -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}`)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user