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

View File

@@ -1,6 +1,6 @@
{
"name": "hipmi",
"version": "1.2.68",
"version": "1.2.69",
"private": true,
"prisma": {
"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";
export const dynamic = "force-dynamic";
export { GET };
async function GET(request: Request) {
// GET ALL DATA INVESTASI
export async function GET(request: Request) {
try {
return NextResponse.json({
success: true,
message: "Get data invetsasi",
data: "",
});
let dataFix;
const { searchParams } = new URL(request.url);
const kategori = searchParams.get("cat");
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) {
backendLogger.error("Error get data investasi", error);
console.error(error);
return NextResponse.json(
{
success: false,
message: "Error get data from API ",
message: "Gagal mendapatkan data, coba lagi nanti ",
reason: (error as Error).message,
},
{ status: 500 }

View File

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