Fix notifikasi
Deskripsi: - Fix notifikasi investasi
This commit is contained in:
@@ -8,6 +8,10 @@ import notifikasi_countUserNotifikasi from "../../fun/count/fun_count_by_id";
|
||||
import notifikasi_funUpdateIsReadById from "../../fun/update/fun_update_is_read_by_user_id";
|
||||
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global";
|
||||
import { notifikasi_funInvestasiCheckStatus } from "../../fun/check/fun_check_investasi_status";
|
||||
import {
|
||||
notifikasi_funGetStatusTransaksiById,
|
||||
notifikasi_funInvestasiChecInvestaorStatus,
|
||||
} from "../../fun";
|
||||
|
||||
export async function redirectInvestasiPage({
|
||||
appId,
|
||||
@@ -29,25 +33,22 @@ export async function redirectInvestasiPage({
|
||||
onLoadCountNtf(val: number): void;
|
||||
}) {
|
||||
const check = await notifikasi_funInvestasiCheckStatus({ id: appId });
|
||||
const checkInvestor = await notifikasi_funInvestasiChecInvestaorStatus({
|
||||
id: appId,
|
||||
});
|
||||
|
||||
console.log("check", check);
|
||||
console.log("check investor:", checkInvestor);
|
||||
|
||||
if (check.status == 200) {
|
||||
// const loadListNotifikasi = await notifikasi_getByUserId({
|
||||
// page: 1,
|
||||
// kategoriApp: categoryPage as any,
|
||||
// });
|
||||
// onLoadDataEvent(loadListNotifikasi);
|
||||
|
||||
// const loadCountNotifikasi = await notifikasi_countUserNotifikasi();
|
||||
// onLoadCountNtf(loadCountNotifikasi);
|
||||
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
});
|
||||
|
||||
if (updateReadNotifikasi.status == 200) {
|
||||
onSetVisible(true);
|
||||
|
||||
onSetMenuId(1);
|
||||
|
||||
if (check.statusName == "publish") {
|
||||
router.push(`/dev/investasi/detail/${appId}`, { scroll: false });
|
||||
} else {
|
||||
@@ -55,6 +56,25 @@ export async function redirectInvestasiPage({
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
}
|
||||
} else if (checkInvestor.status == 200) {
|
||||
const updateReadNotifikasi = await notifikasi_funUpdateIsReadById({
|
||||
notifId: dataId,
|
||||
});
|
||||
|
||||
if (updateReadNotifikasi.status == 200) {
|
||||
onSetVisible(true);
|
||||
onSetMenuId(1);
|
||||
|
||||
if (checkInvestor.statusName == "berhasil") {
|
||||
const path = `/dev/investasi/detail/saham/${appId}`;
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
|
||||
if (checkInvestor.statusName == "gagal") {
|
||||
const path = `/dev/investasi/status-transaksi/gagal/${appId}`;
|
||||
router.push(path, { scroll: false });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ComponentGlobal_NotifikasiPeringatan("Status tidak ditemukan");
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ export async function notifikasi_funInvestasiCheckStatus({
|
||||
message: "Investasi tidak ditemukan",
|
||||
statusName: "",
|
||||
};
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil di cek",
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
"use server";
|
||||
|
||||
import { prisma } from "@/app/lib";
|
||||
import _ from "lodash";
|
||||
|
||||
export async function notifikasi_funInvestasiChecInvestaorStatus({
|
||||
id,
|
||||
}: {
|
||||
id: string;
|
||||
}) {
|
||||
const data = await prisma.investasi_Invoice.findUnique({
|
||||
where: {
|
||||
id: id,
|
||||
},
|
||||
select: {
|
||||
StatusInvoice: true,
|
||||
},
|
||||
});
|
||||
|
||||
if (!data)
|
||||
return {
|
||||
status: 400,
|
||||
message: "Investasi tidak ditemukan",
|
||||
statusName: "",
|
||||
};
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
message: "Berhasil di cek",
|
||||
statusName: _.lowerCase(data.StatusInvoice?.name),
|
||||
};
|
||||
}
|
||||
@@ -2,23 +2,29 @@
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
import { MODEL_NOTIFIKASI } from "../../model/interface";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
|
||||
export default async function notifikasiToUser_funCreate({
|
||||
data,
|
||||
}: {
|
||||
data: MODEL_NOTIFIKASI;
|
||||
}) {
|
||||
const created = await prisma.notifikasi.create({
|
||||
data: {
|
||||
userId: data.userId,
|
||||
appId: data.appId,
|
||||
status: data.status,
|
||||
title: data.title,
|
||||
pesan: data.pesan,
|
||||
kategoriApp: data.kategoriApp,
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
if (!created) return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
return { status: 201, message: "Berhasil mengirim notifikasi" };
|
||||
try {
|
||||
const created = await prisma.notifikasi.create({
|
||||
data: {
|
||||
userId: data.userId,
|
||||
appId: data.appId,
|
||||
status: data.status,
|
||||
title: data.title,
|
||||
pesan: data.pesan,
|
||||
kategoriApp: data.kategoriApp,
|
||||
userRoleId: "1",
|
||||
},
|
||||
});
|
||||
if (!created) return { status: 400, message: "Gagal mengirim notifikasi" };
|
||||
return { status: 201, message: "Berhasil mengirim notifikasi" };
|
||||
} catch (error) {
|
||||
backendLogger.error("Gagal mengirim notifikasi", error);
|
||||
return { status: 401, message: "Error server" };
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
"use server";
|
||||
|
||||
import prisma from "@/app/lib/prisma";
|
||||
|
||||
export default async function notifikasi_funGetStatusTransaksiById({
|
||||
notifId,
|
||||
}: {
|
||||
notifId: string;
|
||||
}) {
|
||||
const data = await prisma.notifikasi.findFirst({
|
||||
where: {
|
||||
id: notifId,
|
||||
},
|
||||
select: {
|
||||
status: true,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
if (!data) return { status: 400 };
|
||||
return { status: 200, data: data };
|
||||
}
|
||||
@@ -1,11 +1,15 @@
|
||||
import { notifikasi_funEventCheckStatus } from "./check/fun_check_event_status";
|
||||
import { notifikasi_funInvestasiChecInvestaorStatus } from "./check/fun_check_investor_status";
|
||||
import notifikasiToAdmin_funCreate from "./create/create_notif_to_admin";
|
||||
import notifikasiToUser_funCreate from "./create/create_notif_to_user";
|
||||
import { notifikasiToUser_CreateGroupCollaboration } from "./create/create_notif_to_user_collaboration";
|
||||
import { notifikasiToUser_CreateKabarDonasi } from "./create/create_notif_to_user_kabar_donasi";
|
||||
import notifikasi_funGetStatusTransaksiById from "./get/fun_get_status_transaksi";
|
||||
|
||||
export { notifikasiToAdmin_funCreate };
|
||||
export { notifikasiToUser_CreateGroupCollaboration };
|
||||
export { notifikasiToUser_CreateKabarDonasi };
|
||||
export { notifikasiToUser_funCreate };
|
||||
export { notifikasi_funEventCheckStatus };
|
||||
export { notifikasi_funGetStatusTransaksiById };
|
||||
export { notifikasi_funInvestasiChecInvestaorStatus };
|
||||
|
||||
Reference in New Issue
Block a user