Compare commits
28 Commits
amalia/02-
...
amalia/15-
| Author | SHA1 | Date | |
|---|---|---|---|
| 968202e34b | |||
| 0ce94e0e2b | |||
| 9f3acf306e | |||
| 3d2a35446c | |||
| 3ab2566a89 | |||
| 9573c1472a | |||
| ed2c9495c3 | |||
| 1b8bfebf4f | |||
| 10b9037fda | |||
| 4a4be31921 | |||
| 9b48fe56fd | |||
| 18023807cd | |||
| bd1758ce32 | |||
| 878b3aa278 | |||
| f02ffc58ad | |||
| 3d5149cbba | |||
| 411037ec4a | |||
| 66ba6dfa91 | |||
| 389f115923 | |||
| 2251818908 | |||
| b625150eb5 | |||
| bae91db60a | |||
| 150151e823 | |||
| d1a591a63a | |||
| 7e80a1f311 | |||
| b648735b06 | |||
| a3d8bf1e92 | |||
| c2c52ed5fd |
@@ -168,6 +168,7 @@ model Announcement {
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
AnnouncementMember AnnouncementMember[]
|
||||
AnnouncementFile AnnouncementFile[]
|
||||
}
|
||||
|
||||
model AnnouncementMember {
|
||||
@@ -183,6 +184,18 @@ model AnnouncementMember {
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model AnnouncementFile {
|
||||
id String @id @default(cuid())
|
||||
Announcement Announcement @relation(fields: [idAnnouncement], references: [id])
|
||||
idAnnouncement String
|
||||
name String
|
||||
extension String
|
||||
idStorage String?
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model Project {
|
||||
id String @id @default(cuid())
|
||||
Village Village @relation(fields: [idVillage], references: [id])
|
||||
@@ -420,6 +433,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
|
||||
}
|
||||
@@ -594,6 +608,7 @@ model Discussion {
|
||||
updatedAt DateTime @updatedAt
|
||||
DiscussionMember DiscussionMember[]
|
||||
DiscussionComment DiscussionComment[]
|
||||
DiscussionFile DiscussionFile[]
|
||||
}
|
||||
|
||||
model DiscussionMember {
|
||||
@@ -615,6 +630,19 @@ model DiscussionComment {
|
||||
idUser String
|
||||
comment String @db.Text
|
||||
isActive Boolean @default(true)
|
||||
isEdited Boolean @default(false)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
}
|
||||
|
||||
model DiscussionFile {
|
||||
id String @id @default(cuid())
|
||||
Discussion Discussion @relation(fields: [idDiscussion], references: [id])
|
||||
idDiscussion String
|
||||
name String
|
||||
extension String
|
||||
idStorage String?
|
||||
isActive Boolean @default(true)
|
||||
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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
@@ -20,6 +20,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
const data = await prisma.announcement.count({
|
||||
where: {
|
||||
id: id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -29,7 +30,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
success: false,
|
||||
message: "Gagal mendapatkan pengumuman, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,13 +76,26 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
// const fixMember = Object.groupBy(formatMember, ({ group }) => group);
|
||||
const fixMember = _.groupBy(formatMember, ({ group }) => group);
|
||||
|
||||
const file = await prisma.announcementFile.findMany({
|
||||
where: {
|
||||
idAnnouncement: id
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
idStorage: true,
|
||||
name: true,
|
||||
extension: true
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan pengumuman",
|
||||
data: announcement,
|
||||
member: fixMember
|
||||
member: fixMember,
|
||||
file: file
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
@@ -153,7 +167,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
// EDIT PENGUMUMAN
|
||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { title, desc, groups, user } = (await request.json());
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { title, desc, groups, user } = (await request.json());
|
||||
const { title, desc, groups, user, oldFile } = JSON.parse(dataBody as string)
|
||||
const { id } = context.params;
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
@@ -173,7 +192,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
success: false,
|
||||
message: "Edit pengumuman gagal, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -213,6 +232,41 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
data: memberDivision,
|
||||
});
|
||||
|
||||
if (oldFile.length > 0) {
|
||||
for (let index = 0; index < oldFile.length; index++) {
|
||||
const element = oldFile[index];
|
||||
if (element.delete) {
|
||||
await prisma.announcementFile.delete({
|
||||
where: {
|
||||
id: element.id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cekFile) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.announcement })
|
||||
if (upload.success) {
|
||||
await prisma.announcementFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idAnnouncement: id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data pengumuman', table: 'announcement', data: id, user: userMobile.id })
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { funSendWebPush, prisma } from "@/module/_global";
|
||||
import { DIR, funSendWebPush, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from '@/module/user';
|
||||
import _ from "lodash";
|
||||
@@ -113,7 +113,12 @@ export async function GET(request: Request) {
|
||||
// CREATE PENGUMUMAN
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { title, desc, groups, user } = (await request.json());
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { title, desc, groups, user } = (await request.json());
|
||||
const { title, desc, groups, user } = JSON.parse(dataBody as string)
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
if (userMobile.id == "null" || userMobile.id == undefined || userMobile.id == "") {
|
||||
@@ -152,6 +157,29 @@ export async function POST(request: Request) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (cekFile) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.announcement })
|
||||
if (upload.success) {
|
||||
await prisma.announcementFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idAnnouncement: data.id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const announcementMember = await prisma.announcementMember.createMany({
|
||||
data: memberDivision,
|
||||
});
|
||||
@@ -255,15 +283,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",
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: Request) {
|
||||
const userMobile = searchParams.get("user")
|
||||
|
||||
if (userMobile == "null" || userMobile == undefined || userMobile == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const user = await funGetUserById({ id: userMobile })
|
||||
|
||||
@@ -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)" })
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { countTime, prisma } from "@/module/_global";
|
||||
import { countTime, DIR, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
@@ -19,7 +19,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
const user = await funGetUserById({ id: String(userMobile) })
|
||||
|
||||
if (user.id == "null" || user.id == undefined || user.id == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const cek = await prisma.discussion.count({
|
||||
@@ -29,7 +29,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
})
|
||||
|
||||
if (cek == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, data tidak ditemukan" }, { status: 404 });
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
if (kategori == "detail") {
|
||||
@@ -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
|
||||
}))
|
||||
@@ -121,8 +127,21 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
} else {
|
||||
dataFix = false
|
||||
}
|
||||
}
|
||||
} else if (kategori == "file") {
|
||||
const data = await prisma.discussionFile.findMany({
|
||||
where: {
|
||||
idDiscussion: id
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
idStorage: true,
|
||||
name: true,
|
||||
extension: true
|
||||
}
|
||||
})
|
||||
|
||||
dataFix = data
|
||||
}
|
||||
|
||||
return NextResponse.json({ success: true, message: "Berhasil mendapatkan diskusi", data: dataFix }, { status: 200 });
|
||||
|
||||
@@ -241,7 +260,12 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
export async function PUT(request: Request, context: { params: { id: string } }) {
|
||||
try {
|
||||
const { id } = context.params
|
||||
const { title, desc, user } = (await request.json());
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { title, desc, user } = (await request.json());
|
||||
const { title, desc, user, oldFile } = JSON.parse(dataBody as string)
|
||||
|
||||
const userMobile = await funGetUserById({ id: String(user) })
|
||||
|
||||
@@ -269,6 +293,41 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
}
|
||||
});
|
||||
|
||||
if (oldFile.length > 0) {
|
||||
for (let index = 0; index < oldFile.length; index++) {
|
||||
const element = oldFile[index];
|
||||
if (element.delete) {
|
||||
await prisma.discussionFile.delete({
|
||||
where: {
|
||||
id: element.id
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (cekFile) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.discussion })
|
||||
if (upload.success) {
|
||||
await prisma.discussionFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idDiscussion: id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'UPDATE', desc: 'User mengupdate data diskusi umum', table: 'discussion', data: id, user: userMobile.id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil mengedit diskusi umum" }, { status: 200 });
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { DIR, funUploadFile, prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
@@ -15,7 +15,7 @@ export async function GET(request: Request) {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const user = searchParams.get("user")
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
@@ -75,6 +75,9 @@ export async function GET(request: Request) {
|
||||
DiscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where: {
|
||||
isActive: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -109,13 +112,20 @@ export async function GET(request: Request) {
|
||||
// CREATE DISCUSSION GENERALE
|
||||
export async function POST(request: Request) {
|
||||
try {
|
||||
const { idGroup, user, title, desc, member } = await request.json();
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const cekFile = body.has("file0")
|
||||
|
||||
// const { idGroup, user, title, desc, member } = await request.json();
|
||||
const { idGroup, user, title, desc, member } = JSON.parse(dataBody as string)
|
||||
|
||||
const userMobile = await funGetUserById({ id: 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 userMobile = await funGetUserById({ id: user })
|
||||
const userId = user
|
||||
const userRoleLogin = userMobile.idUserRole
|
||||
|
||||
@@ -142,6 +152,29 @@ export async function POST(request: Request) {
|
||||
data: dataMember
|
||||
})
|
||||
|
||||
|
||||
if (cekFile) {
|
||||
body.delete("data")
|
||||
for (var pair of body.entries()) {
|
||||
if (String(pair[0]).substring(0, 4) == "file") {
|
||||
const file = body.get(pair[0]) as File
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = decodeURIComponent(file.name.replace("." + fExt, ""))
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.discussion })
|
||||
if (upload.success) {
|
||||
await prisma.discussionFile.create({
|
||||
data: {
|
||||
idStorage: upload.data.id,
|
||||
idDiscussion: data.id,
|
||||
name: fName,
|
||||
extension: String(fExt)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const memberNotifMobile = await prisma.discussionMember.findMany({
|
||||
where: {
|
||||
idDiscussion: data.id
|
||||
@@ -210,9 +243,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 });
|
||||
}
|
||||
}
|
||||
@@ -31,33 +31,42 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
success: false,
|
||||
message: "Gagal mendapatkan diskusi, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
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 });
|
||||
@@ -128,7 +137,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
});
|
||||
|
||||
if (data == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, data tidak ditemukan" }, { status: 404 });
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan diskusi, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
const result = await prisma.divisionDisscussion.update({
|
||||
|
||||
@@ -35,7 +35,7 @@ export async function GET(request: Request) {
|
||||
})
|
||||
|
||||
if (cekDivision == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.divisionDisscussion.findMany({
|
||||
@@ -67,6 +67,9 @@ export async function GET(request: Request) {
|
||||
DivisionDisscussionComment: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
where: {
|
||||
isActive: true
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +121,7 @@ export async function POST(request: Request) {
|
||||
})
|
||||
|
||||
if (cekDivision == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 404 });
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan divisi, data tidak ditemukan" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.divisionDisscussion.create({
|
||||
@@ -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 });
|
||||
}
|
||||
};
|
||||
@@ -12,7 +12,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
const userMobile = searchParams.get("user")
|
||||
|
||||
if (userMobile == "null" || userMobile == undefined || userMobile == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const { id } = context.params;
|
||||
@@ -28,7 +28,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
success: false,
|
||||
message: "Gagal mendapatkan grup, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
const { isActive, user } = (await request.json());
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
const userLogin = await funGetUserById({ id: user })
|
||||
|
||||
@@ -68,7 +68,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
success: false,
|
||||
message: "Edit grup gagal, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
const { name, user } = (await request.json());
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.group.count({
|
||||
@@ -113,7 +113,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
success: false,
|
||||
message: "Edit grup gagal, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: Request) {
|
||||
const userMobile = searchParams.get("user")
|
||||
|
||||
if (userMobile == "null" || userMobile == undefined || userMobile == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const user = await funGetUserById({ id: userMobile })
|
||||
@@ -51,7 +51,7 @@ export async function POST(request: Request) {
|
||||
const { name, user } = (await request.json());
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: Request) {
|
||||
const userMobile = searchParams.get("user")
|
||||
|
||||
if (userMobile == "null" || userMobile == undefined || userMobile == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const userId = await funGetUserById({ id: userMobile })
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
const { id } = context.params;
|
||||
|
||||
if (userMobile == "null" || userMobile == undefined || userMobile == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.position.findUnique({
|
||||
@@ -30,7 +30,7 @@ export async function GET(request: Request, context: { params: { id: string } })
|
||||
success: false,
|
||||
message: "Gagal mendapatkan jabatan, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
const { isActive, user } = (await request.json());
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.position.count({
|
||||
@@ -104,7 +104,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
const { name, idGroup, user } = await request.json();
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const cek = await prisma.position.count({
|
||||
|
||||
@@ -16,7 +16,7 @@ export async function GET(request: Request) {
|
||||
const userMobile = searchParams.get("user")
|
||||
|
||||
if (userMobile == "null" || userMobile == undefined || userMobile == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const user = await funGetUserById({ id: userMobile })
|
||||
@@ -35,7 +35,7 @@ export async function GET(request: Request) {
|
||||
})
|
||||
|
||||
if (cek == 0) {
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, data tidak ditemukan", }, { status: 404 });
|
||||
return NextResponse.json({ success: false, message: "Gagal mendapatkan jabatan, data tidak ditemukan", }, { status: 200 });
|
||||
}
|
||||
|
||||
const filter = await prisma.group.findUnique({
|
||||
@@ -93,7 +93,7 @@ export async function POST(request: Request) {
|
||||
const { name, idGroup, user } = await request.json();
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const userMobile = await funGetUserById({ id: user })
|
||||
@@ -131,7 +131,7 @@ export async function POST(request: Request) {
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Jabatan sudah ada" },
|
||||
{ status: 400 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -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 != "");
|
||||
|
||||
@@ -87,7 +87,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
const { isActive, user } = (await request.json());
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const data = await prisma.user.count({
|
||||
@@ -102,7 +102,7 @@ export async function DELETE(request: Request, context: { params: { id: string }
|
||||
success: false,
|
||||
message: "Gagal mendapatkan anggota, data tidak ditemukan",
|
||||
},
|
||||
{ status: 404 }
|
||||
{ status: 200 }
|
||||
);
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
} = JSON.parse(data as string)
|
||||
|
||||
if (user == "null" || user == undefined || user == "") {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
|
||||
const cekNIK = await prisma.user.count({
|
||||
@@ -247,7 +247,7 @@ export async function PUT(request: Request, context: { params: { id: string } })
|
||||
{ status: 200 }
|
||||
);
|
||||
} else {
|
||||
return Response.json({ success: false, message: "Anggota sudah ada" }, { status: 400 });
|
||||
return Response.json({ success: false, message: "Anggota sudah ada" }, { status: 200 });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
@@ -11,7 +11,7 @@ export async function GET(request: Request) {
|
||||
try {
|
||||
const user = await funGetUserByCookies()
|
||||
if (user.id == undefined) {
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 401 });
|
||||
return NextResponse.json({ success: false, message: "Anda harus login untuk mengakses ini" }, { status: 200 });
|
||||
}
|
||||
const data = await prisma.user.findUnique({
|
||||
where: {
|
||||
|
||||
@@ -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.1.0", 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 });
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { hookstate } from "@hookstate/core"
|
||||
import { IGlobalTema } from './type_global';
|
||||
import { hookstate } from "@hookstate/core";
|
||||
import { RefObject } from "react";
|
||||
import { IGlobalTema } from './type_global';
|
||||
|
||||
export const pwd_key_config = "fchgvjknlmdfnbvghhujlaknsdvjbhknlkmsdbdyu567t8y9u30r4587638y9uipkoeghjvuyi89ipkoefmnrjbhtiu4or9ipkoemnjfbhjiuoijdklnjhbviufojkejnshbiuojijknehgruyu"
|
||||
export const globalRole = hookstate<string>('')
|
||||
@@ -11,7 +11,9 @@ export const DIR = {
|
||||
document: "cm0xhbkf50009acbbtw03qo4l",
|
||||
village: "cm0xhb91o0007acbbkx8rk8hj",
|
||||
user: "cm0x8dbwn0005bp5tgmfcthzw",
|
||||
banner: "cm1sxex19004938bjvyaq8vta"
|
||||
banner: "cm1sxex19004938bjvyaq8vta",
|
||||
announcement: "cmkdfkze4005hkhjgunsroi4t",
|
||||
discussion: "cmkf5h7ic006jkhjgyrkog7ut"
|
||||
}
|
||||
|
||||
export const keyWibu = 'padahariminggukuturutayahkekotanaikdelmanistimewakududukdimuka'
|
||||
|
||||
@@ -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