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:
Andymick
2026-07-18 19:51:07 +01:00
parent 62ae2755f0
commit 60cb73f8a4
3 changed files with 16 additions and 4 deletions
+2 -1
View File
@@ -63,7 +63,8 @@
"Bash(git show *)", "Bash(git show *)",
"Bash(git status *)", "Bash(git status *)",
"Bash(git revert *)", "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 *)"
] ]
} }
} }
+5 -1
View File
@@ -1,6 +1,7 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
import { sendDesignApprovedEmail } from '@/lib/mail'; import { sendDesignApprovedEmail } from '@/lib/mail';
import { toProductDTO } from '@/lib/product';
export async function POST( export async function POST(
req: Request, req: Request,
@@ -30,7 +31,10 @@ export async function POST(
checkoutLink, checkoutLink,
}); });
return NextResponse.json(updated); return NextResponse.json({
...updated,
product: toProductDTO(updated.product),
});
} catch (err) { } catch (err) {
console.error('Error approving design:', err); console.error('Error approving design:', err);
return NextResponse.json( return NextResponse.json(
+9 -2
View File
@@ -1,6 +1,7 @@
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma'; import { prisma } from '@/lib/prisma';
import { getCurrentCustomer } from '@/lib/auth'; import { getCurrentCustomer } from '@/lib/auth';
import { toProductDTO } from '@/lib/product';
export async function GET( export async function GET(
req: Request, req: Request,
@@ -16,7 +17,10 @@ export async function GET(
return NextResponse.json({ error: 'Design not found' }, { status: 404 }); return NextResponse.json({ error: 'Design not found' }, { status: 404 });
} }
return NextResponse.json(design); return NextResponse.json({
...design,
product: toProductDTO(design.product),
});
} catch (err) { } catch (err) {
console.error('Error fetching design:', err); console.error('Error fetching design:', err);
return NextResponse.json( return NextResponse.json(
@@ -44,7 +48,10 @@ export async function PATCH(
include: { product: true, messages: { orderBy: { createdAt: 'asc' } } }, include: { product: true, messages: { orderBy: { createdAt: 'asc' } } },
}); });
return NextResponse.json(updated); return NextResponse.json({
...updated,
product: toProductDTO(updated.product),
});
} catch (err) { } catch (err) {
console.error('Error updating design:', err); console.error('Error updating design:', err);
return NextResponse.json( return NextResponse.json(