feat(products): implement category selection and product creation in receipt import
This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
|
||||
|
||||
export async function GET() {
|
||||
const res = await fetch(`${API_BASE}/api/categories/tree`, { cache: 'no-store' });
|
||||
export async function GET(req: NextRequest) {
|
||||
const isTree = req.nextUrl.searchParams.has('tree');
|
||||
const endpoint = isTree ? '/api/categories/tree' : '/api/categories';
|
||||
const res = await fetch(`${API_BASE}${endpoint}`, { cache: 'no-store' });
|
||||
const text = await res.text();
|
||||
return new NextResponse(text, {
|
||||
status: res.status,
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthHeaders } from '../../../../lib/auth-headers';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
|
||||
|
||||
export async function PATCH(req: NextRequest, { params }: { params: { id: string } }) {
|
||||
const authHeaders = await getAuthHeaders();
|
||||
const body = await req.json();
|
||||
const res = await fetch(`${API_BASE}/api/products/${params.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json', ...authHeaders },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { getAuthHeaders } from '../../../lib/auth-headers';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
|
||||
|
||||
@@ -10,7 +11,18 @@ export async function GET(req: NextRequest) {
|
||||
const res = await fetch(`${API_BASE}/api/products${query ? `?${query}` : ''}`, {
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
const data = await res.json();
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const authHeaders = await getAuthHeaders();
|
||||
const body = await req.json();
|
||||
const res = await fetch(`${API_BASE}/api/products`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...authHeaders },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
const data = await res.json();
|
||||
return NextResponse.json(data, { status: res.status });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user