2025-02-07 12:25:04 +01:00

28 lines
1.0 KiB
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?.customer_id) {
return NextResponse.json({ error: 'User not logged' }, { status: 401 });
}
const customer = await woocommerce.get('customers', { id: session?.user.customer_id });
return NextResponse.json(customer, { 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 customer = await woocommerce.post('customers', data);
return NextResponse.json(customer, { status: 200 });
} catch (error) {
return NextResponse.json({ error: 'Failed to add item to customer' }, { status: 500 });
}
}