Compare commits

..

33 Commits

Author SHA1 Message Date
d09e30c049 Voting notifikasi for mobile
Fix:
- src/app/api/mobile/admin/voting/[id]/route.ts
- src/app/api/mobile/event/route.ts
- src/app/api/mobile/voting/[id]/route.ts
- src/app/api/mobile/voting/route.ts
- src/lib/mobile/route-page-mobile.ts

### No Issue
2026-01-15 17:38:33 +08:00
c8bd928c33 Fix notifikasi join dari event
Fix:
 modified:   src/app/api/mobile/event/[id]/participants/route.ts
        modified:   src/bin/seeder/user_seeder.json

### No Issue
2026-01-15 13:57:00 +08:00
3a558cec8e chore(release): 1.5.36 2026-01-13 17:45:58 +08:00
b9354cb6bf Penerapan notifikasi pada event
Fix:
- src/app/api/mobile/admin/event/[id]/route.ts
- src/app/api/mobile/admin/job/[id]/route.ts
- src/app/api/mobile/event/route.ts
- src/app/api/mobile/job/route.ts
- src/app/api/mobile/notification/[id]/route.ts
- src/lib/mobile/notification/send-notification.ts
- src/lib/mobile/route-page-mobile.ts
- types/type-mobile-notification.ts

### No Issue
2026-01-13 17:45:37 +08:00
7cdde6b5a9 chore(release): 1.5.35 2026-01-12 17:35:50 +08:00
e77e5eb3ac Fix notification reuse component
Fix:
- modified:   src/app/api/auth/mobile-register/route.ts
- modified:   src/lib/mobile/notification/send-notification.ts

### No Issue
2026-01-12 17:35:27 +08:00
8f3f27122a chore(release): 1.5.34 2026-01-09 17:45:54 +08:00
d84a1d84ff Fix route untuk penambahan fitur EULA
Fix:
- modified:   src/app/api/auth/mobile-login/route.ts

Add:
- src/app/api/auth/mobile-eula/

### No Issue
2026-01-09 17:45:44 +08:00
40ba31edec Fix mobile notification:
- Bug penerima pesan 2 kali

Fix:
modified:   src/lib/mobile/notification/send-notification.ts

### No Issue
2026-01-09 14:42:45 +08:00
a54f8599b4 API Mobile notifikasi job
Fix:
modified:   src/app/api/mobile/admin/job/[id]/route.ts
modified:   src/app/api/mobile/job/[id]/route.ts
modified:   src/app/api/mobile/job/route.ts
modified:   src/lib/mobile/route-page-mobile.ts
modified:   types/type-mobile-notification.ts

### No Issue
2026-01-08 18:35:32 +08:00
09825756f3 Merge branch 'mobile-notification/7-jan-26' of https://wibugit.wibudev.com/wibu/hipmi into mobile-notification/8-jan-26 2026-01-08 10:35:49 +08:00
2086692897 Fix API notifikasi untuk job
### No Issue
2026-01-08 10:14:35 +08:00
87515ae19f Notifikasi mobile job
Add:
 src/lib/mobile/
 types/type-mobile-notification.ts

Fix:
src/app/api/auth/mobile-register/route.ts
src/app/api/mobile/job/route.ts

### No Issue
2026-01-06 17:52:28 +08:00
44d6788f6e chore(release): 1.5.33 2026-01-06 12:24:28 +08:00
ac634100b5 Notifikasi ke admin untuk user baru mendaftar
Fix:

- prisma/schema.prisma
- src/app/api/auth/mobile-register/route.ts
- src/app/api/mobile/admin/user/[id]/route.ts
- src/app/api/mobile/notification/[id]/route.ts
- src/app/api/mobile/notification/route.ts

Add:
Migrasi untuk db table notifikasi
- prisma/migrations/20260105064508_fix_table_notifikasi_optional_data/

