2025-01-02 12:16:25 +01:00

28 lines
1004 B
TypeScript

import { authOptions } from 'lib/auth/config';
import { woocommerce } from 'lib/woocomerce/woocommerce';
import { getServerSession } from 'next-auth';
import { NextRequest, NextResponse } from 'next/server';
export async function GET(req: NextRequest) {
try {
const session = await getServerSession(authOptions);
if (!session?.user?.store_id) {
return NextResponse.json({ error: 'User not logged' }, { status: 401 });
}
const cart = await woocommerce.get('customers', { id: session?.user.store_id });
return NextResponse.json(cart, { status: 200 });
} catch (error) {
return NextResponse.json({ error: JSON.stringify(error) }, { status: 500 });
}
}
export async function POST(req: NextRequest) {
try {
const data = await req.json();
const cart = await woocommerce.post('customers', data);
return NextResponse.json(cart, { status: 200 });
} catch (error) {
return NextResponse.json({ error: 'Failed to add item to cart' }, { status: 500 });
}
}