Merge pull request 'join' (#8) from join into staging
Reviewed-on: bip/sistem-desa-mandiri#8
This commit is contained in:
@@ -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";
|
||||||
|
|
||||||
|
|
||||||
// KIRIM KOMENTAR DISKUSI UMUM
|
// 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
|
// create log user
|
||||||
const log = await createLogUserMobile({ act: 'CREATE', desc: 'User menambah komentar pada diskusi umum', table: 'discussionComment', data: data.id, user: userMobile.id })
|
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 });
|
return NextResponse.json({ success: true, message: "Berhasil menambah komentar" }, { status: 200 });
|
||||||
|
|||||||
@@ -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 });
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ export async function sendFCMNotificationMany({ token, title, body, data }: { to
|
|||||||
},
|
},
|
||||||
// Opsional: konfigurasi APNS (iOS)
|
// Opsional: konfigurasi APNS (iOS)
|
||||||
apns: {
|
apns: {
|
||||||
|
headers: {
|
||||||
|
"apns-collapse-id": "order_update_notification",
|
||||||
|
},
|
||||||
payload: {
|
payload: {
|
||||||
aps: {
|
aps: {
|
||||||
sound: "default",
|
sound: "default",
|
||||||
|
|||||||
Reference in New Issue
Block a user