### No Issue
2026-01-06 12:20:12 +08:00
1b206102b0 Fix API Notifikasi
### No Issue
2026-01-05 14:04:08 +08:00
94a545bd30 chore(release): 1.5.32 2026-01-05 12:37:14 +08:00
3552cf4f39 Merge pull request 'mobile-notification API' (#36) from mobile-notification/24-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/36
2025-12-24 17:48:07 +08:00
d207b6feed Merge pull request 'Penerapan notifikasi mobile' (#35) from mobile-notification/19-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/35
2025-12-19 16:40:09 +08:00
f1c8432fdc Merge pull request 'Fix DB table donasi' (#33) from login-api/17-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/33
2025-12-17 14:44:53 +08:00
1cd4c3713e Merge pull request 'login-api/17-dec-25' (#31) from login-api/17-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/31
2025-12-17 11:43:32 +08:00
4307b383e3 Merge pull request 'Penerapan notifikasi mobil ke database' (#30) from mobile-notification/16-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/30
2025-12-16 17:57:21 +08:00
0786d23336 Merge pull request 'API notif dan penambahan package firebase-admin' (#29) from mobile-notification/15-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/29
2025-12-15 17:52:03 +08:00
cb3511f973 Merge pull request 'Fix QC ( Ayu )' (#28) from qc-mobile/10-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/28
2025-12-10 17:38:42 +08:00
b4921c4e82 Merge pull request 'Fix API untuk QC: Ayu' (#27) from qc-mobile/9-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/27
2025-12-09 17:40:20 +08:00
a9325054eb Merge pull request 'Fix Apple Reject' (#26) from qc-mobile/8-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/26
2025-12-08 15:33:58 +08:00
819812149f Merge pull request 'Fix QC Admin ( Inno )' (#25) from qc-mobile/5-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/25
2025-12-05 17:15:53 +08:00
75ba2b29ae Merge pull request 'Fix QC Inno:' (#24) from mobile-reject/4-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/24
2025-12-04 17:45:04 +08:00
54a4d15bdd Merge pull request 'Fix WA Server' (#23) from mobile-reject/3-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/23
2025-12-03 16:28:09 +08:00
1321f33da9 Merge pull request 'Fix Apple Rejected' (#22) from mobile-reject/3-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/22
2025-12-03 15:02:40 +08:00
fad0c33b9a Merge pull request 'Alur autentikasi dirubah' (#21) from mobile-reject/2-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/21
2025-12-02 14:41:44 +08:00
565bab4998 Merge pull request 'QC Mobile: Pak jun dan Inno' (#20) from qc/1-dec-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/20
2025-12-01 17:44:48 +08:00
7530a38c4d Merge pull request 'Fix version' (#19) from apple-reject/28-nov-25 into staging
Reviewed-on: http://wibugit.wibudev.com/wibu/hipmi/pulls/19
2025-11-28 11:47:44 +08:00
23 changed files with 848 additions and 103 deletions

View File

@@ -2,6 +2,16 @@
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)

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.5.31",
"version": "1.5.36",
"private": true,
"prisma": {
"seed": "bun prisma/seed.ts"

View File

@@ -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;

View File

@@ -982,9 +982,9 @@ model Notifikasi {
isActive Boolean @default(true)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
appId String
kategoriApp String
pesan String
appId String?
kategoriApp String?
pesan String?
title String?
status String?

View 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 }
);
}
}

View File

@@ -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 }
);

View File

@@ -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 }

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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({

View File

@@ -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;
}

View File

@@ -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,

View File

@@ -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,

View File

@@ -13,6 +13,7 @@ async function GET(request: Request, { params }: { params: { id: string } }) {
include: {
Author: {
select: {
id: true,
username: true,
nomor: true,
Profile: {

View File

@@ -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;
}

View File

@@ -1,6 +1,8 @@
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,
@@ -9,7 +11,7 @@ export async function GET(
const { id } = params;
const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
let fixData;
const fixCategory = _.upperCase(category || "");
@@ -43,25 +45,168 @@ export async function PUT(
{ params }: { params: { id: string } }
) {
const { id } = params;
const { searchParams } = new URL(request.url);
const category = searchParams.get("category");
try {
await prisma.notifikasi.update({
where: {
id: id,
},
data: {
isRead: true,
},
});
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 }
// );
// }
// }

View File

@@ -3,7 +3,7 @@ import { prisma } from "@/lib";
import { adminMessaging } from "@/lib/firebase-admin";
import { NextRequest, NextResponse } from "next/server";
type NotificationProp = {
export type NotificationProp = {
title: string;
body: string;
userLoginId: string;
@@ -108,10 +108,40 @@ export async function POST(request: NextRequest) {
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
},
},
},
};
const response = await adminMessaging.send(message);
console.log("✅ FCM sent:", response);
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({

View File

@@ -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",

View File

@@ -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: {

View File

@@ -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,

View 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,
})
)
);
}

View File

@@ -0,0 +1,36 @@
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`,
};
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}`,
};

View 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";