Hoping this lets it build but it probably wont
This commit is contained in:
parent
1f80a449a5
commit
620182fe02
@ -15,6 +15,11 @@ const isTechnician = (technician: unknown): technician is Technician => {
|
|||||||
'status' in technician && typeof (technician as Technician).status === 'string';
|
'status' in technician && typeof (technician as Technician).status === 'string';
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Ensure the body is properly typed
|
||||||
|
interface RequestBody {
|
||||||
|
technicians: Technician[];
|
||||||
|
}
|
||||||
|
|
||||||
export const POST = async (request: Request) => {
|
export const POST = async (request: Request) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
@ -24,13 +29,14 @@ export const POST = async (request: Request) => {
|
|||||||
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
|
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const body = await request.json();
|
const body: unknown = await request.json();
|
||||||
|
|
||||||
if (!body || !Array.isArray(body.technicians)) {
|
// Type assert body to RequestBody only after validation
|
||||||
|
if (typeof body !== 'object' || body === null || !Array.isArray((body as { technicians?: unknown }).technicians)) {
|
||||||
return NextResponse.json({ message: 'Invalid input: expecting an array of technicians.' }, { status: 400 });
|
return NextResponse.json({ message: 'Invalid input: expecting an array of technicians.' }, { status: 400 });
|
||||||
}
|
}
|
||||||
|
|
||||||
const technicians: unknown[] = body.technicians;
|
const technicians: unknown[] = (body as { technicians: unknown }).technicians;
|
||||||
|
|
||||||
if (!technicians.every(isTechnician)) {
|
if (!technicians.every(isTechnician)) {
|
||||||
return NextResponse.json({ message: 'Invalid input: missing name or status for a technician.' }, { status: 400 });
|
return NextResponse.json({ message: 'Invalid input: missing name or status for a technician.' }, { status: 400 });
|
||||||
|
Loading…
Reference in New Issue
Block a user