From 60cb73f8a4d32cbf5f426c2671b748fe1513b4c6 Mon Sep 17 00:00:00 2001 From: Andymick Date: Sat, 18 Jul 2026 19:51:07 +0100 Subject: [PATCH] Fix: Calculate effectivePrice in design API endpoints MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .claude/settings.local.json | 3 ++- src/app/api/designs/[id]/approve/route.ts | 6 +++++- src/app/api/designs/[id]/route.ts | 11 +++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 8c05482..3afad14 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -63,7 +63,8 @@ "Bash(git show *)", "Bash(git status *)", "Bash(git revert *)", - "Bash(git commit -m 'Fix price display issues and layout in design review page *)" + "Bash(git commit -m 'Fix price display issues and layout in design review page *)", + "Bash(git commit -m 'Fix: Calculate effectivePrice in design API endpoints *)" ] } } diff --git a/src/app/api/designs/[id]/approve/route.ts b/src/app/api/designs/[id]/approve/route.ts index 3caee91..e0ed3e4 100644 --- a/src/app/api/designs/[id]/approve/route.ts +++ b/src/app/api/designs/[id]/approve/route.ts @@ -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( diff --git a/src/app/api/designs/[id]/route.ts b/src/app/api/designs/[id]/route.ts index b240fd2..77ac59c 100644 --- a/src/app/api/designs/[id]/route.ts +++ b/src/app/api/designs/[id]/route.ts @@ -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(