feat: add Ina Trading portal flows and API integration
This commit is contained in:
68
src/app/api/products/[productId]/route.ts
Normal file
68
src/app/api/products/[productId]/route.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ productId: string }> }
|
||||
) {
|
||||
const token = req.headers.get("x-auth-token") || "";
|
||||
const { productId } = await context.params;
|
||||
const isDraft = req.nextUrl.searchParams.get("draft") === "1";
|
||||
|
||||
const endpoint = isDraft
|
||||
? `${API_URL}/api/v1.0/seller/draft/product/${productId}`
|
||||
: `${API_URL}/api/v1.0/product/${productId}`;
|
||||
|
||||
const res = await fetch(endpoint, {
|
||||
method: "GET",
|
||||
headers: makeHeaders(token),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
|
||||
export async function PUT(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ productId: string }> }
|
||||
) {
|
||||
const token = req.headers.get("x-auth-token") || "";
|
||||
const { productId } = await context.params;
|
||||
const body = await req.json();
|
||||
const isDraft = req.nextUrl.searchParams.get("draft") === "1";
|
||||
|
||||
const endpoint = isDraft
|
||||
? `${API_URL}/api/v1.0/product/draft/${productId}`
|
||||
: `${API_URL}/api/v1.0/product/${productId}`;
|
||||
|
||||
const res = await fetch(endpoint, {
|
||||
method: "PUT",
|
||||
headers: makeHeaders(token),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
|
||||
export async function DELETE(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ productId: string }> }
|
||||
) {
|
||||
const token = req.headers.get("x-auth-token") || "";
|
||||
const { productId } = await context.params;
|
||||
const isDraft = req.nextUrl.searchParams.get("draft") === "1";
|
||||
|
||||
const endpoint = isDraft
|
||||
? `${API_URL}/api/v1.0/product/draft/${productId}`
|
||||
: `${API_URL}/api/v1.0/product/${productId}`;
|
||||
|
||||
const res = await fetch(endpoint, {
|
||||
method: "DELETE",
|
||||
headers: makeHeaders(token),
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
20
src/app/api/products/categories/route.ts
Normal file
20
src/app/api/products/categories/route.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const rawToken = req.headers.get("x-auth-token") || "";
|
||||
const token = rawToken.startsWith("Bearer ") ? rawToken : rawToken ? `Bearer ${rawToken}` : "";
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const page = searchParams.get("page") || "1";
|
||||
const size = searchParams.get("size") || "100";
|
||||
|
||||
const res = await fetch(`${API_URL}/api/v1.0/categories?page=${page}&size=${size}`, {
|
||||
method: "GET",
|
||||
headers: makeHeaders(token),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
16
src/app/api/products/create/route.ts
Normal file
16
src/app/api/products/create/route.ts
Normal file
@ -0,0 +1,16 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const token = req.headers.get("x-auth-token") || "";
|
||||
const body = await req.json();
|
||||
|
||||
const res = await fetch(`${API_URL}/api/v1.0/product`, {
|
||||
method: "POST",
|
||||
headers: makeHeaders(token),
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
31
src/app/api/products/route.ts
Normal file
31
src/app/api/products/route.ts
Normal file
@ -0,0 +1,31 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const token = req.headers.get("x-auth-token") || "";
|
||||
const searchParams = req.nextUrl.searchParams;
|
||||
const tab = searchParams.get("tab");
|
||||
|
||||
const endpointMap: Record<string, string> = {
|
||||
draft: "/api/v1.0/seller/draft/product",
|
||||
"in-review": "/api/v1.0/product/review",
|
||||
"international-market": "/api/v1.0/seller/international/product",
|
||||
"local-market": "/api/v1.0/seller/local/product",
|
||||
"out-of-stock": "/api/v1.0/seller/outofstock/product",
|
||||
rejected: "/api/v1.0/seller/reject/product",
|
||||
};
|
||||
|
||||
const endpoint = endpointMap[tab || ""] || "/api/v1.0/seller/product";
|
||||
const forwardParams = new URLSearchParams(searchParams.toString());
|
||||
forwardParams.delete("tab");
|
||||
const suffix = forwardParams.toString() ? `?${forwardParams.toString()}` : "";
|
||||
|
||||
const res = await fetch(`${API_URL}${endpoint}${suffix}`, {
|
||||
method: "GET",
|
||||
headers: makeHeaders(token),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
24
src/app/api/products/subcategories/[categoryId]/route.ts
Normal file
24
src/app/api/products/subcategories/[categoryId]/route.ts
Normal file
@ -0,0 +1,24 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function GET(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ categoryId: string }> }
|
||||
) {
|
||||
const rawToken = req.headers.get("x-auth-token") || "";
|
||||
const token = rawToken.startsWith("Bearer ") ? rawToken : rawToken ? `Bearer ${rawToken}` : "";
|
||||
const { categoryId } = await context.params;
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const page = searchParams.get("page") || "1";
|
||||
const size = searchParams.get("size") || "100";
|
||||
|
||||
const res = await fetch(`${API_URL}/api/v1.0/sub/${categoryId}/categories?page=${page}&size=${size}`, {
|
||||
method: "GET",
|
||||
headers: makeHeaders(token),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
18
src/app/api/products/submit-review/[productId]/route.ts
Normal file
18
src/app/api/products/submit-review/[productId]/route.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function POST(
|
||||
req: NextRequest,
|
||||
context: { params: Promise<{ productId: string }> }
|
||||
) {
|
||||
const token = req.headers.get("x-auth-token") || "";
|
||||
const { productId } = await context.params;
|
||||
|
||||
const res = await fetch(`${API_URL}/api/v1.0/product/submit-review/${productId}`, {
|
||||
method: "POST",
|
||||
headers: makeHeaders(token),
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
20
src/app/api/products/warehouses/route.ts
Normal file
20
src/app/api/products/warehouses/route.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { API_URL, makeHeaders } from "@/lib/api";
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const rawToken = req.headers.get("x-auth-token") || "";
|
||||
const token = rawToken.startsWith("Bearer ") ? rawToken : rawToken ? `Bearer ${rawToken}` : "";
|
||||
|
||||
const { searchParams } = new URL(req.url);
|
||||
const page = searchParams.get("page") || "1";
|
||||
const size = searchParams.get("size") || "100";
|
||||
|
||||
const res = await fetch(`${API_URL}/api/v1.0/warehouses?page=${page}&size=${size}`, {
|
||||
method: "GET",
|
||||
headers: makeHeaders(token),
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
Reference in New Issue
Block a user