Merge pull request 'upd: api komen diskusi' (#7) from amalia/06-agustus-25 into join
Reviewed-on: bip/sistem-desa-mandiri#7
This commit is contained in:
@@ -100,6 +100,7 @@ export async function POST(request: Request, context: { params: { id: string } }
|
|||||||
|
|
||||||
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
tokenDup.push(perbekel?.TokenDeviceUser.map((v: any) => v.token).flat())
|
||||||
}
|
}
|
||||||
|
|
||||||
const tokenUnique = [...new Set(tokenDup.flat())];
|
const tokenUnique = [...new Set(tokenDup.flat())];
|
||||||
await sendFCMNotificationMany({
|
await sendFCMNotificationMany({
|
||||||
token: tokenUnique,
|
token: tokenUnique,
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
import { prisma } from "@/module/_global";
|
import { prisma } from "@/module/_global";
|
||||||
import { funGetUserById } from "@/module/auth";
|
import { funGetUserById } from "@/module/auth";
|
||||||
import { createLogUserMobile } from "@/module/user";
|
import { createLogUserMobile } from "@/module/user";
|
||||||
|
import _ from "lodash";
|
||||||
import { NextResponse } from "next/server";
|
import { NextResponse } from "next/server";
|
||||||
|
import { sendFCMNotificationMany } from "../../../../../../../xsendMany";
|
||||||
|
|
||||||
// CREATE COMENT BY ID KOMENTAR
|
// CREATE COMENT BY ID KOMENTAR
|
||||||
export async function POST(request: Request, context: { params: { id: string } }) {
|
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
|
createdBy: userMobile.id
|
||||||
},
|
},
|
||||||
select: {
|
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
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi', table: 'divisionDisscussionComment', data: data.id, user: userMobile.id })
|
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi', table: 'divisionDisscussionComment', data: data.id, user: userMobile.id })
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { NextResponse } from "next/server";
|
|||||||
|
|
||||||
export async function GET(request: Request) {
|
export async function GET(request: Request) {
|
||||||
try {
|
try {
|
||||||
return NextResponse.json({ success: true, version: "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) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
return NextResponse.json({ success: false, version: "Gagal mendapatkan version, coba lagi nanti (error: 500)", reason: (error as Error).message, }, { status: 500 });
|
||||||
|
|||||||
Reference in New Issue
Block a user