Fix: Calculate effectivePrice in design API endpoints
The design API was returning raw product data without calculating effectivePrice, which caused prices to not be set when items were added to the cart. Now uses toProductDTO to properly calculate the effective price (accounting for sales) before returning design data. Fixes issue where design reviews showed correct price but cart showed £0.00
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { sendDesignApprovedEmail } from '@/lib/mail';
|
||||
import { toProductDTO } from '@/lib/product';
|
||||
|
||||
export async function POST(
|
||||
req: Request,
|
||||
@@ -30,7 +31,10 @@ export async function POST(
|
||||
checkoutLink,
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
return NextResponse.json({
|
||||
...updated,
|
||||
product: toProductDTO(updated.product),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error approving design:', err);
|
||||
return NextResponse.json(
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { NextResponse } from 'next/server';
|
||||
import { prisma } from '@/lib/prisma';
|
||||
import { getCurrentCustomer } from '@/lib/auth';
|
||||
import { toProductDTO } from '@/lib/product';
|
||||
|
||||
export async function GET(
|
||||
req: Request,
|
||||
@@ -16,7 +17,10 @@ export async function GET(
|
||||
return NextResponse.json({ error: 'Design not found' }, { status: 404 });
|
||||
}
|
||||
|
||||
return NextResponse.json(design);
|
||||
return NextResponse.json({
|
||||
...design,
|
||||
product: toProductDTO(design.product),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error fetching design:', err);
|
||||
return NextResponse.json(
|
||||
@@ -44,7 +48,10 @@ export async function PATCH(
|
||||
include: { product: true, messages: { orderBy: { createdAt: 'asc' } } },
|
||||
});
|
||||
|
||||
return NextResponse.json(updated);
|
||||
return NextResponse.json({
|
||||
...updated,
|
||||
product: toProductDTO(updated.product),
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error updating design:', err);
|
||||
return NextResponse.json(
|
||||
|
||||
Reference in New Issue
Block a user