Compare commits
40 Commits
mobile-not
...
mobile-not
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c6dde6204 | |||
| cb0845e264 | |||
| d09e30c049 | |||
| c8bd928c33 | |||
| 3a558cec8e | |||
| b9354cb6bf | |||
| 7cdde6b5a9 | |||
| e77e5eb3ac | |||
| 8f3f27122a | |||
| d84a1d84ff | |||
| 40ba31edec | |||
| a54f8599b4 | |||
| 09825756f3 | |||
| 2086692897 | |||
| 87515ae19f | |||
| 44d6788f6e | |||
| ac634100b5 | |||
| 1b206102b0 | |||
| 94a545bd30 | |||
| 3552cf4f39 | |||
| d50fda90e0 | |||
| d3d4912a5f | |||
| b2e8bc3caf | |||
| d207b6feed | |||
| f05571caa4 | |||
| 6507bdcd35 | |||
| f1c8432fdc | |||
| 1cd4c3713e | |||
| 4307b383e3 | |||
| 0786d23336 | |||
| cb3511f973 | |||
| b4921c4e82 | |||
| a9325054eb | |||
| 819812149f | |||
| 75ba2b29ae | |||
| 54a4d15bdd | |||
| 1321f33da9 | |||
| fad0c33b9a | |||
| 565bab4998 | |||
| 7530a38c4d |
14
CHANGELOG.md
14
CHANGELOG.md
@@ -2,6 +2,20 @@
|
||||
|
||||
All notable changes to this project will be documented in this file. See [commit-and-tag-version](https://github.com/absolute-version/commit-and-tag-version) for commit guidelines.
|
||||
|
||||
## [1.5.36](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.35...v1.5.36) (2026-01-13)
|
||||
|
||||
## [1.5.35](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.34...v1.5.35) (2026-01-12)
|
||||
|
||||
## [1.5.34](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.33...v1.5.34) (2026-01-09)
|
||||
|
||||
## [1.5.33](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.32...v1.5.33) (2026-01-06)
|
||||
|
||||
## [1.5.32](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.31...v1.5.32) (2026-01-05)
|
||||
|
||||
## [1.5.31](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.30...v1.5.31) (2025-12-24)
|
||||
|
||||
## [1.5.30](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.29...v1.5.30) (2025-12-19)
|
||||
|
||||
## [1.5.29](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.28...v1.5.29) (2025-12-17)
|
||||
|
||||
## [1.5.28](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.27...v1.5.28) (2025-12-17)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.29",
|
||||
"version": "1.5.36",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Notifikasi" ADD COLUMN "type" TEXT;
|
||||
@@ -0,0 +1,16 @@
|
||||
-- DropForeignKey
|
||||
ALTER TABLE "Notifikasi" DROP CONSTRAINT "Notifikasi_userRoleId_fkey";
|
||||
|
||||
-- AlterTable
|
||||
ALTER TABLE "Notifikasi" ADD COLUMN "recipientId" TEXT,
|
||||
ADD COLUMN "senderId" TEXT,
|
||||
ALTER COLUMN "userRoleId" DROP NOT NULL;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Notifikasi" ADD CONSTRAINT "Notifikasi_userRoleId_fkey" FOREIGN KEY ("userRoleId") REFERENCES "MasterUserRole"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Notifikasi" ADD CONSTRAINT "Notifikasi_recipientId_fkey" FOREIGN KEY ("recipientId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
|
||||
-- AddForeignKey
|
||||
ALTER TABLE "Notifikasi" ADD CONSTRAINT "Notifikasi_senderId_fkey" FOREIGN KEY ("senderId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;
|
||||
@@ -0,0 +1,4 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "Notifikasi" ALTER COLUMN "appId" DROP NOT NULL,
|
||||
ALTER COLUMN "kategoriApp" DROP NOT NULL,
|
||||
ALTER COLUMN "pesan" DROP NOT NULL;
|
||||
@@ -59,6 +59,10 @@ model User {
|
||||
acceptedTermsAt DateTime?
|
||||
acceptedForumTermsAt DateTime?
|
||||
tokenUserDevices TokenUserDevice[]
|
||||
|
||||
// For Mobile App
|
||||
NotificationRecipient Notifikasi[] @relation("NotificationRecipient")
|
||||
NotificationSender Notifikasi[] @relation("NotificationSender")
|
||||
}
|
||||
|
||||
model MasterUserRole {
|
||||
@@ -587,7 +591,7 @@ model Donasi_Invoice {
|
||||
|
||||
imageId String?
|
||||
MasterBank MasterBank? @relation(fields: [masterBankId], references: [id])
|
||||
masterBankId String?
|
||||
masterBankId String?
|
||||
}
|
||||
|
||||
model Donasi_Kabar {
|
||||
@@ -974,27 +978,36 @@ model NomorAdmin {
|
||||
}
|
||||
|
||||
model Notifikasi {
|
||||
id String @id @default(cuid())
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
appId String
|
||||
kategoriApp String
|
||||
pesan String
|
||||
id String @id @default(cuid())
|
||||
isActive Boolean @default(true)
|
||||
createdAt DateTime @default(now())
|
||||
updatedAt DateTime @updatedAt
|
||||
appId String?
|
||||
kategoriApp String?
|
||||
pesan String?
|
||||
title String?
|
||||
status String?
|
||||
|
||||
isRead Boolean @default(false)
|
||||
readAt DateTime? // kapan user membaca notifikasi ini
|
||||
deepLink String? // misal: "announcement/123", "user/profile/cmha6wb9w0001cfndwl9fcse6"
|
||||
|
||||
isRead Boolean @default(false)
|
||||
readAt DateTime? // kapan user membaca notifikasi ini
|
||||
deepLink String? // misal: "announcement/123", "user/profile/cmha6wb9w0001cfndwl9fcse6"
|
||||
type String?
|
||||
|
||||
Role MasterUserRole? @relation(fields: [userRoleId], references: [id])
|
||||
userRoleId String
|
||||
userRoleId String?
|
||||
|
||||
User User? @relation("UserNotifikasi", fields: [userId], references: [id], map: "NotifikasiUser")
|
||||
userId String?
|
||||
Admin User? @relation("AdminNotifikasi", fields: [adminId], references: [id], map: "NotifikasiAdmin")
|
||||
adminId String?
|
||||
|
||||
// Recipient (user who receives the notification)
|
||||
recipient User? @relation("NotificationRecipient", fields: [recipientId], references: [id])
|
||||
recipientId String?
|
||||
|
||||
// Sender (user who sent the notification)
|
||||
sender User? @relation("NotificationSender", fields: [senderId], references: [id])
|
||||
senderId String?
|
||||
}
|
||||
|
||||
// MAPS
|
||||
|
||||
54
src/app/api/auth/mobile-eula/route.tsx
Normal file
54
src/app/api/auth/mobile-eula/route.tsx
Normal file
@@ -0,0 +1,54 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
try {
|
||||
const { nomor } = await req.json();
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
nomor: nomor,
|
||||
},
|
||||
});
|
||||
|
||||
if (!user)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "User belum terdaftar",
|
||||
status: 404,
|
||||
});
|
||||
|
||||
const updateTerms = await prisma.user.update({
|
||||
where: { nomor: nomor },
|
||||
data: {
|
||||
termsOfServiceAccepted: true,
|
||||
acceptedTermsAt: new Date(),
|
||||
},
|
||||
});
|
||||
|
||||
if (!updateTerms) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal setujui syarat dan ketentuan",
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Anda telah setujui syarat dan ketentuan",
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Terjadi masalah saat setujui syarat dan ketentuan",
|
||||
reason: error as Error,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,6 @@ export async function POST(req: Request) {
|
||||
try {
|
||||
const codeOtp = randomOTP();
|
||||
const body = await req.json();
|
||||
console.log("[Masuk API]", body);
|
||||
const { nomor } = body;
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
@@ -15,9 +14,6 @@ export async function POST(req: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
console.log(["cek user", user]);
|
||||
console.log(["cek nomor", nomor]);
|
||||
|
||||
if (!user)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
@@ -66,6 +62,7 @@ export async function POST(req: Request) {
|
||||
success: true,
|
||||
message: "Kode verifikasi terkirim",
|
||||
kodeId: createOtpId.id,
|
||||
isAcceptTerms: user.termsOfServiceAccepted,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
@@ -1,7 +1,12 @@
|
||||
import { sessionCreate } from "@/app/(auth)/_lib/session_create";
|
||||
import { randomOTP } from "@/app_modules/auth/fun/rondom_otp";
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../types/type-mobile-notification";
|
||||
|
||||
export async function POST(req: Request) {
|
||||
if (req.method !== "POST") {
|
||||
@@ -51,12 +56,6 @@ export async function POST(req: Request) {
|
||||
{ status: 500 }
|
||||
);
|
||||
|
||||
// const token = await sessionCreate({
|
||||
// sessionKey: process.env.NEXT_PUBLIC_BASE_SESSION_KEY!,
|
||||
// encodedKey: process.env.NEXT_PUBLIC_BASE_TOKEN_KEY!,
|
||||
// user: createUser as any,
|
||||
// });
|
||||
|
||||
const createOtpId = await prisma.kodeOtp.create({
|
||||
data: {
|
||||
nomor: data.nomor,
|
||||
@@ -87,11 +86,43 @@ export async function POST(req: Request) {
|
||||
{ status: 400 }
|
||||
);
|
||||
|
||||
// =========== START SEND NOTIFICATION =========== //
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
console.log("Users to notify:", adminUsers);
|
||||
|
||||
const dataNotification = {
|
||||
title: "Pendaftaran Baru",
|
||||
type: "announcement",
|
||||
kategoriApp: "OTHER",
|
||||
createdAt: new Date(),
|
||||
pesan: "User baru telah melakukan registrasi. Ayo cek dan verifikasi!",
|
||||
deepLink: `/admin/user-access/${createUser.id}`,
|
||||
senderId: createUser.id,
|
||||
};
|
||||
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: data.authorId,
|
||||
payload: {
|
||||
title: "Pendaftaran User Baru" as NotificationMobileTitleType,
|
||||
body: "User baru telah melakukan registrasi. Ayo cek dan verifikasi!" as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeAdminMobile.userAccess({ id: createUser.id }),
|
||||
kategoriApp: "OTHER",
|
||||
},
|
||||
});
|
||||
|
||||
// =========== END SEND NOTIFICATION =========== //
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Registrasi Berhasil",
|
||||
// token: token,
|
||||
kodeId: createOtpId.id,
|
||||
},
|
||||
{ status: 201 }
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import {
|
||||
sendNotificationMobileToManyUser,
|
||||
sendNotificationMobileToOneUser,
|
||||
} from "@/lib/mobile/notification/send-notification";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -57,6 +66,8 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { catatan, senderId } = data;
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get("status");
|
||||
const fixStatus = _.startCase(status as string);
|
||||
@@ -89,11 +100,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
catatan: data,
|
||||
catatan: catatan,
|
||||
eventMaster_StatusId: checkStatus.id,
|
||||
},
|
||||
});
|
||||
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: updateData.authorId as any,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Pengajuan Review Ditolak",
|
||||
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
||||
type: "announcement",
|
||||
kategoriApp: "EVENT",
|
||||
deepLink: routeUserMobile.eventByStatus({status: "reject"}),
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updateData;
|
||||
} else if (fixStatus === "Publish") {
|
||||
const updateData = await prisma.event.update({
|
||||
@@ -105,6 +128,38 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: updateData.authorId as any,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Review Selesai",
|
||||
body: "Event kamu telah dipublikasikan !" as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "EVENT",
|
||||
deepLink: routeUserMobile.eventByStatus({status: "publish"}),
|
||||
},
|
||||
});
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: {
|
||||
masterUserRoleId: "1",
|
||||
NOT: { id: updateData.authorId as any },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Event Baru" as NotificationMobileTitleType,
|
||||
body: `${updateData.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "EVENT",
|
||||
deepLink: routeUserMobile.eventDetailPublised({ id: id }),
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updateData;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -82,21 +88,43 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const data = await request.json();
|
||||
|
||||
console.log("SENDER Comment", data);
|
||||
|
||||
try {
|
||||
const deleteData = await prisma.forum_Komentar.update({
|
||||
const deactiveComment = await prisma.forum_Komentar.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
},
|
||||
select: {
|
||||
authorId: true,
|
||||
komentar: true,
|
||||
},
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: deactiveComment?.authorId as string,
|
||||
senderId: data?.senderId,
|
||||
payload: {
|
||||
title: "Penghapusan Komentar" as NotificationMobileTitleType,
|
||||
body: `Komentar anda telah dilaporkan: ${deactiveComment?.komentar}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeUserMobile.forumPreviewReportComment({ id: id }),
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[DEACTIVATE COMMENT]");
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success deactivate comment",
|
||||
data: deleteData,
|
||||
// data: deactiveComment,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -78,14 +84,23 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const data = await request.json();
|
||||
const { senderId } = data;
|
||||
|
||||
console.log("SENDER POSTING", data);
|
||||
|
||||
try {
|
||||
const data = await prisma.forum_Posting.update({
|
||||
const deactivePosting = await prisma.forum_Posting.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
isActive: false,
|
||||
},
|
||||
select: {
|
||||
authorId: true,
|
||||
diskusi: true,
|
||||
},
|
||||
});
|
||||
|
||||
const deactivateComment = await prisma.forum_Komentar.updateMany({
|
||||
@@ -97,12 +112,25 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[DEACTIVATE COMMENT]", deactivateComment);
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: deactivePosting?.authorId as string,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Penghapusan Postingan" as NotificationMobileTitleType,
|
||||
body: `Postingan anda telah dilaporkan: ${deactivePosting?.diskusi}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeUserMobile.forumPreviewReportPosting({ id: id }),
|
||||
},
|
||||
});
|
||||
|
||||
console.log("[DEACTIVATE POSTINGAN & COMMENT]", deactivateComment);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Success deactivate posting",
|
||||
data: data,
|
||||
data: deactivePosting,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
|
||||
@@ -1,6 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import {
|
||||
sendNotificationMobileToManyUser,
|
||||
sendNotificationMobileToOneUser,
|
||||
} from "@/lib/mobile/notification/send-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { NotificationMobileBodyType, NotificationMobileTitleType } from "../../../../../../../types/type-mobile-notification";
|
||||
|
||||
export { GET, PUT };
|
||||
|
||||
@@ -54,6 +60,9 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
|
||||
const { catatan, senderId } = data;
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get("status");
|
||||
const fixStatus = _.startCase(status as string);
|
||||
@@ -83,7 +92,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
data: {
|
||||
masterStatusId: checkStatus.id,
|
||||
catatan: data,
|
||||
catatan: catatan,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -97,6 +106,18 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: updt.authorId as any,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Pengajuan Review Ditolak",
|
||||
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
||||
type: "announcement",
|
||||
kategoriApp: "JOB",
|
||||
deepLink: routeUserMobile.jobByStatus({ status: "reject" }),
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updt;
|
||||
} else if (fixStatus === "Publish") {
|
||||
const updt = await prisma.job.update({
|
||||
@@ -118,6 +139,35 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: updt.authorId as any,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Review Selesai",
|
||||
body: "Selamat data anda telah terpublikasi",
|
||||
type: "announcement",
|
||||
kategoriApp: "JOB",
|
||||
deepLink: routeUserMobile.jobByStatus({ status: "publish" }),
|
||||
},
|
||||
});
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: { masterUserRoleId: "1", NOT: { id: updt.authorId as any } },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: data.authorId,
|
||||
payload: {
|
||||
title: "Ada Lowongan Kerja Baru" as NotificationMobileTitleType,
|
||||
body: `${updt.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeUserMobile.jobDetailPublised({ id: id }),
|
||||
kategoriApp: "JOB",
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updt;
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,15 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
console.log("Received data:", data);
|
||||
console.log("User ID:", id);
|
||||
console.log("Category:", category);
|
||||
|
||||
try {
|
||||
if (data.active) {
|
||||
if (category === "access") {
|
||||
const updateData = await prisma.user.update({
|
||||
where: {
|
||||
id: id,
|
||||
@@ -47,7 +53,7 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
});
|
||||
|
||||
console.log("[Update Active Berhasil]", updateData);
|
||||
} else if (data.role) {
|
||||
} else if (category === "role") {
|
||||
const fixName = _.startCase(data.role.replace(/_/g, " "));
|
||||
|
||||
const checkRole = await prisma.masterUserRole.findFirst({
|
||||
@@ -68,6 +74,12 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
});
|
||||
|
||||
console.log("[Update Role Berhasil]", updateData);
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
status: 400,
|
||||
success: false,
|
||||
message: "Invalid category",
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
|
||||
@@ -1,8 +1,17 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import {
|
||||
sendNotificationMobileToManyUser,
|
||||
sendNotificationMobileToOneUser,
|
||||
} from "@/lib/mobile/notification/send-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
|
||||
export { GET , PUT};
|
||||
export { GET, PUT };
|
||||
|
||||
async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
@@ -41,12 +50,16 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { catatan, senderId } = data;
|
||||
|
||||
console.log("catatan", catatan);
|
||||
console.log("senderId", senderId);
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const status = searchParams.get("status");
|
||||
const fixStatus = _.startCase(status as string);
|
||||
let fixData;
|
||||
|
||||
|
||||
try {
|
||||
const checkStatus = await prisma.voting_Status.findFirst({
|
||||
where: {
|
||||
@@ -71,9 +84,23 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
data: {
|
||||
voting_StatusId: checkStatus.id,
|
||||
catatan: data,
|
||||
catatan: catatan,
|
||||
},
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: updateStatus.authorId as any,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Pengajuan Review Ditolak",
|
||||
body: "Mohon perbaiki data sesuai catatan penolakan !",
|
||||
type: "announcement",
|
||||
kategoriApp: "VOTING",
|
||||
deepLink: routeUserMobile.votingByStatus({ status: "reject" }),
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updateStatus;
|
||||
} else if (fixStatus === "Publish") {
|
||||
const updateStatus = await prisma.voting.update({
|
||||
@@ -84,6 +111,39 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
voting_StatusId: checkStatus.id,
|
||||
},
|
||||
});
|
||||
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: updateStatus.authorId as any,
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Review Selesai",
|
||||
body: "Voting kamu telah dipublikasikan !" as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "VOTING",
|
||||
deepLink: routeUserMobile.votingByStatus({ status: "publish" }),
|
||||
},
|
||||
});
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: {
|
||||
masterUserRoleId: "1",
|
||||
NOT: { id: updateStatus.authorId as any },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: senderId,
|
||||
payload: {
|
||||
title: "Cek Voting Baru Terpublikasi" as NotificationMobileTitleType,
|
||||
body: `${updateStatus.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "VOTING",
|
||||
deepLink: routeUserMobile.votingDetailPublised({ id: id }),
|
||||
},
|
||||
});
|
||||
|
||||
fixData = updateStatus;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,10 +8,17 @@ async function DELETE(
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const deviceId = searchParams.get("deviceId");
|
||||
|
||||
console.log("ID", id);
|
||||
console.log("DEVICE ID", deviceId);
|
||||
|
||||
try {
|
||||
const findFirst = await prisma.tokenUserDevice.findFirst({
|
||||
where: {
|
||||
userId: id,
|
||||
deviceId: deviceId as any,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ export { POST, GET };
|
||||
async function POST(request: NextRequest) {
|
||||
const { data } = await request.json();
|
||||
try {
|
||||
console.log("Data >>", JSON.stringify(data, null, 2));
|
||||
|
||||
const { userId, platform, deviceId, model, appVersion, fcmToken } = data;
|
||||
|
||||
@@ -24,6 +23,9 @@ async function POST(request: NextRequest) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
console.log("✅ EX", existing);
|
||||
|
||||
let deviceToken;
|
||||
|
||||
if (existing) {
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
@@ -13,18 +19,28 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
eventId: id,
|
||||
userId: userId,
|
||||
},
|
||||
|
||||
// select: {
|
||||
// Event: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// title: true,
|
||||
// authorId: true,
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
});
|
||||
|
||||
const findEvent = await prisma.event.findUnique({
|
||||
where: { id: id },
|
||||
select: { authorId: true, title: true },
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
if (userId !== findEvent?.authorId) {
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: findEvent?.authorId as string,
|
||||
senderId: userId,
|
||||
payload: {
|
||||
title: "Peserta Baru Join" as NotificationMobileTitleType,
|
||||
body: `Ada peserta baru dalam event: ${findEvent?.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeUserMobile.eventDetailPublised({ id: id }),
|
||||
kategoriApp: "EVENT",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import moment from "moment";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
|
||||
export { GET, POST };
|
||||
|
||||
@@ -30,6 +33,24 @@ async function POST(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: data.authorId,
|
||||
payload: {
|
||||
title: "Pengajuan Review Baru",
|
||||
body: create.title as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeAdminMobile.eventByStatus({ status: "review" }),
|
||||
kategoriApp: "EVENT",
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
|
||||
@@ -1,11 +1,18 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { POST, GET, DELETE };
|
||||
|
||||
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { comment, authorId } = data;
|
||||
|
||||
console.log("[ID COMMENT]", id);
|
||||
console.log("[DATA COMMENT]", data);
|
||||
@@ -14,8 +21,8 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
const createComment = await prisma.forum_Komentar.create({
|
||||
data: {
|
||||
forum_PostingId: id,
|
||||
komentar: data.comment,
|
||||
authorId: data.authorId,
|
||||
komentar: comment,
|
||||
authorId: authorId,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
@@ -38,6 +45,24 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
const findForum = await prisma.forum_Posting.findUnique({
|
||||
where: { id: id },
|
||||
select: { authorId: true, diskusi: true },
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: findForum?.authorId as string,
|
||||
senderId: authorId,
|
||||
payload: {
|
||||
title: "Komentar Baru" as NotificationMobileTitleType,
|
||||
body: `Ayo cek komentar pada postingan: ${findForum?.diskusi}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeUserMobile.forumDetail({ id: id }),
|
||||
},
|
||||
});
|
||||
|
||||
if (!createComment) {
|
||||
return NextResponse.json({
|
||||
status: 400,
|
||||
@@ -52,7 +77,6 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
message: "Berhasil update data",
|
||||
data: createComment,
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.log("[ERROR COMMENT]", error);
|
||||
return NextResponse.json({
|
||||
@@ -114,7 +138,10 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
}
|
||||
}
|
||||
|
||||
async function DELETE(request: Request, { params }: { params: { id: string } }) {
|
||||
async function DELETE(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
@@ -146,4 +173,4 @@ async function DELETE(request: Request, { params }: { params: { id: string } })
|
||||
reason: (error as Error).message || error,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const data = await prisma.forum_Komentar.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
komentar: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
Forum_ReportKomentar: {
|
||||
select: {
|
||||
deskripsi: true,
|
||||
ForumMaster_KategoriReport: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
success: true,
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
return NextResponse.json({
|
||||
status: 500,
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data posting",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
const data = await prisma.forum_Posting.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
isActive: true,
|
||||
createdAt: true,
|
||||
authorId: true,
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
},
|
||||
},
|
||||
Forum_ReportPosting: {
|
||||
select: {
|
||||
deskripsi: true,
|
||||
ForumMaster_KategoriReport: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
status: 200,
|
||||
success: true,
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("[ERROR]", error);
|
||||
return NextResponse.json({
|
||||
status: 500,
|
||||
success: false,
|
||||
message: "Gagal mendapatkan data posting",
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,11 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
|
||||
export { POST };
|
||||
|
||||
@@ -7,44 +13,70 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
let fixData;
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
console.log("[DATA]", data);
|
||||
console.log("[ID]", id);
|
||||
const { authorId: reportedUserId, categoryId, description } = data;
|
||||
|
||||
try {
|
||||
const content = await prisma.forum_Komentar.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
// Komentar yang di report
|
||||
const findComment = await prisma.forum_Komentar.findUnique({
|
||||
where: { id: id },
|
||||
select: { authorId: true, komentar: true },
|
||||
});
|
||||
|
||||
const reportList = await prisma.forumMaster_KategoriReport.findUnique({
|
||||
// List admin untuk dikirim notifikasi
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: {
|
||||
id: data.categoryId,
|
||||
masterUserRoleId: "2",
|
||||
NOT: { id: findComment?.authorId as any },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
const msg = `Report Komentar: "${content?.komentar}" dengan kategori \n\n\n${reportList?.title} : \n\n${reportList?.deskripsi}`;
|
||||
const res = await fetch(
|
||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
|
||||
{ cache: "no-cache" }
|
||||
);
|
||||
|
||||
if (data.categoryId) {
|
||||
fixData = await prisma.forum_ReportKomentar.create({
|
||||
if (categoryId) {
|
||||
const createdReport = await prisma.forum_ReportKomentar.create({
|
||||
data: {
|
||||
forum_KomentarId: id,
|
||||
userId: data.authorId,
|
||||
forumMaster_KategoriReportId: data.categoryId as any,
|
||||
userId: reportedUserId,
|
||||
forumMaster_KategoriReportId: categoryId,
|
||||
},
|
||||
});
|
||||
|
||||
//SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: reportedUserId,
|
||||
payload: {
|
||||
title: "Laporan Dari User" as NotificationMobileTitleType,
|
||||
body: `Report terhadap komentar, ${findComment?.komentar}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeAdminMobile.forumPreviewReportComment,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = createdReport;
|
||||
} else {
|
||||
fixData = await prisma.forum_ReportKomentar.create({
|
||||
const createdReport = await prisma.forum_ReportKomentar.create({
|
||||
data: {
|
||||
forum_KomentarId: id,
|
||||
userId: data.authorId,
|
||||
deskripsi: data.description,
|
||||
userId: reportedUserId,
|
||||
deskripsi: description,
|
||||
},
|
||||
});
|
||||
|
||||
//SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: reportedUserId,
|
||||
payload: {
|
||||
title: "Laporan Dari User" as NotificationMobileTitleType,
|
||||
body: `Report terhadap komentar, ${findComment?.komentar}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeAdminMobile.forumPreviewReportComment,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = createdReport;
|
||||
}
|
||||
|
||||
if (!fixData) {
|
||||
|
||||
@@ -1,5 +1,15 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
sendNotificationMobileToManyUser
|
||||
} from "@/lib/mobile/notification/send-notification";
|
||||
import {
|
||||
routeAdminMobile
|
||||
} from "@/lib/mobile/route-page-mobile";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../../types/type-mobile-notification";
|
||||
|
||||
export { POST };
|
||||
|
||||
@@ -7,38 +17,70 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
let fixData;
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
console.log("[DATA]", data);
|
||||
console.log("[ID]", id);
|
||||
const { authorId: reportedUserId, categoryId, description } = data;
|
||||
|
||||
try {
|
||||
const content = await prisma.forum_Posting.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
// Postingan yang akan di report
|
||||
const findPosting = await prisma.forum_Posting.findUnique({
|
||||
where: { id: id },
|
||||
select: { authorId: true, diskusi: true },
|
||||
});
|
||||
|
||||
const msg = `Report Postingan: "${content?.diskusi}"`;
|
||||
const res = await fetch(
|
||||
`https://cld-dkr-prod-wajs-server.wibudev.com/api/wa/code?nom=6282340374412&text=${msg}`,
|
||||
{ cache: "no-cache" }
|
||||
);
|
||||
// List admin untuk dikirim notifikasi
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: {
|
||||
masterUserRoleId: "2",
|
||||
NOT: { id: findPosting?.authorId as any },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
if (data.categoryId) {
|
||||
fixData = await prisma.forum_ReportPosting.create({
|
||||
if (categoryId) {
|
||||
const createReported = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
forum_PostingId: id,
|
||||
userId: data.authorId,
|
||||
forumMaster_KategoriReportId: data.categoryId,
|
||||
userId: reportedUserId,
|
||||
forumMaster_KategoriReportId: categoryId,
|
||||
},
|
||||
});
|
||||
|
||||
//SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: reportedUserId,
|
||||
payload: {
|
||||
title: "Laporan Dari User" as NotificationMobileTitleType,
|
||||
body: `Report terhadap postingan, ${findPosting?.diskusi}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeAdminMobile.forumPreviewReportPosting,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = createReported;
|
||||
} else {
|
||||
fixData = await prisma.forum_ReportPosting.create({
|
||||
const createReported = await prisma.forum_ReportPosting.create({
|
||||
data: {
|
||||
forum_PostingId: id,
|
||||
userId: data.authorId,
|
||||
deskripsi: data.description,
|
||||
userId: reportedUserId,
|
||||
deskripsi: description,
|
||||
},
|
||||
});
|
||||
|
||||
//SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: reportedUserId,
|
||||
payload: {
|
||||
title: "Laporan Dari User" as NotificationMobileTitleType,
|
||||
body: `Report terhadap postingan, ${findPosting?.diskusi}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeAdminMobile.forumPreviewReportPosting,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = createReported;
|
||||
}
|
||||
|
||||
if (!fixData) {
|
||||
@@ -63,4 +105,4 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
reason: (error as Error).message,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,22 +1,54 @@
|
||||
import _ from "lodash";
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { NotificationMobileBodyType, NotificationMobileTitleType } from "../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
async function POST(request: Request) {
|
||||
const { data } = await request.json();
|
||||
console.log("[DATA]", data);
|
||||
const { diskusi, authorId } = data;
|
||||
|
||||
try {
|
||||
const create = await prisma.forum_Posting.create({
|
||||
data: {
|
||||
diskusi: data.diskusi,
|
||||
authorId: data.authorId,
|
||||
diskusi: diskusi,
|
||||
authorId: authorId,
|
||||
forumMaster_StatusPostingId: 1,
|
||||
},
|
||||
});
|
||||
|
||||
if (!create) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal memposting",
|
||||
status: 400,
|
||||
});
|
||||
}
|
||||
|
||||
const allUsers = await prisma.user.findMany({
|
||||
where: {
|
||||
id: { not: authorId },
|
||||
},
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: allUsers.map((user) => user.id),
|
||||
senderId: authorId,
|
||||
payload: {
|
||||
title: "Ada Diskusi Baru" as NotificationMobileTitleType,
|
||||
body: `${diskusi}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
kategoriApp: "FORUM",
|
||||
deepLink: routeUserMobile.forumBeranda,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil membuat postingan",
|
||||
@@ -43,7 +75,6 @@ async function GET(request: Request) {
|
||||
const takeData = 5;
|
||||
const skipData = (Number(page) - 1) * takeData;
|
||||
|
||||
|
||||
// console.log("authorId", authorId);
|
||||
// console.log("userLoginId", userLoginId);
|
||||
// console.log("search", search);
|
||||
@@ -83,7 +114,7 @@ async function GET(request: Request) {
|
||||
notIn: blockUserId,
|
||||
},
|
||||
},
|
||||
|
||||
|
||||
select: {
|
||||
id: true,
|
||||
diskusi: true,
|
||||
@@ -128,13 +159,12 @@ async function GET(request: Request) {
|
||||
|
||||
fixData = newData;
|
||||
} else if (category === "forumku") {
|
||||
|
||||
const count = await prisma.forum_Posting.count({
|
||||
where: {
|
||||
isActive: true,
|
||||
authorId: authorId,
|
||||
},
|
||||
})
|
||||
});
|
||||
|
||||
const data = await prisma.forum_Posting.findMany({
|
||||
take: page ? takeData : undefined,
|
||||
@@ -191,7 +221,7 @@ async function GET(request: Request) {
|
||||
const dataFix = {
|
||||
data: newData,
|
||||
count,
|
||||
}
|
||||
};
|
||||
|
||||
fixData = dataFix;
|
||||
} else {
|
||||
|
||||
@@ -13,6 +13,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
include: {
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
nomor: true,
|
||||
Profile: {
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NextResponse } from "next/server";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
@@ -17,6 +20,25 @@ async function POST(request: Request) {
|
||||
},
|
||||
});
|
||||
|
||||
// kirim notifikasi ke semua admin untuk mengetahui ada job baru yang harus di review
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: data.authorId,
|
||||
payload: {
|
||||
title: "Pengajuan Review Baru",
|
||||
body: `${create.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeAdminMobile.jobByStatus({ status: "review" }),
|
||||
kategoriApp: "JOB",
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
@@ -54,10 +76,10 @@ async function GET(request: Request) {
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
// title: {
|
||||
// contains: search || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
// title: {
|
||||
// contains: search || "",
|
||||
// mode: "insensitive",
|
||||
// },
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
@@ -90,46 +112,46 @@ async function GET(request: Request) {
|
||||
|
||||
fixData = data;
|
||||
} else if (category === "beranda") {
|
||||
const data = await prisma.job.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
authorId: true,
|
||||
MasterStatus: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
const data = await prisma.job.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
isArsip: false,
|
||||
MasterStatus: {
|
||||
name: "Publish",
|
||||
},
|
||||
title: {
|
||||
contains: search || "",
|
||||
mode: "insensitive",
|
||||
},
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
title: true,
|
||||
deskripsi: true,
|
||||
authorId: true,
|
||||
MasterStatus: {
|
||||
select: {
|
||||
name: true,
|
||||
},
|
||||
},
|
||||
Author: {
|
||||
select: {
|
||||
id: true,
|
||||
username: true,
|
||||
Profile: {
|
||||
select: {
|
||||
id: true,
|
||||
name: true,
|
||||
imageId: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
}
|
||||
|
||||
212
src/app/api/mobile/notification/[id]/route.ts
Normal file
212
src/app/api/mobile/notification/[id]/route.ts
Normal file
@@ -0,0 +1,212 @@
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { NotificationProp } from "../route";
|
||||
import { adminMessaging } from "@/lib/firebase-admin";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
let fixData;
|
||||
const fixCategory = _.upperCase(category || "");
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: fixData,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
try {
|
||||
if (category === "one") {
|
||||
await prisma.notifikasi.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
isRead: true,
|
||||
readAt: new Date(),
|
||||
},
|
||||
});
|
||||
} else if (category === "all") {
|
||||
await prisma.notifikasi.updateMany({
|
||||
where: {
|
||||
recipientId: id,
|
||||
},
|
||||
data: {
|
||||
isRead: true,
|
||||
readAt: new Date(),
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notifications marked as read",
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Error marking notifications as read:", error);
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// export async function POST(
|
||||
// request: NextRequest,
|
||||
// { params }: { params: { id: string } }
|
||||
// ) {
|
||||
// const { id } = params;
|
||||
|
||||
// const { data } = await request.json();
|
||||
|
||||
// const {
|
||||
// title,
|
||||
// body: notificationBody,
|
||||
// userLoginId,
|
||||
// type,
|
||||
// kategoriApp,
|
||||
// appId,
|
||||
// status,
|
||||
// deepLink,
|
||||
// } = data as NotificationProp;
|
||||
|
||||
// console.log("Notification Send >>", data);
|
||||
|
||||
// try {
|
||||
// // Cari user yang login
|
||||
// const findUserLogin = await prisma.user.findUnique({
|
||||
// where: {
|
||||
// id: userLoginId,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!findUserLogin) {
|
||||
// return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
// }
|
||||
|
||||
// // Cari token fcm user yang login
|
||||
// const checkFcmToken = await prisma.tokenUserDevice.findFirst({
|
||||
// where: {
|
||||
// userId: findUserLogin.id,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!checkFcmToken) {
|
||||
// return NextResponse.json(
|
||||
// { error: "FCM Token not found" },
|
||||
// { status: 404 }
|
||||
// );
|
||||
// }
|
||||
|
||||
// const created = await prisma.notifikasi.create({
|
||||
// data: {
|
||||
// title,
|
||||
// type,
|
||||
// createdAt: new Date(),
|
||||
// appId,
|
||||
// kategoriApp,
|
||||
// pesan: notificationBody || "",
|
||||
// userRoleId: findUserLogin.masterUserRoleId,
|
||||
// status,
|
||||
// deepLink,
|
||||
// senderId: findUserLogin.id,
|
||||
// recipientId: id,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (created) {
|
||||
// const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
// where: {
|
||||
// userId: id,
|
||||
// isActive: true,
|
||||
// },
|
||||
// });
|
||||
|
||||
// for (let i of deviceToken) {
|
||||
// const message = {
|
||||
// token: i.token,
|
||||
// notification: {
|
||||
// title,
|
||||
// body: notificationBody || "",
|
||||
// },
|
||||
// data: {
|
||||
// sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
// id: created.id,
|
||||
// deepLink: deepLink || "",
|
||||
// },
|
||||
// // Konfigurasi Android untuk prioritas tinggi
|
||||
// android: {
|
||||
// priority: "high" as const, // Kirim secepatnya, bahkan di doze mode untuk notifikasi penting
|
||||
// notification: {
|
||||
// channelId: "default", // Sesuaikan dengan channel yang kamu buat di Android
|
||||
// },
|
||||
|
||||
// ttl: 0 as const, // Kirim secepatnya, jangan tunda
|
||||
// },
|
||||
// // Opsional: tambahkan untuk iOS juga
|
||||
// apns: {
|
||||
// payload: {
|
||||
// aps: {
|
||||
// sound: "default" as const,
|
||||
// // 'content-available': 1 as const, // jika butuh silent push
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// };
|
||||
|
||||
// try {
|
||||
// const response = await adminMessaging.send(message);
|
||||
// console.log("✅ FCM sent successfully", "Response:", response);
|
||||
// } catch (error: any) {
|
||||
// console.error("❌ FCM send failed:", error);
|
||||
// // Lanjutkan ke token berikutnya meski satu gagal
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// return NextResponse.json({
|
||||
// success: true,
|
||||
// message: "Notification sent successfully",
|
||||
// });
|
||||
// } catch (error) {
|
||||
// console.error("❌ FCM error:", error);
|
||||
|
||||
// return NextResponse.json(
|
||||
// { error: (error as Error).message },
|
||||
// { status: 500 }
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
31
src/app/api/mobile/notification/[id]/unread-count/route.ts
Normal file
31
src/app/api/mobile/notification/[id]/unread-count/route.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import { prisma } from "@/lib";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
console.log("User ID:", id);
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.count({
|
||||
where: {
|
||||
recipientId: id,
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
|
||||
console.log("List Notification >>", data);
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
data: data,
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed to get unread count",
|
||||
});
|
||||
}
|
||||
}
|
||||
210
src/app/api/mobile/notification/route.ts
Normal file
210
src/app/api/mobile/notification/route.ts
Normal file
@@ -0,0 +1,210 @@
|
||||
// app/api/test/notifications/route.ts
|
||||
import { prisma } from "@/lib";
|
||||
import { adminMessaging } from "@/lib/firebase-admin";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export type NotificationProp = {
|
||||
title: string;
|
||||
body: string;
|
||||
userLoginId: string;
|
||||
appId?: string;
|
||||
status?: string;
|
||||
kategoriApp?: string;
|
||||
type?: string;
|
||||
deepLink?: string;
|
||||
};
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { data } = await request.json();
|
||||
|
||||
const {
|
||||
title,
|
||||
body: notificationBody,
|
||||
userLoginId,
|
||||
type,
|
||||
kategoriApp,
|
||||
appId,
|
||||
status,
|
||||
deepLink,
|
||||
} = data as NotificationProp;
|
||||
|
||||
console.log("Notification Send >>", data);
|
||||
|
||||
// Cari user yang login
|
||||
const findUserLogin = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userLoginId,
|
||||
},
|
||||
});
|
||||
|
||||
if (!findUserLogin) {
|
||||
return NextResponse.json({ error: "User not found" }, { status: 404 });
|
||||
}
|
||||
|
||||
// Cari token fcm user yang login
|
||||
const checkFcmToken = await prisma.tokenUserDevice.findFirst({
|
||||
where: {
|
||||
userId: findUserLogin.id,
|
||||
},
|
||||
});
|
||||
|
||||
if (!checkFcmToken) {
|
||||
return NextResponse.json(
|
||||
{ error: "FCM Token not found" },
|
||||
{ status: 404 }
|
||||
);
|
||||
}
|
||||
|
||||
// Jika user yang masuk maka notifikasik akan dikirim ke semua admin , begitu sebaliknya !
|
||||
const filterByCurrentLoginId =
|
||||
findUserLogin.masterUserRoleId === "1" ? "2" : "1";
|
||||
|
||||
// Cari user yang akan menerima notifikasi
|
||||
const findAllUserBySendTo = await prisma.user.findMany({
|
||||
where: {
|
||||
masterUserRoleId: filterByCurrentLoginId,
|
||||
NOT: {
|
||||
id: findUserLogin.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
console.log("Find All User By Send To >>", findAllUserBySendTo);
|
||||
|
||||
for (let a of findAllUserBySendTo) {
|
||||
const responseCreatedNotifications = await createNotification({
|
||||
title,
|
||||
type: type as string,
|
||||
createdAt: new Date(),
|
||||
pesan: notificationBody || "",
|
||||
appId: appId as string,
|
||||
kategoriApp: kategoriApp as string,
|
||||
userRoleId: findUserLogin.masterUserRoleId,
|
||||
status: status,
|
||||
deepLink: deepLink,
|
||||
senderId: findUserLogin.id,
|
||||
recipientId: a.id,
|
||||
});
|
||||
|
||||
if (responseCreatedNotifications) {
|
||||
const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
where: {
|
||||
userId: a.id,
|
||||
isActive: true,
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of deviceToken) {
|
||||
const message = {
|
||||
token: i.token,
|
||||
notification: {
|
||||
title,
|
||||
body: notificationBody || "",
|
||||
},
|
||||
data: {
|
||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
id: responseCreatedNotifications.id,
|
||||
deepLink: deepLink || "",
|
||||
// contoh: senderId, type, etc.
|
||||
},
|
||||
// Konfigurasi Android untuk prioritas tinggi
|
||||
android: {
|
||||
priority: "high" as const, // Kirim secepatnya, bahkan di doze mode untuk notifikasi penting
|
||||
notification: {
|
||||
channelId: "default", // Sesuaikan dengan channel yang kamu buat di Android
|
||||
// Opsional: sesuaikan icon & warna
|
||||
// icon: 'ic_notification',
|
||||
// color: '#FFD700',
|
||||
},
|
||||
// FCM akan bangunkan app jika perlu
|
||||
ttl: 0 as const, // Kirim secepatnya, jangan tunda
|
||||
},
|
||||
// Opsional: tambahkan untuk iOS juga
|
||||
apns: {
|
||||
payload: {
|
||||
aps: {
|
||||
sound: "default" as const,
|
||||
// 'content-available': 1 as const, // jika butuh silent push
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
try {
|
||||
const response = await adminMessaging.send(message);
|
||||
console.log(
|
||||
"✅ FCM sent to token:",
|
||||
"Response:",
|
||||
response
|
||||
);
|
||||
} catch (error: any) {
|
||||
console.error("❌ FCM send failed for token:", i.token, error);
|
||||
// Lanjutkan ke token berikutnya meski satu gagal
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Failed to create notification",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notification sent successfully",
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("❌ FCM error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || "Failed to send FCM" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function createNotification({
|
||||
title,
|
||||
type,
|
||||
createdAt,
|
||||
appId,
|
||||
kategoriApp,
|
||||
pesan,
|
||||
userRoleId,
|
||||
status,
|
||||
deepLink,
|
||||
senderId,
|
||||
recipientId,
|
||||
}: {
|
||||
title: string;
|
||||
type: string;
|
||||
createdAt: Date;
|
||||
appId: string;
|
||||
kategoriApp: string;
|
||||
userRoleId: string;
|
||||
status?: string;
|
||||
deepLink?: string;
|
||||
pesan: string;
|
||||
|
||||
senderId: string;
|
||||
recipientId: string;
|
||||
}) {
|
||||
const createNotification = await prisma.notifikasi.create({
|
||||
data: {
|
||||
title,
|
||||
type,
|
||||
createdAt,
|
||||
appId,
|
||||
kategoriApp,
|
||||
pesan,
|
||||
userRoleId,
|
||||
status,
|
||||
deepLink,
|
||||
senderId,
|
||||
recipientId,
|
||||
},
|
||||
});
|
||||
|
||||
return createNotification;
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
// app/api/test/notifications/route.ts
|
||||
import { adminMessaging } from "@/lib/firebase-admin";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const { data } = await request.json();
|
||||
const { fcmToken, title, body: notificationBody, userLoginId } = data;
|
||||
|
||||
console.log("Data Notifikasi >>", data);
|
||||
|
||||
if (!fcmToken || !title) {
|
||||
return NextResponse.json(
|
||||
{ error: "Missing fcmToken or title" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
where: {
|
||||
isActive: true,
|
||||
NOT: {
|
||||
userId: userLoginId,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
for (let i of deviceToken) {
|
||||
const message = {
|
||||
token: i.token,
|
||||
notification: {
|
||||
title,
|
||||
body: notificationBody || "",
|
||||
},
|
||||
data: {
|
||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
// contoh: senderId, type, etc.
|
||||
},
|
||||
};
|
||||
console.log("[MSG]", message);
|
||||
|
||||
const response = await adminMessaging.send(message);
|
||||
console.log("✅ FCM sent:", response);
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notification sent successfully",
|
||||
});
|
||||
} catch (error: any) {
|
||||
console.error("❌ FCM error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: error.message || "Failed to send FCM" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,12 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { sendNotificationMobileToOneUser } from "@/lib/mobile/notification/send-notification";
|
||||
import {
|
||||
NotificationMobileBodyType,
|
||||
NotificationMobileTitleType,
|
||||
} from "../../../../../../types/type-mobile-notification";
|
||||
import { routeUserMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { GET, DELETE, PUT, POST };
|
||||
|
||||
@@ -39,7 +45,6 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
|
||||
const listNamaVote = data?.Voting_DaftarNamaVote || [];
|
||||
|
||||
for (let v of listNamaVote) {
|
||||
|
||||
const kontributor = await prisma.voting_Kontributor.findMany({
|
||||
where: {
|
||||
voting_DaftarNamaVoteId: v.id,
|
||||
@@ -90,7 +95,6 @@ async function DELETE(
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil menghapus data",
|
||||
@@ -171,7 +175,6 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!updateVoting)
|
||||
return NextResponse.json({ status: 400, message: "Gagal Update" });
|
||||
}
|
||||
@@ -193,11 +196,12 @@ async function PUT(request: Request, { params }: { params: { id: string } }) {
|
||||
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
const { chooseId, userId } = data;
|
||||
|
||||
try {
|
||||
const findData = await prisma.voting_DaftarNamaVote.findFirst({
|
||||
const findDatapilihan = await prisma.voting_DaftarNamaVote.findFirst({
|
||||
where: {
|
||||
id: data.chooseId,
|
||||
id: chooseId,
|
||||
},
|
||||
select: {
|
||||
jumlah: true,
|
||||
@@ -205,28 +209,32 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
},
|
||||
});
|
||||
|
||||
if (!findData)
|
||||
if (!findDatapilihan)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Data tidak ditemukan",
|
||||
});
|
||||
|
||||
const updateData = await prisma.voting_DaftarNamaVote.update({
|
||||
const updateDataPilihan = await prisma.voting_DaftarNamaVote.update({
|
||||
where: {
|
||||
id: data.chooseId,
|
||||
},
|
||||
data: {
|
||||
jumlah: findData.jumlah + 1,
|
||||
jumlah: findDatapilihan.jumlah + 1,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!updateData)
|
||||
if (!updateDataPilihan)
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Gagal Update Data",
|
||||
});
|
||||
|
||||
const findVotingData = await prisma.voting.findUnique({
|
||||
where: { id: id },
|
||||
select: { authorId: true, title: true },
|
||||
});
|
||||
|
||||
const createKontributor = await prisma.voting_Kontributor.create({
|
||||
data: {
|
||||
votingId: id,
|
||||
@@ -250,6 +258,21 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
message: "Gagal Menjadi Kontributor",
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
if (userId !== findVotingData?.authorId) {
|
||||
await sendNotificationMobileToOneUser({
|
||||
recipientId: findVotingData?.authorId as string,
|
||||
senderId: userId,
|
||||
payload: {
|
||||
title: "User Melakukan Vote" as NotificationMobileTitleType,
|
||||
body: `Salah satu user telah melakukan voting pada: ${findVotingData?.title}` as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeUserMobile.votingDetailPublised({ id: id }),
|
||||
kategoriApp: "VOTING",
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Berhasil Voting",
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import { NextResponse } from "next/server";
|
||||
import prisma from "@/lib/prisma";
|
||||
import _ from "lodash";
|
||||
import { sendNotificationMobileToManyUser } from "@/lib/mobile/notification/send-notification";
|
||||
import { NotificationMobileBodyType } from "../../../../../types/type-mobile-notification";
|
||||
import { routeAdminMobile } from "@/lib/mobile/route-page-mobile";
|
||||
|
||||
export { POST, GET };
|
||||
|
||||
@@ -41,6 +44,24 @@ async function POST(request: Request) {
|
||||
});
|
||||
}
|
||||
|
||||
const adminUsers = await prisma.user.findMany({
|
||||
where: { masterUserRoleId: "2", NOT: { id: data.authorId } },
|
||||
select: { id: true },
|
||||
});
|
||||
|
||||
// SEND NOTIFICATION
|
||||
await sendNotificationMobileToManyUser({
|
||||
recipientIds: adminUsers.map((user) => user.id),
|
||||
senderId: data.authorId,
|
||||
payload: {
|
||||
title: "Pengajuan Review Baru",
|
||||
body: create.title as NotificationMobileBodyType,
|
||||
type: "announcement",
|
||||
deepLink: routeAdminMobile.votingByStatus({ status: "review" }),
|
||||
kategoriApp: "VOTING",
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
@@ -125,8 +146,6 @@ async function GET(request: Request) {
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
|
||||
|
||||
} else if (category === "contribution") {
|
||||
const data = await prisma.voting_Kontributor.findMany({
|
||||
orderBy: {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
[
|
||||
{
|
||||
"name": "default_user",
|
||||
"name": "demo_user",
|
||||
"nomor": "6282340374412",
|
||||
"masterUserRoleId": "1",
|
||||
"active": true,
|
||||
"termsOfServiceAccepted": false
|
||||
},
|
||||
{
|
||||
"name": "admin_911",
|
||||
"name": "demo_admin",
|
||||
"nomor": "6281339158911",
|
||||
"masterUserRoleId": "3",
|
||||
"active": true,
|
||||
|
||||
119
src/lib/mobile/notification/send-notification.ts
Normal file
119
src/lib/mobile/notification/send-notification.ts
Normal file
@@ -0,0 +1,119 @@
|
||||
// lib/notifications/send-notification.ts
|
||||
import { adminMessaging } from "@/lib/firebase-admin";
|
||||
import prisma from "@/lib/prisma";
|
||||
import { NotificationMobilePayload } from "../../../../types/type-mobile-notification";
|
||||
import _ from "lodash";
|
||||
|
||||
/**
|
||||
* Kirim notifikasi ke satu user (semua device aktifnya)
|
||||
* @param recipientId - ID penerima
|
||||
* @param senderId - ID pengirim
|
||||
* @param payload - Data notifikasi
|
||||
*/
|
||||
|
||||
export async function sendNotificationMobileToOneUser({
|
||||
recipientId,
|
||||
senderId,
|
||||
payload,
|
||||
}: {
|
||||
recipientId: string;
|
||||
senderId: string;
|
||||
payload: NotificationMobilePayload;
|
||||
}) {
|
||||
try {
|
||||
const kategoriToNormalCase = _.lowerCase(payload.kategoriApp);
|
||||
const titleFix =
|
||||
kategoriToNormalCase === "other"
|
||||
? payload.title
|
||||
: `${_.startCase(kategoriToNormalCase)}: ${payload.title}`;
|
||||
console.log("titleFix", titleFix);
|
||||
|
||||
// 1. Simpan notifikasi ke DB
|
||||
const notification = await prisma.notifikasi.create({
|
||||
data: {
|
||||
title: titleFix,
|
||||
pesan: payload.body,
|
||||
deepLink: payload.deepLink,
|
||||
kategoriApp: payload.kategoriApp,
|
||||
recipientId: recipientId,
|
||||
senderId: senderId,
|
||||
type: payload.type.trim(),
|
||||
},
|
||||
});
|
||||
|
||||
// 2. Ambil semua token aktif milik penerima
|
||||
const tokens = await prisma.tokenUserDevice.findMany({
|
||||
where: { userId: recipientId },
|
||||
select: { token: true, id: true },
|
||||
});
|
||||
|
||||
if (tokens.length === 0) {
|
||||
console.warn(`No active tokens found for user ${recipientId}`);
|
||||
return;
|
||||
}
|
||||
|
||||
// 3. Kirim FCM ke semua token
|
||||
await Promise.allSettled(
|
||||
tokens.map(async ({ token, id }) => {
|
||||
try {
|
||||
await adminMessaging.send({
|
||||
token,
|
||||
notification: {
|
||||
title: titleFix,
|
||||
body: payload.body,
|
||||
},
|
||||
data: {
|
||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
id: notification.id,
|
||||
deepLink: payload.deepLink,
|
||||
recipientId: recipientId,
|
||||
},
|
||||
android: {
|
||||
priority: "high" as const,
|
||||
notification: { channelId: "default" },
|
||||
ttl: 0 as const,
|
||||
},
|
||||
apns: {
|
||||
payload: { aps: { sound: "default" as const } },
|
||||
},
|
||||
});
|
||||
} catch (fcmError: any) {
|
||||
// Hapus token jika invalid
|
||||
if (fcmError.code === "messaging/registration-token-not-registered") {
|
||||
// Hapus token dari DB
|
||||
await prisma.tokenUserDevice.delete({ where: { id } });
|
||||
console.log(`🗑️ Invalid token removed: ${id}`);
|
||||
}
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
console.log(`✅ Notification sent to user ${recipientId}`);
|
||||
} catch (error) {
|
||||
console.error("Failed to send notification:", error);
|
||||
throw error; // biarkan caller handle error
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kirim notifikasi ke banyak user
|
||||
*/
|
||||
export async function sendNotificationMobileToManyUser({
|
||||
recipientIds,
|
||||
senderId,
|
||||
payload,
|
||||
}: {
|
||||
recipientIds: string[];
|
||||
senderId: string;
|
||||
payload: NotificationMobilePayload;
|
||||
}) {
|
||||
await Promise.allSettled(
|
||||
recipientIds.map((id) =>
|
||||
sendNotificationMobileToOneUser({
|
||||
recipientId: id,
|
||||
senderId: senderId,
|
||||
payload: payload,
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
46
src/lib/mobile/route-page-mobile.ts
Normal file
46
src/lib/mobile/route-page-mobile.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
export { routeAdminMobile, routeUserMobile };
|
||||
|
||||
type StatusApp = "review" | "draft" | "reject" | "publish";
|
||||
|
||||
const routeAdminMobile = {
|
||||
userAccess: ({ id }: { id: string }) => `/admin/user-access/${id}`,
|
||||
// JOB
|
||||
jobByStatus: ({ status }: { status: StatusApp }) =>
|
||||
`/admin/job/${status}/status`,
|
||||
|
||||
// EVENT
|
||||
eventByStatus: ({ status }: { status: StatusApp }) =>
|
||||
`/admin/event/${status}/status`,
|
||||
|
||||
// VOTING
|
||||
votingByStatus: ({ status }: { status: StatusApp }) =>
|
||||
`/admin/voting/${status}/status`,
|
||||
|
||||
// FORUM
|
||||
forumPreviewReportPosting: `/admin/forum/report-posting`,
|
||||
forumPreviewReportComment: `/admin/forum/report-comment`,
|
||||
};
|
||||
|
||||
const routeUserMobile = {
|
||||
home: `/(user)/home`,
|
||||
// JOB
|
||||
jobByStatus: ({ status }: { status?: StatusApp }) =>
|
||||
`/job/(tabs)/status?status=${status}`,
|
||||
jobDetailPublised: ({ id }: { id: string }) => `/job/${id}`,
|
||||
|
||||
// EVENT
|
||||
eventByStatus: ({ status }: { status?: StatusApp }) =>
|
||||
`/event/(tabs)/status?status=${status}`,
|
||||
eventDetailPublised: ({ id }: { id: string }) => `/event/${id}/publish`,
|
||||
|
||||
// VOTING
|
||||
votingByStatus: ({ status }: { status?: StatusApp }) =>
|
||||
`/voting/(tabs)/status?status=${status}`,
|
||||
votingDetailPublised: ({ id }: { id: string }) => `/voting/${id}`,
|
||||
|
||||
// FORUM
|
||||
forumBeranda: `/forum`,
|
||||
forumDetail: ({ id }: { id: string }) => `/forum/${id}`,
|
||||
forumPreviewReportPosting: ({ id }: { id: string }) => `/forum/${id}/preview-report-posting`,
|
||||
forumPreviewReportComment: ({ id }: { id: string }) => `/forum/${id}/preview-report-comment`,
|
||||
};
|
||||
@@ -23,6 +23,6 @@
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app_modules/investasi/proses_transaksi/view.jsx", "src/app/api/investasi/midtrans/[id]/route.ts", "src/app_modules/job/create/TextEdit.tsx", "src/app/api/mobile/forum/[id]/report-comment/route.ts"],
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "src/app_modules/investasi/proses_transaksi/view.jsx", "src/app/api/investasi/midtrans/[id]/route.ts", "src/app_modules/job/create/TextEdit.tsx", "src/app/api/mobile/forum/[id]/report-comment-del-soon/route.ts"],
|
||||
"exclude": ["node_modules"]
|
||||
}
|
||||
|
||||
40
types/type-mobile-notification.ts
Normal file
40
types/type-mobile-notification.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
// Jika semua custom type diawali "custom_"
|
||||
|
||||
export type NotificationMobilePayload = {
|
||||
title: NotificationMobileTitleType;
|
||||
body: NotificationMobileBodyType;
|
||||
userLoginId?: string;
|
||||
appId?: string;
|
||||
status?: string;
|
||||
type: "announcement" | "trigger";
|
||||
deepLink: string;
|
||||
kategoriApp: TypeNotificationCategoryApp;
|
||||
};
|
||||
|
||||
export type NotificationMobileTitleType =
|
||||
| (string & { __type: "NotificationMobileTitleType" })
|
||||
// Admin
|
||||
| "Pengajuan Review Baru"
|
||||
// USER
|
||||
| "Pengajuan Review Ditolak"
|
||||
| "Review Selesai"
|
||||
// to ALL user
|
||||
|
||||
export type NotificationMobileBodyType =
|
||||
// USER
|
||||
| (string & { __type: "NotificationMobileBodyType" })
|
||||
| "Ada pengajuan review" // tambah title
|
||||
|
||||
// ADMIN
|
||||
| "Mohon perbaiki data sesuai catatan penolakan !"
|
||||
| "Selamat data anda telah terpublikasi"
|
||||
|
||||
export type TypeNotificationCategoryApp =
|
||||
| "EVENT"
|
||||
| "JOB"
|
||||
| "VOTING"
|
||||
| "DONASI"
|
||||
| "INVESTASI"
|
||||
| "COLLABORATION"
|
||||
| "FORUM"
|
||||
| "OTHER";
|
||||
7
x.sh
7
x.sh
@@ -3,10 +3,13 @@ URL="http://localhost:3000"
|
||||
# curl -X GET -H "Authorization: Bearer $TOKEN" ${URL}/api/middleware
|
||||
# curl -X GET -H "Cookie: hipmi-key=$TOKEN; user_id=789" ${URL}/dev/home | tee test.html
|
||||
|
||||
curl -X POST ${URL}/api/mobile/notifications \
|
||||
curl -X POST ${URL}/api/mobile/notification \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"fcmToken": "cVmHm-3P4E-1vjt6AA9kSF:APA91bHTkHjGTLxrFsb6Le6bZmzboZhwMGYXU4p0FP9yEeXixLDXNKS4F5vLuZV3sRgSnjjQsPpLOgstVLHJB8VJTObctKLdN-CxAp4dnP7Jbc_mH53jWvs",
|
||||
"title": "Test dari Backend (App Router)!",
|
||||
"body": "Berhasil di App Router!"
|
||||
"body": "Berhasil di App Router!",
|
||||
"userLoginId": "cmha7p6yc0000cfoe5w2e7gdr",
|
||||
"type": "NOTIFICATION",
|
||||
"kategoriApp": "PERCOBAAN"
|
||||
}'
|
||||
Reference in New Issue
Block a user