Hoping this lets it build but it probably wont

This commit is contained in:
Gabriel Brown 2024-07-20 21:17:38 -05:00
parent 7bf6f3d8c3
commit 1f80a449a5
3 changed files with 16 additions and 14 deletions

View File

@ -1,17 +1,18 @@
// src/app/api/update_technicians/route.ts
"use server"; "use server";
import { NextResponse } from 'next/server'; import { NextResponse } from 'next/server';
import { legacyUpdateEmployeeStatusByName } from '~/server/functions'; import { legacyUpdateEmployeeStatusByName } from '~/server/functions';
// Define the Technician type directly in the file
interface Technician { interface Technician {
name: string; name: string;
status: string; status: string;
} }
// Type guard to check if an object is a Technician // Type guard to check if an object is a Technician
const isTechnician = (technician: any): technician is Technician => { const isTechnician = (technician: unknown): technician is Technician => {
return typeof technician.name === 'string' && typeof technician.status === 'string'; 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) => { export const POST = async (request: Request) => {
@ -23,18 +24,19 @@ export const POST = async (request: Request) => {
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 }); return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
} }
const { technicians } = await request.json() as { technicians: Technician[] }; const body = await request.json();
if (!Array.isArray(technicians) || technicians.length === 0) {
if (!body || !Array.isArray(body.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 });
} }
for (const technician of technicians) { const technicians: unknown[] = body.technicians;
if (!isTechnician(technician)) {
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 });
} }
}
await legacyUpdateEmployeeStatusByName(technicians); await legacyUpdateEmployeeStatusByName(technicians as Technician[]);
return NextResponse.json({ message: 'Technicians updated successfully.' }, { status: 200 }); return NextResponse.json({ message: 'Technicians updated successfully.' }, { status: 200 });
} catch (error) { } catch (error) {

View File

@ -1,6 +1,6 @@
"use server"; "use server";
import { NextResponse } from 'next/server';
import { NextRequest, NextResponse } from 'next/server'; import type { NextRequest } from 'next/server';
import { updateEmployeeStatus } from '~/server/functions'; import { updateEmployeeStatus } from '~/server/functions';
import { auth } from '~/auth'; import { auth } from '~/auth';

View File

@ -99,7 +99,7 @@ export const legacyGetHistory = async (page: number, perPage: number): Promise<P
const historyRows = historyResults[0] as unknown as { name: string, status: string, updatedAt: Date }[]; const historyRows = historyResults[0] as unknown as { name: string, status: string, updatedAt: Date }[];
const countRow = countResults[0] as unknown as { total_count: number }[]; const countRow = countResults[0] as unknown as { total_count: number }[];
const totalCount = countRow[0]?.total_count || 0; const totalCount = countRow[0]?.total_count ?? 0;
const totalPages = Math.ceil(totalCount / perPage); const totalPages = Math.ceil(totalCount / perPage);
// Format and map results // Format and map results