fix ( authorization api )

deskripsi:
- memberi authorizetion ke api/new/*
This commit is contained in:
2025-01-08 17:41:04 +08:00
parent ebc9dcef04
commit 8c0af94ff8
5 changed files with 149 additions and 54 deletions

View File

@@ -14,7 +14,8 @@ export async function GET(request: Request) {
const kategori = searchParams.get("cat")
const status = searchParams.get("status")
const page = searchParams.get("page")
const dataSkip = Number(page) * 5 - 5;
const dataTake = 10
const dataSkip = Number(page) * dataTake - dataTake;
if (kategori == "bursa") {
const data = await prisma.investasi.findMany({
@@ -61,7 +62,7 @@ export async function GET(request: Request) {
// cek data yang lewat
// klo ada, update status
const dataAwal = await prisma.investasi.findMany({
take: 5,
take: dataTake,
skip: dataSkip,
orderBy: [
{
@@ -100,28 +101,28 @@ export async function GET(request: Request) {
}
const data = await prisma.investasi.findMany({
take: 5,
skip: dataSkip,
orderBy: {
updatedAt: "desc",
},
where: {
authorId: userLoginId,
masterStatusInvestasiId: status,
},
select: {
id: true,
title: true,
targetDana: true,
imageId: true,
countDown: true,
updatedAt: true,
MasterPencarianInvestor: {
select: {
name: true
}
}
}
take: dataTake,
skip: dataSkip,
orderBy: {
updatedAt: "desc",
},
where: {
authorId: userLoginId,
masterStatusInvestasiId: status,
},
select: {
id: true,
title: true,
targetDana: true,
imageId: true,
countDown: true,
updatedAt: true,
MasterPencarianInvestor: {
select: {
name: true,
},
},
},
});
dataFix = data.map((v: any) => ({

View File

@@ -1,19 +1,59 @@
export const apiGetAllDonasi = async (path?: string) => {
const response = await fetch(`/api/new/donasi${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/donasi${path ? path : ""}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
export const apiGetMasterDonasi = async (path?: string) => {
const response = await fetch(`/api/new/donasi/master${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/donasi/master${path ? path : ""}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
export const apiGetAllDonasiSaya = async (path?: string) => {
const response = await fetch(`/api/new/donasi/invoice${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/donasi/invoice${path ? path : ""}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
export const apiGetOneDonasiById = async (path: string, kategori: string) => {
const response = await fetch(`/api/new/donasi/${path}?cat=${kategori}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/donasi/${path}?cat=${kategori}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};

View File

@@ -1,19 +1,64 @@
export const apiGetMasterInvestasi = async (path?: string) => {
const response = await fetch(`/api/new/investasi/master${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/investasi/master${path ? path : ""}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
export const apiGetOneInvestasiById = async (path: string) => {
const response = await fetch(`/api/new/investasi/${path}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/investasi/${path}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
export const apiGetAllInvestasi = async (path?: string) => {
const response = await fetch(`/api/new/investasi${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/investasi${path ? path : ""}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};
export const apiGetAllSahamSaya = async (path?: string) => {
const response = await fetch(`/api/new/investasi/invoice${(path) ? path : ''}`)
return await response.json().catch(() => null)
}
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(
`/api/new/investasi/invoice${path ? path : ""}`,
{
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
}
);
return await response.json().catch(() => null);
};

View File

@@ -1,6 +1,6 @@
export const apiGetPortofolioByProfile = async (path?: string) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return null;
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/portofolio${path ? path : ""}`, {
headers: {
@@ -18,7 +18,7 @@ export const apiGetPortofolioByProfile = async (path?: string) => {
export const apiGetOnePortofolioById = async (path: string, cat: string) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return null;
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/portofolio/${path}?cat=${cat}`, {
headers: {
@@ -36,7 +36,7 @@ export const apiGetOnePortofolioById = async (path: string, cat: string) => {
export const apiDeletePortofolio = async (path: string) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return null;
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/portofolio/${path}`, {
method: "DELETE",
@@ -46,6 +46,5 @@ export const apiDeletePortofolio = async (path: string) => {
},
});
return await response.json().catch(() => null);
};

View File

@@ -14,7 +14,17 @@ export const apiGetAllMap = async (path?: string) => {
};
export const apiGetOneMapById = async (path: string) => {
const response = await fetch(`/api/new/map/${path}`);
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/new/map/${path}`, {
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await response.json().catch(() => null);
};