Add design approval workflow infrastructure: PATCH endpoint, email notifications, and message types

- Add PATCH method to /api/designs/[id]/route.ts for status updates
- Create sendDesignReadyForReview email template for customer notifications
- Enhance /api/designs/[id]/messages to support messageType field (MESSAGE | CHANGE_REQUEST)
- Add database migration for messageType field with MESSAGE default

This completes the backend infrastructure for the multi-step design approval workflow:
1. Admin edits and sends design to customer for review
2. Customer approves design or requests changes
3. Admin receives notifications for change requests

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Andymick
2026-07-18 17:11:10 +01:00
co-authored by Claude Haiku 4.5
parent 4d124b1550
commit ac27cc554b
10 changed files with 431 additions and 42 deletions
@@ -0,0 +1,48 @@
import { NextResponse } from 'next/server';
import { prisma } from '@/lib/prisma';
import { getCurrentAdmin } from '@/lib/auth';
import { sendDesignReadyForReview } from '@/lib/mail';
export async function POST(
req: Request,
{ params }: { params: { id: string } }
) {
try {
const admin = await getCurrentAdmin();
if (!admin) {
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
}
const design = await prisma.designApproval.findUnique({
where: { id: params.id },
include: { product: true },
});
if (!design) {
return NextResponse.json({ error: 'Design not found' }, { status: 404 });
}
// Update status to IN_REVIEW
const updated = await prisma.designApproval.update({
where: { id: params.id },
data: { status: 'IN_REVIEW' },
include: { product: true, messages: { orderBy: { createdAt: 'asc' } } },
});
// Send email to customer
await sendDesignReadyForReview({
customerName: design.customerName || 'Customer',
customerEmail: design.customerEmail,
productName: design.product.name,
reviewLink: `${process.env.NEXT_PUBLIC_SITE_URL || 'http://localhost:3000'}/designs/${params.id}/review`,
});
return NextResponse.json(updated);
} catch (err) {
console.error('Error sending design to customer:', err);
return NextResponse.json(
{ error: 'Failed to send design' },
{ status: 500 }
);
}
}