upd: api mobile

deskripsi:
- api list diskusi divisi
- detail diskusi divisi
- edit diskusi divisi
- status diskusi divisi
- arsip diskusi divisi
- tambah diskusi divisi
- check anggota divisi
- check admin divisi

No Issues
This commit is contained in:
amel
2025-05-22 17:21:58 +08:00
parent 8c9a09ddc1
commit 1af0ecb7af
4 changed files with 565 additions and 0 deletions

View File

@@ -0,0 +1,54 @@
import { prisma } from "@/module/_global";
import { funGetUserById } from "@/module/auth";
import { createLogUserMobile } from "@/module/user";
import { NextResponse } from "next/server";
// CREATE COMENT BY ID KOMENTAR
export async function POST(request: Request, context: { params: { id: string } }) {
try {
const { id } = context.params
const { comment, user } = (await request.json());
const userMobile = await funGetUserById({ id: String(user) })
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
return NextResponse.json({ success: false, message: "User tidak ditemukan" }, { status: 200 });
}
const cek = await prisma.divisionDisscussion.count({
where: {
id: id
}
})
if (cek == 0) {
return NextResponse.json(
{
success: false,
message: "Tambah komentar gagal, data tidak ditemukan",
},
{ status: 200 }
);
}
const data = await prisma.divisionDisscussionComment.create({
data: {
comment: comment,
idDisscussion: id,
createdBy: userMobile.id
},
select: {
id: true
}
})
// create log user
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi', table: 'divisionDisscussionComment', data: data.id, user: userMobile.id })
return NextResponse.json({ success: true, message: "Berhasil menambah komentar" }, { status: 200 });
} catch (error) {
console.error(error);
return NextResponse.json({ success: false, message: "Gagal menambah komentar, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
}
}