Compare commits
3 Commits
mobile-not
...
v1.5.32
| Author | SHA1 | Date | |
|---|---|---|---|
| 94a545bd30 | |||
| d50fda90e0 | |||
| d3d4912a5f |
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
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.
|
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.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.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.29](https://wibugit.wibudev.com/wibu/hipmi/compare/v1.5.28...v1.5.29) (2025-12-17)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "hipmi",
|
"name": "hipmi",
|
||||||
"version": "1.5.30",
|
"version": "1.5.32",
|
||||||
"private": true,
|
"private": true,
|
||||||
"prisma": {
|
"prisma": {
|
||||||
"seed": "bun prisma/seed.ts"
|
"seed": "bun prisma/seed.ts"
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { prisma } from "@/lib";
|
import { prisma } from "@/lib";
|
||||||
|
import _ from "lodash";
|
||||||
import { NextRequest, NextResponse } from "next/server";
|
import { NextRequest, NextResponse } from "next/server";
|
||||||
|
|
||||||
export async function GET(
|
export async function GET(
|
||||||
@@ -9,32 +10,21 @@ export async function GET(
|
|||||||
const { searchParams } = new URL(request.url);
|
const { searchParams } = new URL(request.url);
|
||||||
const category = searchParams.get("category");
|
const category = searchParams.get("category");
|
||||||
|
|
||||||
|
let fixData;
|
||||||
|
const fixCategory = _.upperCase(category || "");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
let fixData;
|
const data = await prisma.notifikasi.findMany({
|
||||||
|
orderBy: {
|
||||||
|
createdAt: "desc",
|
||||||
|
},
|
||||||
|
where: {
|
||||||
|
recipientId: id,
|
||||||
|
kategoriApp: fixCategory,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
if (category === "count-as-unread") {
|
fixData = data;
|
||||||
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",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return NextResponse.json({
|
return NextResponse.json({
|
||||||
success: true,
|
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 } }
|
{ params }: { params: { id: string } }
|
||||||
) {
|
) {
|
||||||
const { id } = params;
|
const { id } = params;
|
||||||
|
console.log("User ID:", id);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await prisma.notifikasi.count({
|
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;
|
kategoriApp?: string;
|
||||||
type?: string;
|
type?: string;
|
||||||
deepLink?: string;
|
deepLink?: string;
|
||||||
// sendTo: "user" | "admin" | "all";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function POST(request: NextRequest) {
|
export async function POST(request: NextRequest) {
|
||||||
@@ -28,7 +27,6 @@ export async function POST(request: NextRequest) {
|
|||||||
appId,
|
appId,
|
||||||
status,
|
status,
|
||||||
deepLink,
|
deepLink,
|
||||||
// sendTo,
|
|
||||||
} = data as NotificationProp;
|
} = data as NotificationProp;
|
||||||
|
|
||||||
console.log("Notification Send >>", data);
|
console.log("Notification Send >>", data);
|
||||||
@@ -75,7 +73,7 @@ export async function POST(request: NextRequest) {
|
|||||||
console.log("Find All User By Send To >>", findAllUserBySendTo);
|
console.log("Find All User By Send To >>", findAllUserBySendTo);
|
||||||
|
|
||||||
for (let a of findAllUserBySendTo) {
|
for (let a of findAllUserBySendTo) {
|
||||||
const responseCreateToAdmin = await createNotification({
|
const responseCreatedNotifications = await createNotification({
|
||||||
title,
|
title,
|
||||||
type: type as string,
|
type: type as string,
|
||||||
createdAt: new Date(),
|
createdAt: new Date(),
|
||||||
@@ -89,14 +87,11 @@ export async function POST(request: NextRequest) {
|
|||||||
recipientId: a.id,
|
recipientId: a.id,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (responseCreateToAdmin) {
|
if (responseCreatedNotifications) {
|
||||||
const deviceToken = await prisma.tokenUserDevice.findMany({
|
const deviceToken = await prisma.tokenUserDevice.findMany({
|
||||||
where: {
|
where: {
|
||||||
userId: a.id,
|
userId: a.id,
|
||||||
isActive: true,
|
isActive: true,
|
||||||
// user: {
|
|
||||||
// masterUserRoleId: "2",
|
|
||||||
// },
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -109,6 +104,8 @@ export async function POST(request: NextRequest) {
|
|||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
sentAt: new Date().toISOString(), // ✅ Simpan metadata di data
|
||||||
|
id: responseCreatedNotifications.id,
|
||||||
|
deepLink: deepLink || "",
|
||||||
// contoh: senderId, type, etc.
|
// 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({
|
return NextResponse.json({
|
||||||
success: true,
|
success: true,
|
||||||
message: "Notification sent successfully",
|
message: "Notification sent successfully",
|
||||||
@@ -334,7 +144,6 @@ async function createNotification({
|
|||||||
userRoleId,
|
userRoleId,
|
||||||
status,
|
status,
|
||||||
deepLink,
|
deepLink,
|
||||||
|
|
||||||
senderId,
|
senderId,
|
||||||
recipientId,
|
recipientId,
|
||||||
}: {
|
}: {
|
||||||
@@ -362,7 +171,6 @@ async function createNotification({
|
|||||||
userRoleId,
|
userRoleId,
|
||||||
status,
|
status,
|
||||||
deepLink,
|
deepLink,
|
||||||
|
|
||||||
senderId,
|
senderId,
|
||||||
recipientId,
|
recipientId,
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user