From 1f80a449a574cc414fd43a6c3bae61d2758c461c Mon Sep 17 00:00:00 2001 From: gibbyb Date: Sat, 20 Jul 2024 21:17:38 -0500 Subject: [PATCH] Hoping this lets it build but it probably wont --- src/app/api/update_technicians/route.ts | 24 +++++++++++++----------- src/app/api/v2/update_status/route.ts | 4 ++-- src/server/functions.ts | 2 +- 3 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/app/api/update_technicians/route.ts b/src/app/api/update_technicians/route.ts index 9ec3859..2e844f9 100644 --- a/src/app/api/update_technicians/route.ts +++ b/src/app/api/update_technicians/route.ts @@ -1,17 +1,18 @@ -// src/app/api/update_technicians/route.ts - "use server"; import { NextResponse } from 'next/server'; import { legacyUpdateEmployeeStatusByName } from '~/server/functions'; +// Define the Technician type directly in the file interface Technician { name: string; status: string; } // Type guard to check if an object is a Technician -const isTechnician = (technician: any): technician is Technician => { - return typeof technician.name === 'string' && typeof technician.status === 'string'; +const isTechnician = (technician: unknown): technician is Technician => { + if (typeof technician !== 'object' || technician === null) return false; + return 'name' in technician && typeof (technician as Technician).name === 'string' && + 'status' in technician && typeof (technician as Technician).status === 'string'; }; export const POST = async (request: Request) => { @@ -23,18 +24,19 @@ export const POST = async (request: Request) => { return NextResponse.json({ message: 'Unauthorized' }, { status: 401 }); } - const { technicians } = await request.json() as { technicians: Technician[] }; - if (!Array.isArray(technicians) || technicians.length === 0) { + const body = await request.json(); + + if (!body || !Array.isArray(body.technicians)) { return NextResponse.json({ message: 'Invalid input: expecting an array of technicians.' }, { status: 400 }); } - for (const technician of technicians) { - if (!isTechnician(technician)) { - return NextResponse.json({ message: 'Invalid input: missing name or status for a technician.' }, { status: 400 }); - } + const technicians: unknown[] = body.technicians; + + if (!technicians.every(isTechnician)) { + return NextResponse.json({ message: 'Invalid input: missing name or status for a technician.' }, { status: 400 }); } - await legacyUpdateEmployeeStatusByName(technicians); + await legacyUpdateEmployeeStatusByName(technicians as Technician[]); return NextResponse.json({ message: 'Technicians updated successfully.' }, { status: 200 }); } catch (error) { diff --git a/src/app/api/v2/update_status/route.ts b/src/app/api/v2/update_status/route.ts index 4fc8920..e837ba0 100644 --- a/src/app/api/v2/update_status/route.ts +++ b/src/app/api/v2/update_status/route.ts @@ -1,6 +1,6 @@ "use server"; - -import { NextRequest, NextResponse } from 'next/server'; +import { NextResponse } from 'next/server'; +import type { NextRequest } from 'next/server'; import { updateEmployeeStatus } from '~/server/functions'; import { auth } from '~/auth'; diff --git a/src/server/functions.ts b/src/server/functions.ts index b8425c0..50da3ce 100644 --- a/src/server/functions.ts +++ b/src/server/functions.ts @@ -99,7 +99,7 @@ export const legacyGetHistory = async (page: number, perPage: number): Promise