Merge pull request #349 from bipproduction/bagas/28-feb-25

fix version
This commit is contained in:
Bagasbanuna02
2025-02-28 17:16:52 +08:00
committed by GitHub
6 changed files with 227 additions and 24 deletions

View File

@@ -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. 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.2.69](https://github.com/bipproduction/hipmi/compare/v1.2.68...v1.2.69) (2025-02-28)
## [1.2.68](https://github.com/bipproduction/hipmi/compare/v1.2.67...v1.2.68) (2025-02-28) ## [1.2.68](https://github.com/bipproduction/hipmi/compare/v1.2.67...v1.2.68) (2025-02-28)
## [1.2.67](https://github.com/bipproduction/hipmi/compare/v1.2.66...v1.2.67) (2025-02-27) ## [1.2.67](https://github.com/bipproduction/hipmi/compare/v1.2.66...v1.2.67) (2025-02-27)

View File

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

View File

@@ -1,21 +1,182 @@
import backendLogger from "@/util/backendLogger"; import { prisma } from "@/lib";
import _ from "lodash";
import moment from "moment";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export const dynamic = "force-dynamic";
export { GET }; // GET ALL DATA INVESTASI
export async function GET(request: Request) {
async function GET(request: Request) {
try { try {
return NextResponse.json({ let dataFix;
success: true, const { searchParams } = new URL(request.url);
message: "Get data invetsasi", const kategori = searchParams.get("cat");
data: "", const status = searchParams.get("status");
}); const page = searchParams.get("page");
const dataTake = 10;
const dataSkip = Number(page) * dataTake - dataTake;
if (!page) {
const data = await prisma.investasi.findMany({
where: {
masterStatusInvestasiId: "1",
masterProgresInvestasiId: "1",
},
select: {
id: true,
MasterPencarianInvestor: true,
countDown: true,
progress: true,
},
});
for (let a of data) {
if (
(a.MasterPencarianInvestor?.name as any) -
moment(new Date()).diff(new Date(a.countDown as any), "days") <=
0
) {
await prisma.investasi.update({
where: {
id: a.id,
},
data: {
masterProgresInvestasiId: "3",
},
});
}
if (a.progress === "100") {
await prisma.investasi.update({
where: {
id: a.id,
},
data: {
masterProgresInvestasiId: "2",
},
});
}
}
// cek data yang lewat
// klo ada, update status
const dataAwal = await prisma.investasi.findMany({
orderBy: [
{
masterProgresInvestasiId: "asc",
},
{
countDown: "desc",
},
],
where: {
masterStatusInvestasiId: "1",
},
select: {
id: true,
imageId: true,
title: true,
progress: true,
countDown: true,
MasterPencarianInvestor: {
select: {
name: true,
},
},
},
});
dataFix = dataAwal.map((v: any) => ({
..._.omit(v, ["MasterPencarianInvestor"]),
pencarianInvestor: v.MasterPencarianInvestor.name,
}));
} else {
const data = await prisma.investasi.findMany({
where: {
masterStatusInvestasiId: "1",
masterProgresInvestasiId: "1",
},
select: {
id: true,
MasterPencarianInvestor: true,
countDown: true,
progress: true,
},
});
for (let a of data) {
if (
(a.MasterPencarianInvestor?.name as any) -
moment(new Date()).diff(new Date(a.countDown as any), "days") <=
0
) {
await prisma.investasi.update({
where: {
id: a.id,
},
data: {
masterProgresInvestasiId: "3",
},
});
}
if (a.progress === "100") {
await prisma.investasi.update({
where: {
id: a.id,
},
data: {
masterProgresInvestasiId: "2",
},
});
}
}
// cek data yang lewat
// klo ada, update status
const dataAwal = await prisma.investasi.findMany({
take: dataTake,
skip: dataSkip,
orderBy: [
{
masterProgresInvestasiId: "asc",
},
{
countDown: "desc",
},
],
where: {
masterStatusInvestasiId: "1",
},
select: {
id: true,
imageId: true,
title: true,
progress: true,
countDown: true,
MasterPencarianInvestor: {
select: {
name: true,
},
},
},
});
dataFix = dataAwal.map((v: any) => ({
..._.omit(v, ["MasterPencarianInvestor"]),
pencarianInvestor: v.MasterPencarianInvestor.name,
}));
}
return NextResponse.json(
{ success: true, message: "Berhasil mendapatkan data", data: dataFix },
{ status: 200 }
);
} catch (error) { } catch (error) {
backendLogger.error("Error get data investasi", error); console.error(error);
return NextResponse.json( return NextResponse.json(
{ {
success: false, success: false,
message: "Error get data from API ", message: "Gagal mendapatkan data, coba lagi nanti ",
reason: (error as Error).message, reason: (error as Error).message,
}, },
{ status: 500 } { status: 500 }

View File

@@ -1,7 +1,7 @@
import { AccentColor } from "@/app_modules/_global/color/color_pallet"; import { AccentColor } from "@/app_modules/_global/color/color_pallet";
import { Affix, Button, Center, rem } from "@mantine/core"; import { Affix, Button, Center, rem } from "@mantine/core";
import { useState } from "react"; import { useState } from "react";
import { apiGetAllInvestasi } from "../../_lib/api_interface"; import { apiFetchGetAllInvestasi } from "../../_lib/api_fetch_new_investasi";
export function Investasi_ComponentButtonUpdateBeranda({ export function Investasi_ComponentButtonUpdateBeranda({
onLoadData, onLoadData,
@@ -13,7 +13,9 @@ export function Investasi_ComponentButtonUpdateBeranda({
async function onLoaded() { async function onLoaded() {
try { try {
setLoading(true); setLoading(true);
const response = await apiGetAllInvestasi(`?cat=bursa&page=1`); const response = await apiFetchGetAllInvestasi({
page: "1",
});
if (response.success) { if (response.success) {
onLoadData(response.data); onLoadData(response.data);
} }

View File

@@ -0,0 +1,35 @@
export { apiFetchGetAllInvestasi };
const apiFetchGetAllInvestasi = async ({ page }: { page: string }) => {
try {
// Fetch token from cookie
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) {
console.error("No token found");
return null;
}
const nextPage = `?page=${page}`;
const response = await fetch(`/api/investasi${nextPage}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
Authorization: `Bearer ${token}`,
},
});
// Check if the response is OK
if (!response.ok) {
const errorData = await response.json().catch(() => null);
console.error("Failed to get all forum:", response.statusText, errorData);
throw new Error(errorData?.message || "Failed to get all forum");
}
// Return the JSON response
return await response.json();
} catch (error) {
console.error("Error get all forum", error);
throw error; // Re-throw the error to handle it in the calling function
}
};

View File

@@ -4,6 +4,7 @@ import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empt
import ComponentGlobal_Loader from "@/app_modules/_global/component/loader"; import ComponentGlobal_Loader from "@/app_modules/_global/component/loader";
import { gs_investasiTriggerBeranda } from "@/lib/global_state"; import { gs_investasiTriggerBeranda } from "@/lib/global_state";
import { RouterInvestasi_OLD } from "@/lib/router_hipmi/router_investasi"; import { RouterInvestasi_OLD } from "@/lib/router_hipmi/router_investasi";
import { clientLogger } from "@/util/clientLogger";
import { Box, Center } from "@mantine/core"; import { Box, Center } from "@mantine/core";
import { useShallowEffect } from "@mantine/hooks"; import { useShallowEffect } from "@mantine/hooks";
import { useAtom } from "jotai"; import { useAtom } from "jotai";
@@ -12,11 +13,9 @@ import { ScrollOnly } from "next-scroll-loader";
import { useState } from "react"; import { useState } from "react";
import { Investasi_ComponentButtonUpdateBeranda } from "../../_component"; import { Investasi_ComponentButtonUpdateBeranda } from "../../_component";
import { Investasi_ComponentCardBerandaNew } from "../../_component/main/com_card_beranda_new"; import { Investasi_ComponentCardBerandaNew } from "../../_component/main/com_card_beranda_new";
import { apiGetAllInvestasi } from "../../_lib/api_interface"; import { apiFetchGetAllInvestasi } from "../../_lib/api_fetch_new_investasi";
import { IDataInvestasiBursa } from "../../_lib/type_investasi"; import { IDataInvestasiBursa } from "../../_lib/type_investasi";
import SkeletonInvestasiBursa from "./skeleton_beranda"; import SkeletonInvestasiBursa from "./skeleton_beranda";
import frontendLogger from "@/util/frontendLogger";
import { clientLogger } from "@/util/clientLogger";
export function Investasi_ViewBerandaNew() { export function Investasi_ViewBerandaNew() {
const [data, setData] = useState<IDataInvestasiBursa[]>([]); const [data, setData] = useState<IDataInvestasiBursa[]>([]);
@@ -38,13 +37,15 @@ export function Investasi_ViewBerandaNew() {
useShallowEffect(() => { useShallowEffect(() => {
setIsTriggerReload(false); setIsTriggerReload(false);
setIsShowUpdate(false); setIsShowUpdate(false);
getDataInvestasi(); handleLoadData();
}, []); }, []);
async function getDataInvestasi() { const handleLoadData = async () => {
try { try {
setLoading(true); setLoading(true);
const response = await apiGetAllInvestasi(`?cat=bursa&page=1`); const response = await apiFetchGetAllInvestasi({
page: `${activePage}`,
});
if (response.success) { if (response.success) {
setData(response.data); setData(response.data);
} }
@@ -53,14 +54,16 @@ export function Investasi_ViewBerandaNew() {
} finally { } finally {
setLoading(false); setLoading(false);
} }
} };
const handleMoreData = async () => { const handleMoreData = async () => {
try { try {
const pageNew = activePage + 1; const nextPage = activePage + 1;
const loadData = await apiGetAllInvestasi(`?cat=bursa&page=${pageNew}`); const loadData = await apiFetchGetAllInvestasi({
page: `${nextPage}`,
});
if (loadData.success) { if (loadData.success) {
setActivePage(pageNew); setActivePage(nextPage);
return loadData.data; return loadData.data;
} else { } else {
return []; return [];