Compare commits
8 Commits
amalia/30-
...
amalia/06-
| Author | SHA1 | Date | |
|---|---|---|---|
| 9b4dec8a39 | |||
| 494853db06 | |||
| b625328789 | |||
| 3561f80bf6 | |||
| c4d454ea58 | |||
| b4b6076693 | |||
| e766a6059d | |||
| 7086a56e00 |
@@ -1,7 +1,9 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import { sendFCMNotificationMany } from "../../../../../../../xsendMany";
|
||||
|
||||
|
||||
// KIRIM KOMENTAR DISKUSI UMUM
|
||||
@@ -35,6 +37,78 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
}
|
||||
})
|
||||
|
||||
const member = await prisma.discussionMember.findMany({
|
||||
where: {
|
||||
idDiscussion: id,
|
||||
},
|
||||
select: {
|
||||
idUser: true,
|
||||
User: {
|
||||
select: {
|
||||
Subscribe: {
|
||||
select: {
|
||||
subscription: true
|
||||
}
|
||||
},
|
||||
TokenDeviceUser: {
|
||||
select: {
|
||||
token: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const userSent = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: userMobile.id
|
||||
},
|
||||
select: {
|
||||
name: true,
|
||||
img: true
|
||||
}
|
||||
})
|
||||
|
||||
const dataFCM = member.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||
}))
|
||||
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||
|
||||
if (userMobile.idUserRole != "supadmin") {
|
||||
const perbekel = await prisma.user.findFirst({
|
||||
where: {
|
||||
isActive: true,
|
||||
idUserRole: "supadmin",
|
||||
idVillage: userMobile.idVillage
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
Subscribe: {
|
||||
select: {
|
||||
subscription: true
|
||||
}
|
||||
},
|
||||
TokenDeviceUser: {
|
||||
select: {
|
||||
token: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||
}
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||
await sendFCMNotificationMany({
|
||||
token: tokenUnique,
|
||||
title: "Komentar Baru",
|
||||
body: `${userSent?.name}: ${data.comment}`,
|
||||
data: { id: data.id, category: "discussion", content: id }
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi umum', table: 'discussionComment', data: data.id, user: userMobile.id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil menambah komentar" }, { status: 200 });
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { prisma } from "@/module/_global";
|
||||
import { funGetUserById } from "@/module/auth";
|
||||
import { createLogUserMobile } from "@/module/user";
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import { sendFCMNotificationMany } from "../../../../../../../xsendMany";
|
||||
|
||||
// CREATE COMENT BY ID KOMENTAR
|
||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
||||
@@ -38,10 +40,91 @@ export async function POST(request: Request, context: { params: { id: string } }
|
||||
createdBy: userMobile.id
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
id: true,
|
||||
}
|
||||
})
|
||||
|
||||
const dataDivision = await prisma.divisionDisscussion.findUnique({
|
||||
where: {
|
||||
id: id
|
||||
},
|
||||
select: {
|
||||
idDivision: true,
|
||||
}
|
||||
})
|
||||
|
||||
const member = await prisma.divisionMember.findMany({
|
||||
where: {
|
||||
idDivision: dataDivision?.idDivision
|
||||
},
|
||||
select: {
|
||||
idUser: true,
|
||||
User: {
|
||||
select: {
|
||||
Subscribe: {
|
||||
select: {
|
||||
subscription: true
|
||||
}
|
||||
},
|
||||
TokenDeviceUser: {
|
||||
select: {
|
||||
token: true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
const userSent = await prisma.user.findFirst({
|
||||
where: {
|
||||
id: userMobile.id
|
||||
},
|
||||
select: {
|
||||
name: true,
|
||||
img: true
|
||||
}
|
||||
})
|
||||
|
||||
const dataFCM = member.map((v: any) => ({
|
||||
..._.omit(v, ["idUser", "User", "Subscribe", "TokenDeviceUser"]),
|
||||
tokens: v.User.TokenDeviceUser.map((v: any) => v.token)
|
||||
}))
|
||||
|
||||
const tokenDup = dataFCM.filter((v: any) => v.tokens.length > 0).map((v: any) => v.tokens).flat();
|
||||
if (userMobile.idUserRole != "supadmin") {
|
||||
const perbekel = await prisma.user.findFirst({
|
||||
where: {
|
||||
isActive: true,
|
||||
idUserRole: "supadmin",
|
||||
idVillage: userMobile.idVillage
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
Subscribe: {
|
||||
select: {
|
||||
subscription: true
|
||||
}
|
||||
},
|
||||
TokenDeviceUser: {
|
||||
select: {
|
||||
token: true
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||
}
|
||||
|
||||
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||
await sendFCMNotificationMany({
|
||||
token: tokenUnique,
|
||||
title: "Komentar Baru",
|
||||
body: `${userSent?.name}: ${comment}`,
|
||||
data: { id: data.id, category: `division/${dataDivision?.idDivision}/discussion/`, content: id }
|
||||
})
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi', table: 'divisionDisscussionComment', data: data.id, user: userMobile.id })
|
||||
|
||||
|
||||
@@ -10,8 +10,6 @@ export async function POST(request: Request) {
|
||||
try {
|
||||
const body = await request.formData()
|
||||
const dataBody = body.get("data")
|
||||
const file = body.get("file") as File
|
||||
const fileName = file.name
|
||||
|
||||
const { idPath, idDivision, user } = JSON.parse(dataBody as string)
|
||||
|
||||
@@ -57,39 +55,48 @@ export async function POST(request: Request) {
|
||||
..._.omit(v, [""]),
|
||||
file: v.name + '.' + v.extension,
|
||||
}))
|
||||
|
||||
const cek = dataOmit.some((i: any) => i.file == fileName)
|
||||
|
||||
if (cek) {
|
||||
return NextResponse.json({ success: false, message: "Terdapat file dengan nama yang sama" }, { status: 200 });
|
||||
}
|
||||
|
||||
|
||||
const fExt = file.name.split(".").pop()
|
||||
const fName = file.name.replace("." + fExt, "")
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.document })
|
||||
if (upload.success) {
|
||||
const dataInsert = await prisma.divisionDocumentFolderFile.create({
|
||||
data: {
|
||||
name: fName,
|
||||
path: idPath,
|
||||
idDivision,
|
||||
category: "FILE",
|
||||
extension: String(fExt),
|
||||
createdBy: userMobile.id,
|
||||
idStorage: upload.data.id
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
let failed = 0
|
||||
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 fileName = file.name
|
||||
const fExt = file.name.split(".").pop()
|
||||
let fName = file.name.replace("." + fExt, "")
|
||||
const cek = dataOmit.some((i: any) => i.file == fileName)
|
||||
if (cek) {
|
||||
const random = Math.floor(Math.random() * 1000)
|
||||
fName = `${fName}_${random}`
|
||||
}
|
||||
});
|
||||
const upload = await funUploadFile({ file: file, dirId: DIR.document })
|
||||
if (upload.success) {
|
||||
const dataInsert = await prisma.divisionDocumentFolderFile.create({
|
||||
data: {
|
||||
name: fName,
|
||||
path: idPath,
|
||||
idDivision,
|
||||
category: "FILE",
|
||||
extension: String(fExt),
|
||||
createdBy: userMobile.id,
|
||||
idStorage: upload.data.id
|
||||
},
|
||||
select: {
|
||||
id: true
|
||||
}
|
||||
});
|
||||
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User mengupload file baru', table: 'divisionDocumentFolderFile', data: dataInsert.id, user: userMobile.id })
|
||||
return NextResponse.json({ success: true, message: "Berhasil upload file" }, { status: 200 });
|
||||
} else {
|
||||
return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti" }, { status: 200 });
|
||||
// create log user
|
||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User mengupload file baru', table: 'divisionDocumentFolderFile', data: dataInsert.id, user: userMobile.id })
|
||||
} else {
|
||||
failed++
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (failed > 0) {
|
||||
return NextResponse.json({ success: false, message: "Beberapa file gagal diupload", failed }, { status: 200 });
|
||||
}
|
||||
return NextResponse.json({ success: true, message: "Berhasil upload file" }, { status: 200 });
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return NextResponse.json({ success: false, message: "Gagal upload file, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||
|
||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
try {
|
||||
return NextResponse.json({ success: true, version: "1.5.7", tahap: "beta", update: "-fix mobile api" }, { status: 200 });
|
||||
return NextResponse.json({ success: true, version: "1.5.8", tahap: "beta", update: "-update notif komen diskusi" }, { 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 });
|
||||
|
||||
@@ -33,6 +33,9 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
||||
},
|
||||
// Opsional: konfigurasi APNS (iOS)
|
||||
apns: {
|
||||
headers: {
|
||||
"apns-collapse-id": "order_update_notification",
|
||||
},
|
||||
payload: {
|
||||
aps: {
|
||||
sound: "default",
|
||||
|
||||
Reference in New Issue
Block a user