feat: add functionality for managing deleted products, including restoration and permanent deletion
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
import { withAuth } from '../../../../../../lib/with-auth';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
|
||||
|
||||
export const POST = withAuth(async (_req, session, context) => {
|
||||
const { id } = await context.params;
|
||||
const productId = Number(id);
|
||||
if (!productId) return Response.json({ error: 'Ogiltigt id' }, { status: 400 });
|
||||
|
||||
const res = await fetch(`${API_BASE}/api/products/${productId}/restore`, {
|
||||
method: 'POST',
|
||||
headers: { Authorization: `Bearer ${session.accessToken}` },
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return Response.json(data, { status: res.status });
|
||||
});
|
||||
|
||||
export const DELETE = withAuth(async (_req, session, context) => {
|
||||
const { id } = await context.params;
|
||||
const productId = Number(id);
|
||||
if (!productId) return Response.json({ error: 'Ogiltigt id' }, { status: 400 });
|
||||
|
||||
const res = await fetch(`${API_BASE}/api/products/${productId}/permanent`, {
|
||||
method: 'DELETE',
|
||||
headers: { Authorization: `Bearer ${session.accessToken}` },
|
||||
});
|
||||
const data = await res.json().catch(() => ({}));
|
||||
return Response.json(data, { status: res.status });
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
import { withAuth } from '../../../../lib/with-auth';
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL_INTERNAL || 'http://recipe-api:8080';
|
||||
|
||||
export const GET = withAuth(async (_req, session) => {
|
||||
const res = await fetch(`${API_BASE}/api/products/deleted`, {
|
||||
headers: { Authorization: `Bearer ${session.accessToken}` },
|
||||
});
|
||||
const data = await res.json().catch(() => ([]));
|
||||
return Response.json(data, { status: res.status });
|
||||
});
|
||||
Reference in New Issue
Block a user