|
| 1 | + |
| 2 | +'use server'; |
| 3 | + |
| 4 | +import prisma from '@/lib/db'; |
| 5 | +import { revalidatePath } from 'next/cache'; |
| 6 | +import { isAdmin } from '@/lib/auth'; |
| 7 | + |
| 8 | +// Leela Actions |
| 9 | +export async function saveLeela(data: any) { |
| 10 | + if (!await isAdmin()) throw new Error('Unauthorized'); |
| 11 | + const { id, ...rest } = data; |
| 12 | + if (id && id !== 'new') { |
| 13 | + await prisma.leela.update({ |
| 14 | + where: { id }, |
| 15 | + data: rest |
| 16 | + }); |
| 17 | + } else { |
| 18 | + await prisma.leela.create({ |
| 19 | + data: rest |
| 20 | + }); |
| 21 | + } |
| 22 | + revalidatePath('/leela'); |
| 23 | + revalidatePath('/admin/leela'); |
| 24 | +} |
| 25 | + |
| 26 | +export async function deleteLeela(id: string) { |
| 27 | + if (!await isAdmin()) throw new Error('Unauthorized'); |
| 28 | + await prisma.leela.delete({ where: { id } }); |
| 29 | + revalidatePath('/leela'); |
| 30 | + revalidatePath('/admin/leela'); |
| 31 | +} |
| 32 | + |
| 33 | +// Bodhakatha Actions |
| 34 | +export async function saveBodhakatha(data: any) { |
| 35 | + if (!await isAdmin()) throw new Error('Unauthorized'); |
| 36 | + const { id, ...rest } = data; |
| 37 | + if (id && id !== 'new') { |
| 38 | + await prisma.bodhakatha.update({ |
| 39 | + where: { id }, |
| 40 | + data: rest |
| 41 | + }); |
| 42 | + } else { |
| 43 | + await prisma.bodhakatha.create({ |
| 44 | + data: rest |
| 45 | + }); |
| 46 | + } |
| 47 | + revalidatePath('/bodhakatha'); |
| 48 | + revalidatePath('/admin/bodhakatha'); |
| 49 | +} |
| 50 | + |
| 51 | +export async function deleteBodhakatha(id: string) { |
| 52 | + if (!await isAdmin()) throw new Error('Unauthorized'); |
| 53 | + await prisma.bodhakatha.delete({ where: { id } }); |
| 54 | + revalidatePath('/bodhakatha'); |
| 55 | + revalidatePath('/admin/bodhakatha'); |
| 56 | +} |
| 57 | + |
| 58 | +// Glossary Actions |
| 59 | +export async function saveGlossary(data: any) { |
| 60 | + if (!await isAdmin()) throw new Error('Unauthorized'); |
| 61 | + const { id, ...rest } = data; |
| 62 | + if (id && id !== 'new') { |
| 63 | + await prisma.glossary.update({ |
| 64 | + where: { id }, |
| 65 | + data: rest |
| 66 | + }); |
| 67 | + } else { |
| 68 | + await prisma.glossary.create({ |
| 69 | + data: rest |
| 70 | + }); |
| 71 | + } |
| 72 | + revalidatePath('/glossary'); |
| 73 | + revalidatePath('/admin/glossary'); |
| 74 | +} |
| 75 | + |
| 76 | +export async function deleteGlossary(id: string) { |
| 77 | + if (!await isAdmin()) throw new Error('Unauthorized'); |
| 78 | + await prisma.glossary.delete({ where: { id } }); |
| 79 | + revalidatePath('/glossary'); |
| 80 | + revalidatePath('/admin/glossary'); |
| 81 | +} |
0 commit comments