Add Docker support and notification URL enhancement
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
import prisma from "@/lib/prisma"
|
||||
import { revalidatePath } from "next/cache"
|
||||
import { headers } from "next/headers"
|
||||
import { sendNotification } from "@/lib/notifications"
|
||||
|
||||
export async function createBooking(planId: string, date: Date, name: string, type: "SITTER" | "OWNER_HOME" = "SITTER") {
|
||||
@@ -31,10 +32,14 @@ export async function createBooking(planId: string, date: Date, name: string, ty
|
||||
})
|
||||
|
||||
if (plan?.webhookUrl && plan.notifyAll) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/dashboard/${planId}`
|
||||
|
||||
const dateStr = date.toLocaleDateString()
|
||||
const message = type === "OWNER_HOME"
|
||||
? `🏠 OWNER HOME: Marked for ${dateStr}.`
|
||||
: `✅ NEW BOOKING: ${name} is sitting on ${dateStr}.`
|
||||
? `🏠 OWNER HOME: Marked for ${dateStr}.\nPlan: ${planUrl}`
|
||||
: `✅ NEW BOOKING: ${name} is sitting on ${dateStr}.\nPlan: ${planUrl}`
|
||||
await sendNotification(plan.webhookUrl, message)
|
||||
}
|
||||
|
||||
@@ -54,8 +59,12 @@ export async function deleteBooking(bookingId: number, planId: string) {
|
||||
})
|
||||
|
||||
if (booking.plan.webhookUrl) {
|
||||
const host = (await headers()).get("host")
|
||||
const protocol = host?.includes("localhost") ? "http" : "https"
|
||||
const planUrl = `${protocol}://${host}/dashboard/${planId}`
|
||||
|
||||
const dateStr = booking.date.toLocaleDateString()
|
||||
await sendNotification(booking.plan.webhookUrl, `🚨 CANCELLATION: ${booking.sitterName} removed their booking for ${dateStr}.`)
|
||||
await sendNotification(booking.plan.webhookUrl, `🚨 CANCELLATION: ${booking.sitterName} removed their booking for ${dateStr}.\nPlan: ${planUrl}`)
|
||||
}
|
||||
|
||||
revalidatePath(`/dashboard/${planId}`)
|
||||
|
||||
Reference in New Issue
Block a user