Compare commits
18 Commits
amalia/02-
...
amalia/14-
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b48fe56fd | |||
| 18023807cd | |||
| bd1758ce32 | |||
| 878b3aa278 | |||
| f02ffc58ad | |||
| 3d5149cbba | |||
| 411037ec4a | |||
| 66ba6dfa91 | |||
| 389f115923 | |||
| 2251818908 | |||
| b625150eb5 | |||
| bae91db60a | |||
| 150151e823 | |||
| d1a591a63a | |||
| 7e80a1f311 | |||
| b648735b06 | |||
| a3d8bf1e92 | |||
| c2c52ed5fd |
@@ -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
|
||||
}
|
||||
|
||||
@@ -74,6 +74,9 @@ export async function GET(request: Request) {
|
||||
DiscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where:{
|
||||
isActive:true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
img: true
|
||||
}
|
||||
}
|
||||
},
|
||||
where: {
|
||||
isActive:true
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
@@ -64,6 +64,9 @@ export async function GET(request: Request) {
|
||||
DivisionDisscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where:{
|
||||
isActive:true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { DivisionProject } from './../../../../node_modules/.prisma/client/index.d';
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserByCookies } from "@/module/auth";
|
||||
import _, { ceil } from "lodash";
|
||||
@@ -36,22 +35,28 @@ export async function GET(request: Request) {
|
||||
isActive: true,
|
||||
}
|
||||
}
|
||||
} else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idGroup: idGroup
|
||||
}
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idGroup: idGroup,
|
||||
ProjectMember: {
|
||||
some: {
|
||||
idUser: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// idGroup: idGroup
|
||||
// }
|
||||
// } else {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// idGroup: idGroup,
|
||||
// ProjectMember: {
|
||||
// some: {
|
||||
// idUser: user.id
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
const data = await prisma.project.findMany({
|
||||
skip: 0,
|
||||
@@ -74,7 +79,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc"
|
||||
updatedAt: "desc"
|
||||
}
|
||||
})
|
||||
|
||||
@@ -96,22 +101,28 @@ export async function GET(request: Request) {
|
||||
isActive: true,
|
||||
}
|
||||
}
|
||||
} else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idGroup: idGroup
|
||||
}
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
idGroup: idGroup,
|
||||
DivisionMember: {
|
||||
some: {
|
||||
idUser: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// idGroup: idGroup
|
||||
// }
|
||||
// } else {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// idGroup: idGroup,
|
||||
// DivisionMember: {
|
||||
// some: {
|
||||
// idUser: user.id
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
const data = await prisma.division.findMany({
|
||||
where: kondisi,
|
||||
@@ -134,7 +145,9 @@ export async function GET(request: Request) {
|
||||
jumlah: v.DivisionProject.length,
|
||||
}))
|
||||
|
||||
allData = _.orderBy(format, 'jumlah', 'desc').slice(0, 5)
|
||||
const filter = format.filter((v: any) => v.jumlah > 0)
|
||||
|
||||
allData = _.orderBy(filter, 'jumlah', 'desc').slice(0, 5)
|
||||
|
||||
} else if (kategori == "progress") {
|
||||
let kondisi
|
||||
@@ -143,37 +156,50 @@ export async function GET(request: Request) {
|
||||
if (roleUser == "supadmin" || roleUser == "developer") {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
Division: {
|
||||
idVillage: idVillage,
|
||||
Group: {
|
||||
isActive: true,
|
||||
idVillage: idVillage,
|
||||
Group: {
|
||||
isActive: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
Division: {
|
||||
isActive: true,
|
||||
idGroup: idGroup
|
||||
}
|
||||
}
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// Division: {
|
||||
// isActive: true,
|
||||
// idVillage: idVillage,
|
||||
// Group: {
|
||||
// isActive: true,
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
Division: {
|
||||
isActive: true,
|
||||
DivisionMember: {
|
||||
some: {
|
||||
idUser: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
idGroup: idGroup
|
||||
}
|
||||
}
|
||||
// else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// Division: {
|
||||
// isActive: true,
|
||||
// idGroup: idGroup
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// Division: {
|
||||
// isActive: true,
|
||||
// DivisionMember: {
|
||||
// some: {
|
||||
// idUser: user.id
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
const data = await prisma.divisionProject.groupBy({
|
||||
const data = await prisma.project.groupBy({
|
||||
where: kondisi,
|
||||
by: ["status"],
|
||||
_count: true
|
||||
@@ -218,7 +244,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
category: 'FILE',
|
||||
@@ -227,20 +253,30 @@ export async function GET(request: Request) {
|
||||
idGroup: idGroup
|
||||
}
|
||||
}
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
category: 'FILE',
|
||||
Division: {
|
||||
isActive: true,
|
||||
DivisionMember: {
|
||||
some: {
|
||||
idUser: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// category: 'FILE',
|
||||
// Division: {
|
||||
// isActive: true,
|
||||
// idGroup: idGroup
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// category: 'FILE',
|
||||
// Division: {
|
||||
// isActive: true,
|
||||
// DivisionMember: {
|
||||
// some: {
|
||||
// idUser: user.id
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
const data = await prisma.divisionDocumentFolderFile.findMany({
|
||||
where: kondisi,
|
||||
@@ -377,7 +413,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
status: 1,
|
||||
@@ -386,20 +422,30 @@ export async function GET(request: Request) {
|
||||
isActive: true
|
||||
}
|
||||
}
|
||||
} else {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
status: 1,
|
||||
Division: {
|
||||
isActive: true,
|
||||
DivisionMember: {
|
||||
some: {
|
||||
idUser: user.id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if (roleUser == "admin" || roleUser == "cosupadmin") {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// status: 1,
|
||||
// Division: {
|
||||
// idGroup: idGroup,
|
||||
// isActive: true
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// kondisi = {
|
||||
// isActive: true,
|
||||
// status: 1,
|
||||
// Division: {
|
||||
// isActive: true,
|
||||
// DivisionMember: {
|
||||
// some: {
|
||||
// idUser: user.id
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
const data = await prisma.divisionDisscussion.findMany({
|
||||
skip: 0,
|
||||
|
||||
@@ -255,15 +255,20 @@ export async function POST(request: Request) {
|
||||
|
||||
|
||||
const dataNotifFilter = dataNotif.filter((v: any) => v.idUserTo != undefined && v.idUserTo != null && v.idUserTo != "" && v.idUserTo != userId)
|
||||
const dataNotifFilterUnique = dataNotifFilter
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t: any) => t.idUserTo == v.idUserTo)
|
||||
)
|
||||
|
||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||
|
||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Pengumuman Baru', body: title } })
|
||||
const insertNotif = await prisma.notifications.createMany({
|
||||
data: dataNotifFilter
|
||||
data: dataNotifFilterUnique
|
||||
})
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())].filter((v: any) => v != undefined && v != null && v != "");
|
||||
|
||||
await sendFCMNotificationMany({
|
||||
token: tokenUnique,
|
||||
title: "Pengumuman Baru",
|
||||
|
||||
@@ -37,6 +37,29 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const dataDiscussion = await prisma.discussion.findUnique({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
select: {
|
||||
createdBy: true,
|
||||
User: {
|
||||
select: {
|
||||
Subscribe: {
|
||||
select: {
|
||||
subscription: true
|
||||
}
|
||||
},
|
||||
TokenDeviceUser: {
|
||||
select: {
|
||||
token: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const member = await prisma.discussionMember.findMany({
|
||||
where: {
|
||||
idDiscussion: id,
|
||||
@@ -70,7 +93,10 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const memberFilter = member.filter((v: any) => v.idUser != userMobile.id)
|
||||
const memberFilter = [...member, { idUser: dataDiscussion?.createdBy, User: dataDiscussion?.User }].filter((v: any) => v.idUser != userMobile.id)
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t) => t.idUser === v.idUser)
|
||||
);
|
||||
|
||||
const dataFCM = memberFilter.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||
@@ -121,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: {
|
||||
@@ -79,8 +81,9 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -210,9 +213,13 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
dataNotif.filter((v: any) => v.idUserTo != undefined && v.idUserTo != null && v.idUserTo != "" && v.idUserTo != userId)
|
||||
const dataNotifUnique = dataNotif
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t: any) => t.idUserTo == v.idUserTo)
|
||||
)
|
||||
|
||||
const insertNotif = await prisma.notifications.createMany({
|
||||
data: dataNotif
|
||||
data: dataNotifUnique
|
||||
})
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())].filter((v: any) => v != undefined && v != null && v != "");
|
||||
|
||||
@@ -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
|
||||
@@ -50,6 +50,21 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
},
|
||||
select: {
|
||||
idDivision: true,
|
||||
createdBy: true,
|
||||
User: {
|
||||
select: {
|
||||
Subscribe: {
|
||||
select: {
|
||||
subscription: true
|
||||
}
|
||||
},
|
||||
TokenDeviceUser: {
|
||||
select: {
|
||||
token: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -86,7 +101,10 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const memberFilter = member.filter((v: any) => v.idUser != userMobile.id)
|
||||
const memberFilter = [...member, { idUser: dataDivision?.createdBy, User: dataDivision?.User }].filter((v: any) => v.idUser != userMobile.id)
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t) => t.idUser === v.idUser)
|
||||
);
|
||||
|
||||
const dataFCM = memberFilter.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||
@@ -138,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,12 +38,16 @@ 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,
|
||||
@@ -54,10 +58,12 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
})
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -263,12 +266,16 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const dataNotifFilter = dataNotif.filter((v: any) => v.idUserTo != undefined && v.idUserTo != null && v.idUserTo != "" && v.idUserTo != userId)
|
||||
const dataNotifFilterUnique = dataNotifFilter
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t: any) => t.idUserTo == v.idUserTo)
|
||||
)
|
||||
|
||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||
|
||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { body: deskripsiNotif, title: 'Diskusi Baru' } })
|
||||
const insertNotif = await prisma.notifications.createMany({
|
||||
data: dataNotifFilter
|
||||
data: dataNotifFilterUnique
|
||||
})
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())].filter((v: any) => v != undefined && v != null && v != "");
|
||||
|
||||
@@ -314,12 +314,16 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const dataNotifFilter = dataNotif.filter((v: any) => v.idUserTo != undefined && v.idUserTo != null && v.idUserTo != "" && v.idUserTo != userId)
|
||||
const dataNotifFilterUnique = dataNotifFilter
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t: any) => t.idUserTo == v.idUserTo)
|
||||
)
|
||||
|
||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||
|
||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Divisi Baru', body: `Divisi ${sent.data.name} telah dibuat. Silakan periksa detailnya.` } })
|
||||
const insertNotif = await prisma.notifications.createMany({
|
||||
data: dataNotifFilter
|
||||
data: dataNotifFilterUnique
|
||||
})
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())].filter((v: any) => v != undefined && v != null && v != "");
|
||||
@@ -338,4 +342,45 @@ export async function POST(request: Request) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal menambahkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// CEK DATA DIVISI (NAME DI DESA DAN GROUP YG SAMA)
|
||||
export async function PUT(request: Request) {
|
||||
try {
|
||||
|
||||
const sent = (await request.json())
|
||||
const user = sent.user
|
||||
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 });
|
||||
}
|
||||
|
||||
let fixGroup
|
||||
if (sent.data.idGroup == "null" || sent.data.idGroup == undefined || sent.data.idGroup == "") {
|
||||
fixGroup = userMobile.idGroup
|
||||
} else {
|
||||
fixGroup = sent.data.idGroup
|
||||
}
|
||||
|
||||
const checkData = await prisma.division.count({
|
||||
where: {
|
||||
name: {
|
||||
equals: sent.data.name,
|
||||
mode: "insensitive"
|
||||
},
|
||||
idGroup: fixGroup,
|
||||
idVillage: String(userMobile.idVillage)
|
||||
}
|
||||
})
|
||||
|
||||
if (checkData > 0) {
|
||||
return NextResponse.json({ success: true, message: "Divisi dengan nama ini sudah ada", available: false }, { status: 200 });
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil cek data divisi", available: true }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal menambahkan divisi, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
}
|
||||
};
|
||||
@@ -81,7 +81,7 @@ export async function GET(request: Request) {
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc"
|
||||
updatedAt: "desc"
|
||||
}
|
||||
})
|
||||
|
||||
@@ -425,19 +425,19 @@ export async function GET(request: Request) {
|
||||
isActive: true,
|
||||
status: 1,
|
||||
idVillage: idVillage
|
||||
},
|
||||
}
|
||||
|
||||
kondisi = {
|
||||
kondisi = {
|
||||
isActive: true,
|
||||
status: 1,
|
||||
Division: {
|
||||
isActive: true,
|
||||
status: 1,
|
||||
Division: {
|
||||
idVillage: idVillage,
|
||||
Group: {
|
||||
isActive: true,
|
||||
idVillage: idVillage,
|
||||
Group: {
|
||||
isActive: true,
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
kondisiUmum = {
|
||||
isActive: true,
|
||||
|
||||
@@ -71,7 +71,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
createdAt: true
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc'
|
||||
dateStart: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -385,11 +385,15 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const dataNotifFilter = dataNotif.filter((item) => item.idUserTo != undefined && item.idUserTo != null && item.idUserTo != "" && item.idUserTo != userId)
|
||||
const dataNotifFilterUnique = dataNotifFilter
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t: any) => t.idUserTo == v.idUserTo)
|
||||
)
|
||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||
|
||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { title: 'Kegiatan Baru', body: title } })
|
||||
const insertNotif = await prisma.notifications.createMany({
|
||||
data: dataNotifFilter
|
||||
data: dataNotifFilterUnique
|
||||
})
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())].filter((v: any) => v != undefined && v != null && v != "");
|
||||
|
||||
@@ -76,7 +76,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
dateEnd: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc'
|
||||
dateStart: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -356,11 +356,15 @@ export async function POST(request: Request) {
|
||||
}
|
||||
|
||||
const dataNotifFilter = dataNotif.filter((v: any) => v.idUserTo != undefined && v.idUserTo != null && v.idUserTo != "" && v.idUserTo != userId)
|
||||
const dataNotifFilterUnique = dataNotifFilter
|
||||
.filter((v: any, index: number, self: any[]) =>
|
||||
index === self.findIndex((t: any) => t.idUserTo == v.idUserTo)
|
||||
)
|
||||
const pushNotif = dataPush.filter((item) => item.subscription != undefined)
|
||||
|
||||
const sendWebPush = await funSendWebPush({ sub: pushNotif, message: { body: title, title: 'Tugas Divisi Baru' } })
|
||||
const insertNotif = await prisma.notifications.createMany({
|
||||
data: dataNotifFilter
|
||||
data: dataNotifFilterUnique
|
||||
})
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())].filter((v: any) => v != undefined && v != null && v != "");
|
||||
|
||||
@@ -68,7 +68,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
createdAt: true
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc'
|
||||
dateStart: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
@@ -78,8 +78,8 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
dateEnd: moment(v.dateEnd).format("DD-MM-YYYY"),
|
||||
createdAt: moment(v.createdAt).format("DD-MM-YYYY HH:mm"),
|
||||
}))
|
||||
const dataFix = _.orderBy(formatData, 'createdAt', 'asc')
|
||||
allData = dataFix
|
||||
// const dataFix = _.orderBy(formatData, 'createdAt', 'asc')
|
||||
allData = formatData
|
||||
|
||||
} else if (kategori == "file") {
|
||||
const dataFile = await prisma.projectFile.findMany({
|
||||
|
||||
@@ -75,7 +75,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
dateEnd: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'asc'
|
||||
dateStart: 'asc'
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
return NextResponse.json({ success: true, version: "2.0.4", 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) {
|
||||
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