Merge pull request #301 from bipproduction/join

fix server action to API
This commit is contained in:
Bagasbanuna02
2025-02-11 17:41:45 +08:00
committed by GitHub
40 changed files with 397 additions and 370 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.53](https://github.com/bipproduction/hipmi/compare/v1.2.52...v1.2.53) (2025-02-11)
## [1.2.52](https://github.com/bipproduction/hipmi/compare/v1.2.51...v1.2.52) (2025-02-10) ## [1.2.52](https://github.com/bipproduction/hipmi/compare/v1.2.51...v1.2.52) (2025-02-10)
## [1.2.51](https://github.com/bipproduction/hipmi/compare/v1.2.50...v1.2.51) (2025-02-10) ## [1.2.51](https://github.com/bipproduction/hipmi/compare/v1.2.50...v1.2.51) (2025-02-10)

View File

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

View File

@@ -1,3 +0,0 @@
git add -A
git commit -m "data auto"
git push origin bagas/10-feb-25

1
run.dev Normal file
View File

@@ -0,0 +1 @@
bun --env-file=.env run dev

View File

@@ -10,7 +10,6 @@ export async function GET(request: Request, { params }:
const { status } = params; const { status } = params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const search = searchParams.get("search");
const page = searchParams.get("page"); const page = searchParams.get("page");
const takeData = 10; const takeData = 10;
const skipData = Number(page) * takeData - takeData; const skipData = Number(page) * takeData - takeData;
@@ -21,8 +20,6 @@ export async function GET(request: Request, { params }:
if (!page) { if (!page) {
fixData = await prisma.projectCollaboration.findMany({ fixData = await prisma.projectCollaboration.findMany({
skip: skipData,
take: takeData,
orderBy: { orderBy: {
createdAt: "desc", createdAt: "desc",
}, },
@@ -32,10 +29,7 @@ export async function GET(request: Request, { params }:
Author: { Author: {
active: true, active: true,
}, },
title: {
contains: search ? search : "",
mode: "insensitive",
},
}, },
select: { select: {
id: true, id: true,
@@ -82,10 +76,6 @@ export async function GET(request: Request, { params }:
Author: { Author: {
active: true, active: true,
}, },
title: {
contains: search ? search : "",
mode: "insensitive",
},
}, },
select: { select: {
id: true, id: true,

View File

@@ -6,15 +6,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { name: string } params: { name: string }
}) { }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
const { name } = params; const { name } = params;
try { try {
let fixData; let fixData;
@@ -59,7 +50,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect
} }
} }

View File

@@ -7,15 +7,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, export async function GET(request: Request,
{ params }: { params: { status: string } }) { { params }: { params: { status: string } }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
succes: false,
message: "Method not allowed"
},
{ status: 405 }
);
}
const { status } = params; const { status } = params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
@@ -30,7 +21,7 @@ export async function GET(request: Request,
if (!page) { if (!page) {
const data = await prisma.donasi.findMany({ fixData = await prisma.donasi.findMany({
orderBy: { orderBy: {
createdAt: "desc", createdAt: "desc",
}, },
@@ -120,7 +111,5 @@ export async function GET(request: Request,
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -7,15 +7,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { name: string } params: { name: string }
}) { }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
const { name } = params; const { name } = params;
try { try {
@@ -44,7 +35,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,14 +4,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method; const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method nol allowed"
},
{ status: 405 }
)
}
try { try {
const data = await prisma.donasiMaster_Kategori.findMany({ const data = await prisma.donasiMaster_Kategori.findMany({
orderBy: { orderBy: {
@@ -38,7 +30,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect
} }
} }

View File

@@ -8,13 +8,7 @@ export async function GET(
request: Request, request: Request,
{ params }: { params: { status: string } } { params }: { params: { status: string } }
) { ) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
const { status } = params; const { status } = params;
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
@@ -249,7 +243,5 @@ export async function GET(
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -7,13 +7,6 @@ export async function GET(
request: Request, request: Request,
{ params }: { params: { name: string } } { params }: { params: { name: string } }
) { ) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
const { name } = params; const { name } = params;
@@ -47,7 +40,5 @@ export async function GET(
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,14 +4,6 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try { try {
let fixData; let fixData;
fixData = await prisma.event.count({ fixData = await prisma.event.count({
@@ -41,7 +33,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,13 +4,6 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const search = searchParams.get("search"); const search = searchParams.get("search");
@@ -195,7 +188,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -3,15 +3,7 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
try { try {
let fixData; let fixData;
fixData = await prisma.forum_ReportKomentar.count({ fixData = await prisma.forum_ReportKomentar.count({
@@ -35,7 +27,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -3,15 +3,6 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
try { try {
let fixData; let fixData;
fixData = await prisma.forum_ReportPosting.count({ fixData = await prisma.forum_ReportPosting.count({
@@ -35,7 +26,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -5,15 +5,6 @@ import { NextResponse } from "next/server";
import _ from 'lodash'; import _ from 'lodash';
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed"
},
{ status: 405 }
);
}
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const search = searchParams.get("search"); const search = searchParams.get("search");
@@ -127,7 +118,5 @@ export async function GET(request: Request) {
reason: (error as Error).message reason: (error as Error).message
}, },
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -5,16 +5,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, export async function GET(request: Request,
{ postingId }: { postingId: string }) { { postingId }: { postingId: string }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const search = searchParams.get('search'); const search = searchParams.get('search');
@@ -144,7 +134,5 @@ export async function GET(request: Request,
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,15 +4,6 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);
const search = searchParams.get("search"); const search = searchParams.get("search");
@@ -124,7 +115,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect()
} }
} }

View File

@@ -4,15 +4,7 @@ import _ from "lodash";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { params: { name: string } }) { export async function GET(request: Request, { params }: { params: { name: string } }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
const { name } = params; const { name } = params;
try { try {
let fixData; let fixData;
@@ -40,7 +32,5 @@ export async function GET(request: Request, { params }: { params: { name: string
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -0,0 +1,79 @@
import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server";
export async function GET(req: Request,
{ params }: { params: { id: string } }) {
console.log("Ini ID", params.id);
try {
const { id } = params;
const data = await prisma.investasi.findUnique({
where: {
id: id,
},
select: {
imageId: true,
prospektusFileId: true,
id: true,
author: {
select: {
id: true,
username: true,
nomor: true,
Profile: true,
},
},
title: true,
authorId: true,
hargaLembar: true,
targetDana: true,
totalLembar: true,
sisaLembar: true,
lembarTerbeli: true,
progress: true,
roi: true,
active: true,
createdAt: true,
updatedAt: true,
catatan: true,
imagesId: true,
MasterStatusInvestasi: true,
BeritaInvestasi: true,
DokumenInvestasi: true,
ProspektusInvestasi: true,
MasterPembagianDeviden: true,
MasterPencarianInvestor: true,
MasterPeriodeDeviden: true,
MasterProgresInvestasi: true,
masterStatusInvestasiId: true,
Investasi_Invoice: {
where: {
statusInvoiceId: "1",
},
},
countDown: true,
},
});
return NextResponse.json({
success: true,
message: "Success get detail investasi",
data: data,
},
{ status: 200 }
)
} catch (error) {
backendLogger.error("Error get detail investasi", error);
return NextResponse.json({
success: false,
message: "Error get detail investasi",
reason: (error as Error).message
},
{ status: 500 }
);
}
}

View File

@@ -6,15 +6,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { status: string } params: { status: string }
}) { }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
const { status } = params; const { status } = params;
try { try {
let fixData; let fixData;
@@ -44,7 +36,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,14 +4,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method; const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
try { try {
let fixData; let fixData;
fixData = await prisma.job.count({ fixData = await prisma.job.count({
@@ -38,7 +31,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -25,7 +25,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -4,12 +4,7 @@ import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
const method = request.method; const method = request.method;
if (method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try { try {
const data = await prisma.user.count({ const data = await prisma.user.count({
where: { where: {
@@ -35,8 +30,6 @@ export async function GET(request: Request) {
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -6,15 +6,6 @@ import { NextResponse } from "next/server";
export async function GET(request: Request, { params }: { export async function GET(request: Request, { params }: {
params: { name: string } params: { name: string }
}) { }) {
const method = request.method;
if (method !== "GET") {
return NextResponse.json({
success: false,
message: "Method not allowed",
},
{ status: 405 }
)
}
const { name } = params; const { name } = params;
try { try {
@@ -45,7 +36,5 @@ export async function GET(request: Request, { params }: {
}, },
{ status: 500 } { status: 500 }
) )
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -3,15 +3,6 @@ import backendLogger from "@/util/backendLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
if (request.method !== "GET") {
return NextResponse.json(
{
success: false,
message: "Method not allowed",
},
{ status: 405 }
);
}
try { try {
let fixData; let fixData;
@@ -42,7 +33,5 @@ export async function GET(request: Request) {
}, },
{ status: 500 } { status: 500 }
); );
} finally {
await prisma.$disconnect();
} }
} }

View File

@@ -0,0 +1,74 @@
import { prisma } from "@/app/lib";
import { funGetUserIdByToken } from "@/app_modules/_global/fun/get";
import backendLogger from "@/util/backendLogger";
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 userLoginId = await funGetUserIdByToken();
if (!userLoginId) {
return NextResponse.json(
{
success: false,
message: "User tidak ditemukan",
},
{ status: 401 }
);
}
const { id } = params;
const { data } = await request.json();
const created = await prisma.businessMaps.create({
data: {
latitude: data.latitude,
longitude: data.longitude,
namePin: data.namePin,
imageId: data.imageId,
portofolioId: id,
authorId: userLoginId,
},
});
if (!created) {
return NextResponse.json(
{
success: false,
message: "Gagal membuat pin map",
},
{ status: 400 }
);
}
return NextResponse.json(
{
success: true,
message: "Berhasil membuat portofolio",
data: created,
},
{ status: 201 }
);
} catch (error) {
backendLogger.error("Error create pin map", error);
return NextResponse.json(
{
success: false,
message: "Gagal membuat pin map",
reason: (error as Error).message,
},
{ status: 500 }
);
}
}

View File

@@ -1,15 +1,8 @@
import { prisma } from "@/app/lib"; import { prisma } from "@/app/lib";
import backendLogger from "@/util/backendLogger"; import backendLogger from "@/util/backendLogger";
import { clientLogger } from "@/util/clientLogger";
import { NextResponse } from "next/server"; import { NextResponse } from "next/server";
export async function GET(request: Request) { export async function GET(request: Request) {
if (request.method !== "GET") {
return NextResponse.json(
{ success: false, message: "Method not allowed" },
{ status: 405 }
);
}
try { try {
let fixData; let fixData;

View File

@@ -18,25 +18,53 @@ async function POST(request: Request, { params }: { params: { id: string } }) {
const { id } = params; const { id } = params;
const { data } = await request.json(); const { data } = await request.json();
// const createPortofolio = await prisma.portofolio.create({ const createPortofolio = await prisma.portofolio.create({
// data: { data: {
// profileId: id, profileId: id,
// id_Portofolio: "Porto" + Date.now().toString(), id_Portofolio: "Porto" + Date.now().toString(),
// namaBisnis: data.namaBisnis, namaBisnis: data.namaBisnis,
// deskripsi: data.deskripsi, deskripsi: data.deskripsi,
// tlpn: data.tlpn, tlpn: data.tlpn,
// alamatKantor: data.alamatKantor, alamatKantor: data.alamatKantor,
// masterBidangBisnisId: data.masterBidangBisnisId, masterBidangBisnisId: data.masterBidangBisnisId,
// logoId: data.fileId, logoId: data.fileId,
// }, },
// }); });
if (!createPortofolio)
return NextResponse.json(
{
success: false,
message: "Gagal membuat portofolio",
},
{ status: 400 }
);
const createMedsos = await prisma.portofolio_MediaSosial.create({
data: {
portofolioId: createPortofolio.id,
facebook: data?.facebook,
instagram: data?.instagram,
tiktok: data?.tiktok,
twitter: data?.twitter,
youtube: data?.youtube,
},
});
if (!createMedsos)
return NextResponse.json(
{
success: false,
message: "Gagal menambahkan medsos",
},
{ status: 400 }
);
return NextResponse.json( return NextResponse.json(
{ {
success: true, success: true,
message: "Berhasil mendapatkan data", message: "Berhasil mendapatkan data",
id, data: createPortofolio,
data,
}, },
{ status: 200 } { status: 200 }
); );

View File

@@ -1,10 +1,9 @@
import { Map_CreateNewPin } from "@/app_modules/map/view"; import { Map_CreateNewPin } from "@/app_modules/map/view";
export default async function Page({ params }: { params: { id: string } }) { export default async function Page() {
let portofolioId = params.id;
return ( return (
<> <>
<Map_CreateNewPin portofolioId={portofolioId} /> <Map_CreateNewPin />
</> </>
); );
} }

View File

@@ -1,14 +1,9 @@
import { CreatePortofolio } from "@/app_modules/katalog/portofolio"; 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() { export default async function Page() {
// const profileId = params.id;
// const bidangBisnis = await Portofolio_getMasterBidangBisnis();
return ( return (
<> <>
<CreatePortofolio <CreatePortofolio />
/>
</> </>
); );
} }

View File

@@ -25,18 +25,17 @@ const apiGetAdminCollaborationStatusCountDashboard = async ({
// console.log("Ini Response", await response.json()); // console.log("Ini Response", await response.json());
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminCollaborationStatusById = async ({ status, page, search }: { const apiGetAdminCollaborationStatusById = async ({ status, page}: {
status: "Publish" | "Reject", status: "Publish" | "Reject",
page: string, page: string,
search: string
}) => { }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
const isPage = page ? `?page=${page}` : ""; const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : ""; const response = await fetch(`/api/admin/collaboration/${status}${isPage}`, {
const response = await fetch(`/api/admin/collaboration/${status}${isPage}${isSearch}`, {
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Accept: "application/json", Accept: "application/json",

View File

@@ -1,6 +1,8 @@
export { export {
apiGetAdminInvestasiCountDashboard, apiGetAdminInvestasiCountDashboard,
apiGetAdminInvestasiByStatus, apiGetAdminInvestasiByStatus,
apiGetAdminInvestasiById,
} }
const apiGetAdminInvestasiCountDashboard = async ({ name }: const apiGetAdminInvestasiCountDashboard = async ({ name }:
{ name: "Publish" | "Review" | "Reject" }) => { { name: "Publish" | "Review" | "Reject" }) => {
@@ -37,6 +39,7 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
const isPage = page ? `?page=${page}` : ""; const isPage = page ? `?page=${page}` : "";
const isSearch = search ? `&search=${search}` : ""; const isSearch = search ? `&search=${search}` : "";
const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, { const response = await fetch(`/api/admin/investasi/${status}${isPage}${isSearch}`, {
method: "GET",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
Accept: "application/json", Accept: "application/json",
@@ -47,3 +50,22 @@ const apiGetAdminInvestasiByStatus = async ({ status, page, search }: {
return await response.json().catch(() => null); return await response.json().catch(() => null);
} }
const apiGetAdminInvestasiById = async ({id} : {id: string}) => {
const { token } = await fetch ("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const response = await fetch(`/api/admin/investasi/detail/${id}`, {
method: "GET",
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
}
})
console.log("Ini data Response", await response.json())
return await response.json().catch(() => null);
}

View File

@@ -2,11 +2,11 @@ export {
apiCreatePortofolio, apiCreatePortofolio,
}; };
const apiCreatePortofolio = async ({ data }: { data: any }) => { const apiCreatePortofolio = async ({ profileId, data }: { profileId: string, data: any }) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json()); const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null); if (!token) return await token.json().catch(() => null);
const res = await fetch(`/api/portofolio`, { const res = await fetch(`/api/portofolio/${profileId}`, {
method: "POST", method: "POST",
body: JSON.stringify({ data }), body: JSON.stringify({ data }),
headers: { headers: {

View File

@@ -14,7 +14,6 @@ import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
import { clientLogger } from "@/util/clientLogger"; import { clientLogger } from "@/util/clientLogger";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import funCreatePortofolio from "../../fun/fun_create_portofolio";
import { apiCreatePortofolio } from "../api_fetch_portofolio"; import { apiCreatePortofolio } from "../api_fetch_portofolio";
interface ICreatePortofolio { interface ICreatePortofolio {
@@ -45,33 +44,21 @@ export function Portofolio_ComponentButtonSelanjutnya({
const router = useRouter(); const router = useRouter();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
async function onSubmit() { const validateData = () => {
if (_.values(dataPortofolio).includes("")) { if (_.includes(_.values(dataPortofolio), "")) {
ComponentGlobal_NotifikasiPeringatan("Lengkapi Data"); ComponentGlobal_NotifikasiPeringatan("Lengkapi Data");
return; return false;
} }
if (dataPortofolio.tlpn.length < 10) { if (dataPortofolio.tlpn.length < 10) {
ComponentGlobal_NotifikasiPeringatan("Nomor telepon minimal 10 angka"); ComponentGlobal_NotifikasiPeringatan("Nomor telepon minimal 10 angka");
return; return false;
} }
try { return true;
setLoading(true); };
const uploadFile = await funGlobal_UploadToStorage({
file: file,
dirId: DIRECTORY_ID.portofolio_logo,
});
if (!uploadFile.success) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
return;
}
const fileId = uploadFile.data.id;
const handleCreatePortofolio = async (fileId: string) => {
const newData: ICreatePortofolio = { const newData: ICreatePortofolio = {
namaBisnis: dataPortofolio.namaBisnis, namaBisnis: dataPortofolio.namaBisnis,
masterBidangBisnisId: dataPortofolio.masterBidangBisnisId, masterBidangBisnisId: dataPortofolio.masterBidangBisnisId,
@@ -86,38 +73,48 @@ export function Portofolio_ComponentButtonSelanjutnya({
fileId: fileId, fileId: fileId,
}; };
// const responeCreated = await apiCreatePortofolio({ const response = 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, profileId: profileId,
data: dataPortofolio as any, data: newData,
medsos: dataMedsos,
fileId: fileId,
}); });
if (res.status === 201) {
if (response.success) {
ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan"); ComponentGlobal_NotifikasiBerhasil("Berhasil disimpan");
router.replace(RouterMap.create + res.id, { scroll: false }); router.replace(RouterMap.create + response.data.id, { scroll: false });
} else { } else {
setLoading(false); setLoading(false);
ComponentGlobal_NotifikasiGagal("Gagal disimpan"); throw new Error("Failed to create portfolio");
} }
};
const onSubmit = async () => {
if (!validateData()) return;
try {
setLoading(true);
const uploadFile = await funGlobal_UploadToStorage({
file: file,
dirId: DIRECTORY_ID.portofolio_logo,
});
if (!uploadFile.success) {
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
return;
}
await handleCreatePortofolio(uploadFile.data.id);
} catch (error) { } catch (error) {
setLoading(false); setLoading(false);
ComponentGlobal_NotifikasiGagal("Gagal disimpan");
clientLogger.error("Error create portofolio", error); clientLogger.error("Error create portofolio", error);
} }
} };
return ( return (
<> <>
<Button <Button
disabled={_.values(dataPortofolio).includes("") || file === null} disabled={_.values(dataPortofolio).includes("") || !file}
mt={"md"} mt={"md"}
radius={50} radius={50}
loading={loading} loading={loading}

View File

@@ -0,0 +1,25 @@
export { apiCreatePinMap };
const apiCreatePinMap = async ({
portofolioId,
data,
}: {
portofolioId: string;
data: any;
}) => {
const { token } = await fetch("/api/get-cookie").then((res) => res.json());
if (!token) return await token.json().catch(() => null);
const respone = await fetch(`/api/map/${portofolioId}`, {
method: "POST",
body: JSON.stringify({ data }),
headers: {
"Content-Type": "application/json",
Accept: "application/json",
"Access-Control-Allow-Origin": "*",
Authorization: `Bearer ${token}`,
},
});
return await respone.json().catch(() => null);
};

View File

@@ -12,7 +12,16 @@ import { useState } from "react";
import { map_funCreatePin } from "../../fun/create/fun_create_pin"; import { map_funCreatePin } from "../../fun/create/fun_create_pin";
import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun"; import { funGlobal_UploadToStorage } from "@/app_modules/_global/fun";
import { DIRECTORY_ID } from "@/app/lib"; import { DIRECTORY_ID } from "@/app/lib";
import { clientLogger } from "@/util/clientLogger";
import { data } from "autoprefixer";
import { apiCreatePinMap } from "../api_fetch_map";
interface ICreatePinMAp {
latitude: string;
longitude: string;
namePin: string;
imageId: string;
}
export function ComponentMap_ButtonSavePin({ export function ComponentMap_ButtonSavePin({
namePin, namePin,
lat, lat,
@@ -29,43 +38,72 @@ export function ComponentMap_ButtonSavePin({
const router = useRouter(); const router = useRouter();
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
async function onSavePin() { const handleUploadImage = async () => {
try { const uploadResult = await funGlobal_UploadToStorage({
setLoading(true);
const uploadFile = await funGlobal_UploadToStorage({
file: file, file: file,
dirId: DIRECTORY_ID.map_image, dirId: DIRECTORY_ID.map_image,
}); });
if (!uploadFile.success) { if (!uploadResult.success) {
setLoading(false); setLoading(false);
ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar"); ComponentGlobal_NotifikasiPeringatan("Gagal upload gambar");
return;
} }
const imageId = uploadFile.data.id; return uploadResult.data.id;
};
const res = await map_funCreatePin({ const handleCreatePin = async (imageId: string) => {
data: { const newData: ICreatePinMAp = {
latitude: lat as any, latitude: lat,
longitude: long as any, longitude: long,
namePin: namePin as any, namePin: namePin,
imageId: imageId, imageId: imageId,
Portofolio: { };
create: { id: portofolioId } as any,
}, const respone = await apiCreatePinMap({
}, portofolioId: portofolioId,
data: newData,
}); });
res.status === 200
? (ComponentGlobal_NotifikasiBerhasil(res.message), router.back()) console.log("respone >", respone);
: ComponentGlobal_NotifikasiGagal(res.message);
if (respone && respone.success) {
ComponentGlobal_NotifikasiBerhasil(respone.message);
router.back();
}
return respone;
};
const validateInput = () => {
if (!namePin || !file) {
ComponentGlobal_NotifikasiPeringatan(
"Nama pin dan file gambar harus diisi"
);
return false;
}
return true;
};
const onSavePin = async () => {
if (!validateInput()) return;
try {
setLoading(true);
const imageId = await handleUploadImage();
const createPinResult = await handleCreatePin(imageId);
if (!createPinResult.success) {
setLoading(false);
ComponentGlobal_NotifikasiPeringatan("Gagal membuat pin");
}
} catch (error) { } catch (error) {
setLoading(false); setLoading(false);
clientLogger.error("Error create pin", (error as Error).message);
console.error(error); ComponentGlobal_NotifikasiGagal("Terjadi kesalahan saat menyimpan pin");
}
} }
};
return ( return (
<> <>
@@ -73,7 +111,7 @@ export function ComponentMap_ButtonSavePin({
loading={loading} loading={loading}
my={"xl"} my={"xl"}
style={{ transition: "0.5s" }} style={{ transition: "0.5s" }}
disabled={namePin === "" || file === null} disabled={!namePin || !file}
radius={"xl"} radius={"xl"}
loaderPosition="center" loaderPosition="center"
bg={MainColor.yellow} bg={MainColor.yellow}

View File

@@ -1,6 +1,5 @@
"use client"; "use client";
import { DIRECTORY_ID } from "@/app/lib";
import { import {
AccentColor, AccentColor,
MainColor, MainColor,
@@ -10,25 +9,17 @@ import {
ComponentGlobal_BoxUploadImage, ComponentGlobal_BoxUploadImage,
ComponentGlobal_ButtonUploadFileImage, ComponentGlobal_ButtonUploadFileImage,
} from "@/app_modules/_global/component"; } from "@/app_modules/_global/component";
import {
funGlobal_DeleteFileById,
funGlobal_UploadToStorage,
} from "@/app_modules/_global/fun";
import { MAX_SIZE } from "@/app_modules/_global/lib";
import { PemberitahuanMaksimalFile } from "@/app_modules/_global/lib/max_size";
import { ComponentGlobal_NotifikasiPeringatan } from "@/app_modules/_global/notif_global/notifikasi_peringatan";
import { import {
AspectRatio, AspectRatio,
Button,
Center, Center,
FileButton,
Image, Image,
Paper, Paper,
Stack, Stack,
TextInput, TextInput
} from "@mantine/core"; } from "@mantine/core";
import { IconCamera, IconPhoto } from "@tabler/icons-react"; import { IconPhoto } from "@tabler/icons-react";
import _ from "lodash"; import _ from "lodash";
import { useParams } from "next/navigation";
import { useState } from "react"; import { useState } from "react";
import Map, { import Map, {
AttributionControl, AttributionControl,
@@ -39,13 +30,9 @@ import Map, {
import { ComponentMap_ButtonSavePin } from "../_component"; import { ComponentMap_ButtonSavePin } from "../_component";
import { defaultLatLong, defaultMapZoom } from "../lib/default_lat_long"; import { defaultLatLong, defaultMapZoom } from "../lib/default_lat_long";
export function UiMap_CreatePin({ export function UiMap_CreatePin({ mapboxToken }: { mapboxToken: string }) {
mapboxToken, const params = useParams<{ id: string }>();
portofolioId, const portofolioId = params.id;
}: {
mapboxToken: string;
portofolioId: string;
}) {
const [[lat, long], setLatLong] = useState([0, 0]); const [[lat, long], setLatLong] = useState([0, 0]);
const [isPin, setIsPin] = useState(false); const [isPin, setIsPin] = useState(false);
const [namePin, setNamePin] = useState(""); const [namePin, setNamePin] = useState("");

View File

@@ -1,17 +1,10 @@
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate"; import UIGlobal_LayoutHeaderTamplate from "@/app_modules/_global/ui/ui_header_tamplate";
import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate"; import UIGlobal_LayoutTamplate from "@/app_modules/_global/ui/ui_layout_tamplate";
import { UiMap_CreatePin } from "../ui/ui_create_pin"; import { UiMap_CreatePin } from "../ui/ui_create_pin";
import ComponentGlobal_IsEmptyData from "@/app_modules/_global/component/is_empty_data";
const mapboxToken = process.env.MAPBOX_TOKEN!; const mapboxToken = process.env.MAPBOX_TOKEN!;
export async function Map_CreateNewPin({ export async function Map_CreateNewPin() {
portofolioId,
}: {
portofolioId: string;
}) {
if (!mapboxToken)
return <ComponentGlobal_IsEmptyData text="Mapbox token not found" />;
return ( return (
<> <>
<UIGlobal_LayoutTamplate <UIGlobal_LayoutTamplate
@@ -19,10 +12,11 @@ export async function Map_CreateNewPin({
<UIGlobal_LayoutHeaderTamplate title="Tambah Pin" hideButtonLeft /> <UIGlobal_LayoutHeaderTamplate title="Tambah Pin" hideButtonLeft />
} }
> >
<UiMap_CreatePin {!mapboxToken ? (
mapboxToken={mapboxToken} <ComponentGlobal_IsEmptyData text="Mapbox token not found" />
portofolioId={portofolioId} ) : (
/> <UiMap_CreatePin mapboxToken={mapboxToken} />
)}
</UIGlobal_LayoutTamplate> </UIGlobal_LayoutTamplate>
</> </>
); );

View File

@@ -35,6 +35,7 @@ const middlewareConfig: MiddlewareConfig = {
// ADMIN API // ADMIN API
// >> buat dibawah sini << // >> buat dibawah sini <<
"/api/admin/collaboration/*", "/api/admin/collaboration/*",
"/api/admin/investasi/*",
// Akses awal // Akses awal
"/api/get-cookie", "/api/get-cookie",