Compare commits
9 Commits
amalia/08-
...
amalia/15-
| Author | SHA1 | Date | |
|---|---|---|---|
| 1b8bfebf4f | |||
| 10b9037fda | |||
| 4a4be31921 | |||
| 9b48fe56fd | |||
| 18023807cd | |||
| bd1758ce32 | |||
| 878b3aa278 | |||
| f02ffc58ad | |||
| 3d5149cbba |
@@ -420,6 +420,7 @@ model DivisionDisscussionComment {
|
||||
isActive Boolean @default(true)
|
||||
User User @relation(fields: [createdBy], references: [id])
|
||||
createdBy String
|
||||
isEdited Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
@@ -615,6 +616,7 @@ model DiscussionComment {
|
||||
idUser String
|
||||
comment String @db.Text
|
||||
isActive Boolean @default(true)
|
||||
isEdited Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@ import { funGetUserByCookies } from "@/module/auth";
|
||||
import { createLogUser } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
import "moment/locale/id";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
|
||||
// GET ONE DETAIL DISKUSI UMUM
|
||||
@@ -75,6 +75,9 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
img: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -74,6 +74,9 @@ export async function GET(request: Request) {
|
||||
DiscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where:{
|
||||
isActive:true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,12 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
img: true
|
||||
}
|
||||
}
|
||||
},
|
||||
where: {
|
||||
isActive:true
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc"
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ export async function GET(request: Request) {
|
||||
DivisionDisscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where:{
|
||||
isActive:true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,4 +147,90 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
console.error(error)
|
||||
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)" })
|
||||
}
|
||||
}
|
||||
@@ -68,6 +68,8 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
id: true,
|
||||
comment: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
isEdited: true,
|
||||
idUser: true,
|
||||
User: {
|
||||
select: {
|
||||
@@ -75,12 +77,16 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
img: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
dataFix = data.map((v: any) => ({
|
||||
..._.omit(v, ["createdAt", "User",]),
|
||||
..._.omit(v, ["createdAt", "User", "updatedAt"]),
|
||||
createdAt: countTime(v.createdAt),
|
||||
updatedAt: moment(v.updatedAt).format("ll"),
|
||||
username: v.User.name,
|
||||
img: v.User.img
|
||||
}))
|
||||
|
||||
@@ -75,6 +75,9 @@ export async function GET(request: Request) {
|
||||
DiscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where: {
|
||||
isActive: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import { sendFCMNotificationMany } from "../../../../../../../xsendMany";
|
||||
|
||||
// CREATE COMENT BY ID KOMENTAR
|
||||
// CREATE COMENT
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
@@ -156,4 +156,103 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
console.error(error);
|
||||
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,26 +38,35 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
if (cat == "comment") {
|
||||
const data = await prisma.divisionDisscussionComment.findMany({
|
||||
where: {
|
||||
idDisscussion: id
|
||||
idDisscussion: id,
|
||||
isActive: true
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
comment: true,
|
||||
createdAt: true,
|
||||
updatedAt: true,
|
||||
isEdited: true,
|
||||
createdBy: true,
|
||||
User: {
|
||||
select: {
|
||||
name: true,
|
||||
img: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "asc"
|
||||
}
|
||||
})
|
||||
|
||||
const omitMember = data.map((v: any) => ({
|
||||
..._.omit(v, ["User", "createdAt"]),
|
||||
..._.omit(v, ["User", "createdBy", "createdAt", "updatedAt"]),
|
||||
idUser: v.createdBy,
|
||||
username: v.User.name,
|
||||
img: v.User.img,
|
||||
createdAt: countTime(v.createdAt),
|
||||
updatedAt: moment(v.updatedAt).format("ll")
|
||||
}))
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan komentar", data: omitMember }, { status: 200 });
|
||||
|
||||
@@ -67,6 +67,9 @@ export async function GET(request: Request) {
|
||||
DivisionDisscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where: {
|
||||
isActive: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
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.9", 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) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
@@ -18,7 +18,7 @@ export function countTime(date: Date) {
|
||||
const seconds = totalSeconds;
|
||||
|
||||
if (days > 0) {
|
||||
return moment(date).format("ll")
|
||||
return String(dateNow.getFullYear()) == moment(date).format("YYYY") ? moment(date).format("DD MMM") : moment(date).format("ll")
|
||||
} else if (hours > 0) {
|
||||
return `${hours} jam`
|
||||
} else if (minutes > 0) {
|
||||
|
||||
Reference in New Issue
Block a user