feat : update get user announcement

This commit is contained in:
lukman
2024-08-08 17:34:14 +08:00
parent 7f18f1cb78
commit 43035bc14a
5 changed files with 87 additions and 0 deletions

39
src/app/api/coba/route.ts Normal file
View File

@@ -0,0 +1,39 @@
import { prisma } from "@/module/_global";
import { funGetUserByCookies } from "@/module/auth";
import { revalidatePath, revalidateTag } from "next/cache";
import { NextResponse } from "next/server";
export const dynamic = 'force-dynamic'
export const revalidate = true
export async function GET(request: Request) {
try {
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const villaId = user.idVillage
const data = await prisma.group.findMany({
where: {
isActive: true,
idVillage: String(villaId)
},
select: {
id: true,
name: true,
Division: {
select: {
id: true,
name: true
}
}
}
});
return NextResponse.json({ success: true, message: "Berhasil mendapatkan grup", data, }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan grup, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}