feat(job-completion): add message and photo upload to job completion
This commit is contained in:
@@ -83,7 +83,7 @@ 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") {
|
||||
export async function completeBooking(bookingId: number, planId: string, lang: string = "en", message?: string, imageUrl?: string) {
|
||||
const dict = await getDictionary(lang as any)
|
||||
|
||||
const booking = await prisma.booking.findUnique({
|
||||
@@ -95,7 +95,11 @@ export async function completeBooking(bookingId: number, planId: string, lang: s
|
||||
|
||||
await prisma.booking.update({
|
||||
where: { id: bookingId },
|
||||
data: { completedAt: new Date() }
|
||||
data: {
|
||||
completedAt: new Date(),
|
||||
completionMessage: message,
|
||||
completionImage: imageUrl
|
||||
}
|
||||
})
|
||||
|
||||
if (booking.plan.notifyAll) {
|
||||
@@ -104,12 +108,19 @@ export async function completeBooking(bookingId: number, planId: string, lang: s
|
||||
const planUrl = `${protocol}://${host}/${lang}/dashboard/${planId}`
|
||||
|
||||
const dateStr = booking.date.toLocaleDateString(lang)
|
||||
const message = dict.notifications.completed
|
||||
let notificationMessage = dict.notifications.completed
|
||||
.replace("{name}", booking.sitterName || "Someone")
|
||||
.replace("{date}", dateStr)
|
||||
.replace("{url}", planUrl)
|
||||
|
||||
await sendPlanNotification(planId, message, booking.plan.webhookUrl)
|
||||
if (message) {
|
||||
notificationMessage += `\n"${message}"`
|
||||
}
|
||||
|
||||
// We need to pass the full URL for the image
|
||||
const fullImageUrl = imageUrl ? `${protocol}://${host}${imageUrl}` : undefined
|
||||
|
||||
await sendPlanNotification(planId, notificationMessage, booking.plan.webhookUrl, fullImageUrl)
|
||||
}
|
||||
|
||||
revalidatePath(`/${lang}/dashboard/${planId}`)
|
||||
|
||||
Reference in New Issue
Block a user