27 lines
976 B
TypeScript
27 lines
976 B
TypeScript
"use server"
|
|
|
|
import prisma from "@/lib/prisma"
|
|
import { revalidatePath } from "next/cache"
|
|
import { headers } from "next/headers"
|
|
import { sendNotification } from "@/lib/notifications"
|
|
|
|
export async function updatePlan(planId: string, data: { instructions?: string; webhookUrl?: string; notifyAll?: boolean }) {
|
|
const plan = await prisma.plan.update({
|
|
where: { id: planId },
|
|
data: {
|
|
instructions: data.instructions,
|
|
webhookUrl: data.webhookUrl,
|
|
notifyAll: data.notifyAll,
|
|
}
|
|
})
|
|
|
|
if (data.instructions && plan.webhookUrl && plan.notifyAll) {
|
|
const host = (await headers()).get("host")
|
|
const protocol = host?.includes("localhost") ? "http" : "https"
|
|
const planUrl = `${protocol}://${host}/dashboard/${planId}`
|
|
await sendNotification(plan.webhookUrl, `📝 UPDATED: Cat instructions have been modified.\nPlan: ${planUrl}`)
|
|
}
|
|
|
|
revalidatePath(`/dashboard/${planId}`)
|
|
}
|