fix portofolio
deskripsi: - fix server to API
This commit is contained in:
41
src/app/api/master/bidang-bisnis/route.ts
Normal file
41
src/app/api/master/bidang-bisnis/route.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import backendLogger from "@/util/backendLogger";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export async function GET(request: Request) {
|
||||
if (request.method !== "GET") {
|
||||
return NextResponse.json(
|
||||
{ success: false, message: "Method not allowed" },
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
let fixData;
|
||||
fixData = await prisma.masterBidangBisnis.findMany({
|
||||
where: {
|
||||
active: true,
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
data: fixData,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
backendLogger.error("Error Get Master Bidang Bisnis >>", error);
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "API Error Get Data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
53
src/app/api/portofolio/[id]/route.ts
Normal file
53
src/app/api/portofolio/[id]/route.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { prisma } from "@/app/lib";
|
||||
import { NextResponse } from "next/server";
|
||||
|
||||
export { POST };
|
||||
|
||||
async function POST(request: Request, { params }: { params: { id: string } }) {
|
||||
if (request.method !== "POST") {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "Method not allowed",
|
||||
},
|
||||
{ status: 405 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const { id } = params;
|
||||
const { data } = await request.json();
|
||||
|
||||
// const createPortofolio = await prisma.portofolio.create({
|
||||
// data: {
|
||||
// profileId: id,
|
||||
// id_Portofolio: "Porto" + Date.now().toString(),
|
||||
// namaBisnis: data.namaBisnis,
|
||||
// deskripsi: data.deskripsi,
|
||||
// tlpn: data.tlpn,
|
||||
// alamatKantor: data.alamatKantor,
|
||||
// masterBidangBisnisId: data.masterBidangBisnisId,
|
||||
// logoId: data.fileId,
|
||||
// },
|
||||
// });
|
||||
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: true,
|
||||
message: "Berhasil mendapatkan data",
|
||||
id,
|
||||
data,
|
||||
},
|
||||
{ status: 200 }
|
||||
);
|
||||
} catch (error) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
message: "API Error Post Data",
|
||||
reason: (error as Error).message,
|
||||
},
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +1,13 @@
|
||||
import { CreatePortofolio } from "@/app_modules/katalog/portofolio";
|
||||
import { Portofolio_getMasterBidangBisnis } from "@/app_modules/katalog/portofolio/fun/master/get_bidang_bisnis";
|
||||
|
||||
export default async function Page({ params }: { params: { id: string } }) {
|
||||
const profileId = params.id;
|
||||
const bidangBisnis = await Portofolio_getMasterBidangBisnis();
|
||||
export default async function Page() {
|
||||
// const profileId = params.id;
|
||||
// const bidangBisnis = await Portofolio_getMasterBidangBisnis();
|
||||
|
||||
return (
|
||||
<>
|
||||
<CreatePortofolio
|
||||
bidangBisnis={bidangBisnis as any}
|
||||
profileId={profileId}
|
||||
/>
|
||||
</>
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export { apiGetMasterBank };
|
||||
export { apiGetMasterBank, apiGetMasterBidangBisnis };
|
||||
|
||||
const apiGetMasterBank = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
@@ -12,8 +12,22 @@ const apiGetMasterBank = async () => {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await respone.json().catch(() => null);
|
||||
};
|
||||
|
||||
const apiGetMasterBidangBisnis = async () => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const respone = await fetch(`/api/master/bidang-bisnis`, {
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await respone.json().catch(() => null);
|
||||
};
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
export {
|
||||
apiCreatePortofolio,
|
||||
};
|
||||
|
||||
const apiCreatePortofolio = async ({ data }: { data: any }) => {
|
||||
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
|
||||
if (!token) return await token.json().catch(() => null);
|
||||
|
||||
const res = await fetch(`/api/portofolio`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ data }),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
"Access-Control-Allow-Origin": "*",
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
});
|
||||
|
||||
return await res.json().catch(() => null);
|
||||
};
|
||||
@@ -15,6 +15,21 @@ import { clientLogger } from "@/util/clientLogger";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import funCreatePortofolio from "../../fun/fun_create_portofolio";
|
||||
import { apiCreatePortofolio } from "../api_fetch_portofolio";
|
||||
|
||||
interface ICreatePortofolio {
|
||||
namaBisnis: string;
|
||||
masterBidangBisnisId: string;
|
||||
alamatKantor: string;
|
||||
tlpn: string;
|
||||
deskripsi: string;
|
||||
fileId: string;
|
||||
facebook: string;
|
||||
twitter: string;
|
||||
instagram: string;
|
||||
tiktok: string;
|
||||
youtube: string;
|
||||
}
|
||||
|
||||
export function Portofolio_ComponentButtonSelanjutnya({
|
||||
profileId,
|
||||
@@ -31,15 +46,7 @@ export function Portofolio_ComponentButtonSelanjutnya({
|
||||
const [loading, setLoading] = useState(false);
|
||||
|
||||
async function onSubmit() {
|
||||
const porto = {
|
||||
namaBisnis: dataPortofolio.namaBisnis,
|
||||
masterBidangBisnisId: dataPortofolio.masterBidangBisnisId,
|
||||
alamatKantor: dataPortofolio.alamatKantor,
|
||||
tlpn: dataPortofolio.tlpn,
|
||||
deskripsi: dataPortofolio.deskripsi,
|
||||
};
|
||||
|
||||
if (_.values(porto).includes("")) {
|
||||
if (_.values(dataPortofolio).includes("")) {
|
||||
ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
|
||||
return;
|
||||
}
|
||||
@@ -65,6 +72,29 @@ export function Portofolio_ComponentButtonSelanjutnya({
|
||||
|
||||
const fileId = uploadFile.data.id;
|
||||
|
||||
const newData: ICreatePortofolio = {
|
||||
namaBisnis: dataPortofolio.namaBisnis,
|
||||
masterBidangBisnisId: dataPortofolio.masterBidangBisnisId,
|
||||
alamatKantor: dataPortofolio.alamatKantor,
|
||||
tlpn: dataPortofolio.tlpn,
|
||||
deskripsi: dataPortofolio.deskripsi,
|
||||
facebook: dataMedsos.facebook,
|
||||
twitter: dataMedsos.twitter,
|
||||
instagram: dataMedsos.instagram,
|
||||
tiktok: dataMedsos.tiktok,
|
||||
youtube: dataMedsos.youtube,
|
||||
fileId: fileId,
|
||||
};
|
||||
|
||||
// const responeCreated = await apiCreatePortofolio({
|
||||
// data: newData,
|
||||
// });
|
||||
|
||||
// if (responeCreated.success) {
|
||||
// ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan");
|
||||
// router.replace(RouterMap.create + responeCreated.id, { scroll: false });
|
||||
// }
|
||||
|
||||
const res = await funCreatePortofolio({
|
||||
profileId: profileId,
|
||||
data: dataPortofolio as any,
|
||||
|
||||
@@ -35,14 +35,16 @@ import { useState } from "react";
|
||||
import { PhoneInput } from "react-international-phone";
|
||||
import "react-international-phone/style.css";
|
||||
import { Portofolio_ComponentButtonSelanjutnya } from "../component";
|
||||
import { useParams } from "next/navigation";
|
||||
import { useShallowEffect } from "@mantine/hooks";
|
||||
import { apiGetMasterBidangBisnis } from "@/app_modules/_global/lib/api_master";
|
||||
import { MODEL_PORTOFOLIO_BIDANG_BISNIS } from "../model/interface";
|
||||
import { clientLogger } from "@/util/clientLogger";
|
||||
|
||||
export default function CreatePortofolio() {
|
||||
const params = useParams<{ id: string }>();
|
||||
const profileId = params.id;
|
||||
|
||||
export default function CreatePortofolio({
|
||||
bidangBisnis,
|
||||
profileId,
|
||||
}: {
|
||||
bidangBisnis: BIDANG_BISNIS_OLD;
|
||||
profileId: any;
|
||||
}) {
|
||||
const [dataPortofolio, setDataPortofolio] = useState({
|
||||
namaBisnis: "",
|
||||
masterBidangBisnisId: "",
|
||||
@@ -62,6 +64,25 @@ export default function CreatePortofolio({
|
||||
const [file, setFile] = useState<File | null>(null);
|
||||
const [img, setImg] = useState<any | null>(null);
|
||||
const [imageId, setImageId] = useState("");
|
||||
const [listBidangBisnis, setListBidangBisnis] = useState<
|
||||
MODEL_PORTOFOLIO_BIDANG_BISNIS[] | null
|
||||
>(null);
|
||||
|
||||
useShallowEffect(() => {
|
||||
onLoadMaster();
|
||||
}, []);
|
||||
|
||||
async function onLoadMaster() {
|
||||
try {
|
||||
const respone = await apiGetMasterBidangBisnis();
|
||||
|
||||
if (respone.success) {
|
||||
setListBidangBisnis(respone.data);
|
||||
}
|
||||
} catch (error) {
|
||||
clientLogger.error("Error on load master bidang bisnis", error);
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -91,6 +112,7 @@ export default function CreatePortofolio({
|
||||
});
|
||||
}}
|
||||
/>
|
||||
|
||||
<Select
|
||||
styles={{
|
||||
label: {
|
||||
@@ -108,8 +130,10 @@ export default function CreatePortofolio({
|
||||
}}
|
||||
withAsterisk
|
||||
label="Bidang Bisnis"
|
||||
placeholder="Pilih salah satu bidang bisnis"
|
||||
data={_.map(bidangBisnis as any).map((e: any) => ({
|
||||
placeholder={
|
||||
listBidangBisnis ? "Pilih bidang bisnis" : "Loading..."
|
||||
}
|
||||
data={_.map(listBidangBisnis as any).map((e: any) => ({
|
||||
value: e.id,
|
||||
label: e.name,
|
||||
}))}
|
||||
@@ -420,7 +444,7 @@ export default function CreatePortofolio({
|
||||
dataPortofolio={dataPortofolio as any}
|
||||
dataMedsos={dataMedsos}
|
||||
profileId={profileId}
|
||||
//
|
||||
//
|
||||
file={file as File}
|
||||
/>
|
||||
</Stack>
|
||||
|
||||
@@ -31,18 +31,9 @@ const middlewareConfig: MiddlewareConfig = {
|
||||
"/api/auth/*",
|
||||
"/api/origin-url",
|
||||
"/api/event/*",
|
||||
// "/api/master/*",
|
||||
// "/api/image/*",
|
||||
// "/api/user/*",
|
||||
// "/api/new/*",
|
||||
|
||||
// ADMIN API
|
||||
// "/api/admin/event/*",
|
||||
"/api/admin/investasi/*",
|
||||
// "/api/admin/donasi/*",
|
||||
// "/api/admin/voting/dashboard/*",
|
||||
// "/api/admin/job/*",
|
||||
// "/api/admin/forum/*",
|
||||
// "/api/admin/collaboration/*",
|
||||
// >> buat disini <<
|
||||
|
||||
// Akses awal
|
||||
"/api/get-cookie",
|
||||
|
||||
Reference in New Issue
Block a user