upd: diskusi umum
Deskripsi: - api load get all diskusi umum - api send komentar dikusi umum - api mobile create diskusi umum, blm integrasi - api mobile aktifasi diskusi umum, blm integrasi No Issues
This commit is contained in:
46
src/app/api/mobile/discussion-general/[id]/comment/route.ts
Normal file
46
src/app/api/mobile/discussion-general/[id]/comment/route.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// KIRIM KOMENTAR DISKUSI UMUM
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
const { desc, 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: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const cek = await prisma.discussion.count({
|
||||
where: {
|
||||
id,
|
||||
isActive: true
|
||||
}
|
||||
})
|
||||
|
||||
if (cek == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal menambahkan komentar, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
|
||||
const data = await prisma.discussionComment.create({
|
||||
data: {
|
||||
comment: desc,
|
||||
idDiscussion: id,
|
||||
idUser: userMobile.id
|
||||
}
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi umum', table: 'discussionComment', 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 menambahkan komentar, coba lagi nanti (error: 500)" })
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user