upd: edit divisi

No Issues
This commit is contained in:
amel
2024-08-12 17:44:57 +08:00
parent 9a000d3387
commit 3ba348ad38
8 changed files with 275 additions and 63 deletions

View File

@@ -62,4 +62,55 @@ export async function GET(request: Request, context: { params: { id: string } })
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}
// EDIT DATA DIVISI
export async function PUT(request: Request, context: { params: { id: string } }) {
try {
const user = await funGetUserByCookies()
if (user.id == undefined) {
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
}
const { id } = context.params;
const { name, desc } = (await request.json());
const data = await prisma.division.count({
where: {
id: id,
},
});
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Edit divisi gagal, data tidak ditemukan",
},
{ status: 404 }
);
}
const update = await prisma.division.update({
where: {
id: id,
},
data: {
name: name,
desc: desc
},
});
return NextResponse.json(
{
success: true,
message: "Divisi berhasil diedit",
},
{ status: 200 }
);
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
}