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

@@ -207,7 +207,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
}
// MENGGANTIS STATUS ADMIN DIVISI
// MENGGANTI STATUS ADMIN DIVISI
export async function PUT(request: Request, context: { params: { id: string } }) {
try {
const user = await funGetUserByCookies()
@@ -255,4 +255,54 @@ export async function PUT(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 });
}
}
}
// TAMBAH ANGGOTA DIVISI
export async function POST(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 member = await request.json();
const idDivision = context.params.id;
console.log("amalia", member)
const data = await prisma.division.count({
where: {
id: idDivision,
isActive: true
},
});
if (data == 0) {
return NextResponse.json(
{
success: false,
message: "Tambah anggota divisi gagal, data tidak ditemukan",
},
{ status: 404 }
);
}
const dataMember = member.map((v: any) => ({
..._.omit(v, ["name"]),
idUser: v.idUser,
idDivision: idDivision,
}))
const insertMember = await prisma.divisionMember.createMany({
data: dataMember
})
return NextResponse.json({ success: true, message: "Berhasil menambahkan anggota divisi" }, { status: 200 });
} catch (error) {
console.log(error);
return NextResponse.json({ success: false, message: "Gagal menambahkan anggota divisi, coba lagi nanti", reason: (error as Error).message, }, { status: 500 });
}
};

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 });
}
}