feat : update discussion
Deskripsi - update discussion No issue
This commit is contained in:
50
src/app/api/discussion/[id]/route.ts
Normal file
50
src/app/api/discussion/[id]/route.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
// GET ONE DISCUSSION BY ID
|
||||
export async function GET(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 data = await prisma.divisionDisscussion.findUnique({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
desc: true,
|
||||
status: true,
|
||||
createdAt: true,
|
||||
User: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
},
|
||||
DivisionDisscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
comment: true,
|
||||
createdAt: true,
|
||||
User: {
|
||||
select: {
|
||||
name: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: data }, { 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 });
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
import "moment/locale/id";
|
||||
|
||||
|
||||
// GET ALL DISCUSSION DIVISION ACTIVE = TRUE
|
||||
@@ -14,7 +16,7 @@ export async function GET(request: Request) {
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const idDivision = searchParams.get("division");
|
||||
const title = searchParams.get('search');
|
||||
const name = searchParams.get('search');
|
||||
|
||||
|
||||
if (idDivision != "null" && idDivision != null && idDivision != undefined) {
|
||||
@@ -33,9 +35,11 @@ export async function GET(request: Request) {
|
||||
where: {
|
||||
isActive: true,
|
||||
idDivision: idDivision,
|
||||
title: {
|
||||
contains: (title == undefined || title == "null") ? "" : title,
|
||||
mode: "insensitive"
|
||||
User: {
|
||||
name: {
|
||||
contains: (name == undefined || name == "null") ? "" : name,
|
||||
mode: "insensitive"
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
@@ -63,9 +67,10 @@ export async function GET(request: Request) {
|
||||
|
||||
|
||||
const fixData = data.map((v: any) => ({
|
||||
..._.omit(v, ["User", "DivisionDisscussionComment"]),
|
||||
..._.omit(v, ["User", "DivisionDisscussionComment", "createdAt"]),
|
||||
user_name: v.User.name,
|
||||
total_komentar: v.DivisionDisscussionComment.length
|
||||
total_komentar: v.DivisionDisscussionComment.length,
|
||||
createdAt: moment(v.createdAt).format("LL")
|
||||
}))
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: fixData, }, { status: 200 });
|
||||
|
||||
@@ -269,8 +269,6 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
const member = await request.json();
|
||||
const idDivision = context.params.id;
|
||||
|
||||
console.log("amalia", member)
|
||||
|
||||
|
||||
const data = await prisma.division.count({
|
||||
where: {
|
||||
|
||||
@@ -55,6 +55,8 @@ export async function GET(request: Request) {
|
||||
jumlah_member: v.DivisionMember.length
|
||||
}))
|
||||
|
||||
console.log(allData)
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan divisi", data: allData, }, { status: 200 });
|
||||
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user