Compare commits
2 Commits
mobile-not
...
mobile-not
| Author | SHA1 | Date | |
|---|---|---|---|
| d50fda90e0 | |||
| d3d4912a5f |
@@ -2,6 +2,8 @@
|
||||
|
||||
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.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,6 +1,6 @@
|
||||
{
|
||||
"name": "hipmi",
|
||||
"version": "1.5.30",
|
||||
"version": "1.5.31",
|
||||
"private": true,
|
||||
"prisma": {
|
||||
"seed": "bun prisma/seed.ts"
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { prisma } from "@/lib";
|
||||
import _ from "lodash";
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
|
||||
export async function GET(
|
||||
@@ -8,33 +9,22 @@ export async function GET(
|
||||
const { id } = params;
|
||||
const { searchParams } = new URL(request.url);
|
||||
const category = searchParams.get("category");
|
||||
|
||||
let fixData;
|
||||
const fixCategory = _.upperCase(category || "");
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
orderBy: {
|
||||
createdAt: "desc",
|
||||
},
|
||||
where: {
|
||||
recipientId: id,
|
||||
kategoriApp: fixCategory,
|
||||
},
|
||||
});
|
||||
|
||||
if (category === "count-as-unread") {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
where: {
|
||||
userId: id,
|
||||
isRead: false,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data.length;
|
||||
} else if (category === "all") {
|
||||
const data = await prisma.notifikasi.findMany({
|
||||
where: {
|
||||
userId: id,
|
||||
},
|
||||
});
|
||||
|
||||
fixData = data;
|
||||
} else {
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: "Invalid category",
|
||||
});
|
||||
}
|
||||
fixData = data;
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
@@ -47,3 +37,31 @@ export async function GET(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
request: NextRequest,
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
|
||||
try {
|
||||
await prisma.notifikasi.update({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
data: {
|
||||
isRead: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notifications marked as read",
|
||||
});
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{ error: (error as Error).message },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ export async function GET(
|
||||
{ params }: { params: { id: string } }
|
||||
) {
|
||||
const { id } = params;
|
||||
console.log("User ID:", id);
|
||||
|
||||
try {
|
||||
const data = await prisma.notifikasi.count({
|
||||
@@ -28,7 +29,3 @@ export async function GET(
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
type Pilihan = "PENGIRIM" | "PENERIMA";
|
||||
|
||||
const data: Pilihan = "PENERIMA";
|
||||
|
||||
@@ -12,7 +12,6 @@ type NotificationProp = {
|
||||
kategoriApp?: string;
|
||||
type?: string;
|
||||
deepLink?: string;
|
||||
// sendTo: "user" | "admin" | "all";
|
||||
};
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
@@ -28,7 +27,6 @@ export async function POST(request: NextRequest) {
|
||||
appId,
|
||||
status,
|
||||
deepLink,
|
||||
// sendTo,
|
||||
} = data as NotificationProp;
|
||||
|
||||
console.log("Notification Send >>", data);
|
||||
@@ -75,7 +73,7 @@ export async function POST(request: NextRequest) {
|
||||
console.log("Find All User By Send To >>", findAllUserBySendTo);
|
||||
|
||||
for (let a of findAllUserBySendTo) {
|
||||
const responseCreateToAdmin = await createNotification({
|
||||
const responseCreatedNotifications = await createNotification({
|
||||
title,
|
||||
type: type as string,
|
||||
createdAt: new Date(),
|
||||
@@ -89,14 +87,11 @@ export async function POST(request: NextRequest) {
|
||||
recipientId: a.id,
|
||||
});
|
||||
|
||||
if (responseCreateToAdmin) {
|
||||
if (responseCreatedNotifications) {
|
||||
const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
where: {
|
||||
userId: a.id,
|
||||
isActive: true,
|
||||
// user: {
|
||||
// masterUserRoleId: "2",
|
||||
// },
|
||||
},
|
||||
});
|
||||
|
||||
@@ -109,6 +104,8 @@ export async function POST(request: NextRequest) {
|
||||
},
|
||||
data: {
|
||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||
id: responseCreatedNotifications.id,
|
||||
deepLink: deepLink || "",
|
||||
// contoh: senderId, type, etc.
|
||||
},
|
||||
};
|
||||
@@ -124,193 +121,6 @@ export async function POST(request: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// if (sendTo === "admin") {
|
||||
// for (let a of findAllUserBySendTo) {
|
||||
// const responseCreateToAdmin = 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,
|
||||
// adminId: a.id,
|
||||
// userId: findUserLogin.id,
|
||||
// });
|
||||
|
||||
// if (responseCreateToAdmin) {
|
||||
// const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
// where: {
|
||||
// userId: a.id,
|
||||
// isActive: true,
|
||||
// // user: {
|
||||
// // masterUserRoleId: "2",
|
||||
// // },
|
||||
// },
|
||||
// });
|
||||
|
||||
// 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.
|
||||
// },
|
||||
// };
|
||||
|
||||
// const response = await adminMessaging.send(message);
|
||||
// console.log("✅ FCM sent:", response);
|
||||
// }
|
||||
// } else {
|
||||
// return NextResponse.json({
|
||||
// success: false,
|
||||
// message: "Failed to create notification",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else if (sendTo === "user") {
|
||||
// for (let a of findAllUserBySendTo) {
|
||||
// const responseCreateToUser = 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,
|
||||
// adminId: findUserLogin.id,
|
||||
// userId: a.id,
|
||||
// });
|
||||
|
||||
// if (responseCreateToUser) {
|
||||
// const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
// where: {
|
||||
// userId: a.id,
|
||||
// isActive: true,
|
||||
// // user: {
|
||||
// // masterUserRoleId: "1",
|
||||
// // },
|
||||
// },
|
||||
// });
|
||||
|
||||
// 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.
|
||||
// },
|
||||
// };
|
||||
|
||||
// const response = await adminMessaging.send(message);
|
||||
// console.log("✅ FCM sent:", response);
|
||||
// }
|
||||
// } else {
|
||||
// return NextResponse.json({
|
||||
// success: false,
|
||||
// message: "Failed to create notification",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// return NextResponse.json({
|
||||
// success: false,
|
||||
// message: "Invalid ' to ' value",
|
||||
// });
|
||||
// }
|
||||
|
||||
// ================== BATAS ================== //
|
||||
// const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||
// where: {
|
||||
// isActive: true,
|
||||
// NOT: {
|
||||
// userId: findUserLogin.id,
|
||||
// },
|
||||
// user: {
|
||||
// masterUserRoleId: "1",
|
||||
// },
|
||||
// },
|
||||
// include: {
|
||||
// user: true,
|
||||
// },
|
||||
// });
|
||||
|
||||
// console.log("Device Token >>", deviceToken);
|
||||
|
||||
// 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.
|
||||
// },
|
||||
// };
|
||||
|
||||
// if (i.user?.masterUserRoleId === "1") {
|
||||
// const responseCreate = await createNotification({
|
||||
// title,
|
||||
// type: type as string,
|
||||
// createdAt: message.data.sentAt,
|
||||
// pesan: notificationBody || "",
|
||||
// appId: appId as string,
|
||||
// kategoriApp: kategoriApp as string,
|
||||
// userRoleId: findUserLogin.masterUserRoleId,
|
||||
// userId: findUserLogin.id,
|
||||
// status: status,
|
||||
// deepLink: deepLink,
|
||||
// });
|
||||
|
||||
// if (responseCreate) {
|
||||
// const response = await adminMessaging.send(message);
|
||||
// console.log("✅ FCM sent:", response);
|
||||
// } else {
|
||||
// return NextResponse.json({
|
||||
// success: false,
|
||||
// message: "Failed to create notification",
|
||||
// });
|
||||
// }
|
||||
// } else {
|
||||
// const responseCreate = await createNotification({
|
||||
// title: title,
|
||||
// type: type as string,
|
||||
// createdAt: message.data.sentAt,
|
||||
// pesan: notificationBody || "",
|
||||
// appId: appId as string,
|
||||
// kategoriApp: kategoriApp as string,
|
||||
// userRoleId: findUserLogin.masterUserRoleId,
|
||||
// adminId: findUserLogin.id,
|
||||
// status: status,
|
||||
// deepLink: deepLink,
|
||||
// });
|
||||
|
||||
// if (responseCreate) {
|
||||
// const response = await adminMessaging.send(message);
|
||||
// console.log("✅ FCM sent:", response);
|
||||
// } else {
|
||||
// return NextResponse.json({
|
||||
// success: false,
|
||||
// message: "Failed to create notification",
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: "Notification sent successfully",
|
||||
@@ -334,7 +144,6 @@ async function createNotification({
|
||||
userRoleId,
|
||||
status,
|
||||
deepLink,
|
||||
|
||||
senderId,
|
||||
recipientId,
|
||||
}: {
|
||||
@@ -362,7 +171,6 @@ async function createNotification({
|
||||
userRoleId,
|
||||
status,
|
||||
deepLink,
|
||||
|
||||
senderId,
|
||||
recipientId,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user