Merge pull request 'amalia/14-okt-25' (#63) from amalia/14-okt-25 into join
Reviewed-on: bip/sistem-desa-mandiri#63
This commit is contained in:
@@ -74,6 +74,9 @@ export async function GET(request: Request) {
|
|||||||
DiscussionComment: {
|
DiscussionComment: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
},
|
||||||
|
where:{
|
||||||
|
isActive:true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,9 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
img: true
|
img: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive:true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,6 +64,9 @@ export async function GET(request: Request) {
|
|||||||
DivisionDisscussionComment: {
|
DivisionDisscussionComment: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
},
|
||||||
|
where:{
|
||||||
|
isActive:true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,4 +147,90 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
console.error(error)
|
console.error(error)
|
||||||
return NextResponse.json({ success: false, message: "Gagal menambahkan komentar, coba lagi nanti (error: 500)" })
|
return NextResponse.json({ success: false, message: "Gagal menambahkan komentar, coba lagi nanti (error: 500)" })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EDIT KOMENTAR
|
||||||
|
export async function PUT(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.discussionComment.count({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cek == 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mengedit komentar, data tidak ditemukan" }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const data = await prisma.discussionComment.update({
|
||||||
|
where: {
|
||||||
|
id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
comment: desc,
|
||||||
|
isEdited: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengedit komentar pada diskusi umum', table: 'discussionComment', data: id, user: userMobile.id })
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mengedit komentar" }, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mengedit komentar, coba lagi nanti (error: 500)" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// HAPUS KOMENTAR
|
||||||
|
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||||
|
try {
|
||||||
|
const { id } = context.params
|
||||||
|
const { 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.discussionComment.count({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cek == 0) {
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mengedit komentar, data tidak ditemukan" }, { status: 200 });
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const data = await prisma.discussionComment.update({
|
||||||
|
where: {
|
||||||
|
id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isActive: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus komentar pada diskusi umum', table: 'discussionComment', data: id, user: userMobile.id })
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mengedit komentar" }, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error)
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal mengedit komentar, coba lagi nanti (error: 500)" })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -75,6 +75,9 @@ export async function GET(request: Request) {
|
|||||||
DiscussionComment: {
|
DiscussionComment: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import _ from "lodash";
|
|||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
import { sendFCMNotificationMany } from "../../../../../../../xsendMany";
|
import { sendFCMNotificationMany } from "../../../../../../../xsendMany";
|
||||||
|
|
||||||
// CREATE COMENT BY ID KOMENTAR
|
// CREATE COMENT
|
||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||||
try {
|
try {
|
||||||
const { id } = context.params
|
const { id } = context.params
|
||||||
@@ -156,4 +156,103 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
console.error(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 });
|
return NextResponse.json({ success: false, message: "Gagal menambah komentar, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// EDIT KOMENTAR
|
||||||
|
export async function PUT(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.divisionDisscussionComment.count({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cek == 0) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Edit komentar gagal, data tidak ditemukan",
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.divisionDisscussionComment.update({
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
comment: comment,
|
||||||
|
isEdited: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengedit komentar pada diskusi divisi', table: 'divisionDisscussionComment', data: id, user: userMobile.id })
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil mengedit 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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// HAPUS KOMENTAR
|
||||||
|
export async function DELETE(request: Request, context: { params: { id: string } }) {
|
||||||
|
try {
|
||||||
|
const { id } = context.params
|
||||||
|
const { 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.divisionDisscussionComment.count({
|
||||||
|
where: {
|
||||||
|
id,
|
||||||
|
isActive: true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if (cek == 0) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{
|
||||||
|
success: false,
|
||||||
|
message: "Hapus komentar gagal, data tidak ditemukan",
|
||||||
|
},
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const data = await prisma.divisionDisscussionComment.update({
|
||||||
|
where: {
|
||||||
|
id: id
|
||||||
|
},
|
||||||
|
data: {
|
||||||
|
isActive: false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
// create log user
|
||||||
|
const log = await createLogUserMobile({ act: 'DELETE', desc: 'User menghapus komentar pada diskusi divisi', table: 'divisionDisscussionComment', data: id, user: userMobile.id })
|
||||||
|
|
||||||
|
return NextResponse.json({ success: true, message: "Berhasil menghapus komentar" }, { status: 200 });
|
||||||
|
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
return NextResponse.json({ success: false, message: "Gagal menghapus komentar, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,8 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
if (cat == "comment") {
|
if (cat == "comment") {
|
||||||
const data = await prisma.divisionDisscussionComment.findMany({
|
const data = await prisma.divisionDisscussionComment.findMany({
|
||||||
where: {
|
where: {
|
||||||
idDisscussion: id
|
idDisscussion: id,
|
||||||
|
isActive: true
|
||||||
},
|
},
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
|||||||
@@ -67,6 +67,9 @@ export async function GET(request: Request) {
|
|||||||
DivisionDisscussionComment: {
|
DivisionDisscussionComment: {
|
||||||
select: {
|
select: {
|
||||||
id: true,
|
id: true,
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
isActive: true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
return NextResponse.json({ success: true, version: "2.0.7", tahap: "beta", update: "-api mobile; -login tanpa otp (mobile app); -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi; -api jenna ai; -privacy policy" }, { status: 200 });
|
return NextResponse.json({ success: true, version: "2.0.8", tahap: "beta", update: "-api mobile; -login tanpa otp (mobile app); -tambah laporan pada project dan tugas divisi; -tambah upload link pada project dan tugas divisi; -tambah detail tanggal dan jam pada project dan tugas divisi; -api jenna ai; -privacy policy" }, { status: 200 });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
Reference in New Issue
Block a user