- Vintage Modell hinzugefuegt - Equipment Multi-Select (Neue Buchung + Bearbeitung) - Kundenadresse in Formularen - Bearbeiten-Seite fuer Buchungen - Abbau-Zeiten in Formularen und Uebersicht - Vertrag PDF nur bei Privatkunden - LexOffice Kontakt-Erstellung Fix (BUSINESS) - Zurueck-Pfeil auf Touren-Seite
77 lines
2.0 KiB
TypeScript
77 lines
2.0 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { getServerSession } from 'next-auth';
|
|
import { authOptions } from '@/lib/auth';
|
|
import { prisma } from '@/lib/prisma';
|
|
|
|
export async function PATCH(
|
|
request: NextRequest,
|
|
{ params }: { params: { id: string } }
|
|
) {
|
|
try {
|
|
const session = await getServerSession(authOptions);
|
|
|
|
if (!session || session.user.role !== 'DRIVER') {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const body = await request.json();
|
|
const { status } = body;
|
|
|
|
if (!status) {
|
|
return NextResponse.json({ error: 'Status is required' }, { status: 400 });
|
|
}
|
|
|
|
const tourStop = await prisma.tourStop.findUnique({
|
|
where: { id: params.id },
|
|
include: {
|
|
tour: {
|
|
select: {
|
|
driverId: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
|
|
if (!tourStop) {
|
|
return NextResponse.json({ error: 'Tour stop not found' }, { status: 404 });
|
|
}
|
|
|
|
if (tourStop.tour.driverId !== session.user.id) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 403 });
|
|
}
|
|
|
|
const updateData: any = { status };
|
|
|
|
switch (status) {
|
|
case 'ARRIVED':
|
|
updateData.arrivedAt = new Date();
|
|
break;
|
|
case 'SETUP_IN_PROGRESS':
|
|
updateData.setupStartedAt = new Date();
|
|
break;
|
|
case 'SETUP_COMPLETE':
|
|
updateData.setupCompleteAt = new Date();
|
|
break;
|
|
case 'PICKUP_IN_PROGRESS':
|
|
updateData.pickupStartedAt = new Date();
|
|
break;
|
|
case 'PICKUP_COMPLETE':
|
|
updateData.pickupCompleteAt = new Date();
|
|
break;
|
|
}
|
|
|
|
const updatedStop = await prisma.tourStop.update({
|
|
where: { id: params.id },
|
|
data: updateData,
|
|
});
|
|
|
|
return NextResponse.json({ tourStop: updatedStop });
|
|
} catch (error: any) {
|
|
console.error('Status update error:', error);
|
|
return NextResponse.json(
|
|
{ error: error.message || 'Failed to update status' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|