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";
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)) {
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) {

View File

@ -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';

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 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);
// Format and map results