Compare commits
6 Commits
amalia/08-
...
amalia/14-
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b48fe56fd | |||
| 18023807cd | |||
| bd1758ce32 | |||
| 878b3aa278 | |||
| f02ffc58ad | |||
| 3d5149cbba |
@@ -420,6 +420,7 @@ model DivisionDisscussionComment {
|
|||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
User User @relation(fields: [createdBy], references: [id])
|
User User @relation(fields: [createdBy], references: [id])
|
||||||
createdBy String
|
createdBy String
|
||||||
|
isEdited Boolean @default(false)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
@@ -615,6 +616,7 @@ model DiscussionComment {
|
|||||||
idUser String
|
idUser String
|
||||||
comment String @db.Text
|
comment String @db.Text
|
||||||
isActive Boolean @default(true)
|
isActive Boolean @default(true)
|
||||||
|
isEdited Boolean @default(false)
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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)" })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -68,6 +68,8 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
id: true,
|
id: true,
|
||||||
comment: true,
|
comment: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
isEdited: true,
|
||||||
idUser: true,
|
idUser: true,
|
||||||
User: {
|
User: {
|
||||||
select: {
|
select: {
|
||||||
@@ -79,8 +81,9 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
})
|
})
|
||||||
|
|
||||||
dataFix = data.map((v: any) => ({
|
dataFix = data.map((v: any) => ({
|
||||||
..._.omit(v, ["createdAt", "User",]),
|
..._.omit(v, ["createdAt", "User", "updatedAt"]),
|
||||||
createdAt: countTime(v.createdAt),
|
createdAt: countTime(v.createdAt),
|
||||||
|
updatedAt: moment(v.updatedAt).format("ll"),
|
||||||
username: v.User.name,
|
username: v.User.name,
|
||||||
img: v.User.img
|
img: v.User.img
|
||||||
}))
|
}))
|
||||||
|
|||||||
@@ -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,12 +38,16 @@ 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,
|
||||||
comment: true,
|
comment: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
|
updatedAt: true,
|
||||||
|
isEdited: true,
|
||||||
|
createdBy: true,
|
||||||
User: {
|
User: {
|
||||||
select: {
|
select: {
|
||||||
name: true,
|
name: true,
|
||||||
@@ -54,10 +58,12 @@ export async function GET(request: Request, context: { params: { id: string } })
|
|||||||
})
|
})
|
||||||
|
|
||||||
const omitMember = data.map((v: any) => ({
|
const omitMember = data.map((v: any) => ({
|
||||||
..._.omit(v, ["User", "createdAt"]),
|
..._.omit(v, ["User", "createdBy", "createdAt", "updatedAt"]),
|
||||||
|
idUser: v.createdBy,
|
||||||
username: v.User.name,
|
username: v.User.name,
|
||||||
img: v.User.img,
|
img: v.User.img,
|
||||||
createdAt: countTime(v.createdAt),
|
createdAt: countTime(v.createdAt),
|
||||||
|
updatedAt: moment(v.updatedAt).format("ll")
|
||||||
}))
|
}))
|
||||||
|
|
||||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan komentar", data: omitMember }, { status: 200 });
|
return NextResponse.json({ success: true, message: "Berhasil mendapatkan komentar", data: omitMember }, { status: 200 });
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export function countTime(date: Date) {
|
|||||||
const seconds = totalSeconds;
|
const seconds = totalSeconds;
|
||||||
|
|
||||||
if (days > 0) {
|
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) {
|
} else if (hours > 0) {
|
||||||
return `${hours} jam`
|
return `${hours} jam`
|
||||||
} else if (minutes > 0) {
|
} else if (minutes > 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user