Mostly Front End & UI fixes

This commit is contained in:
2024-07-20 09:12:29 -05:00
parent 8e02288d3d
commit 5f020bf542
12 changed files with 176 additions and 151 deletions

View File

@ -1,18 +0,0 @@
"use server";
import type { NextApiRequest, NextApiResponse } from 'next';
import { getEmployees } from '~/server/functions';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'GET') {
try {
const employees = await getEmployees();
res.status(200).json(employees);
} catch (error) {
console.error('Error fetching employees:', error);
res.status(500).json({ message: 'Internal server error' });
}
} else {
res.setHeader('Allow', ['GET']);
res.status(405).json({ message: `Method ${req.method} Not Allowed` });
}
}

View File

@ -0,0 +1,18 @@
"use server";
import { NextResponse } from 'next/server';
import { getEmployees } from '~/server/functions';
import { auth } from '~/auth';
export const GET = async () => {
try {
const session = await auth();
if (!session)
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
const employees = await getEmployees();
return NextResponse.json(employees, { status: 200 });
} catch (error) {
console.error('Error fetching employees:', error);
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
}
};

View File

@ -1,29 +0,0 @@
"use server";
import type { NextApiRequest, NextApiResponse } from 'next';
import { updateEmployeeStatus } from '~/server/functions';
type UpdateStatusBody = {
employeeIds: number[];
newStatus: string;
};
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
if (req.method === 'POST') {
const { employeeIds, newStatus } = req.body as UpdateStatusBody;
if (!Array.isArray(employeeIds) || typeof newStatus !== 'string') {
return res.status(400).json({ message: 'Invalid input' });
}
try {
await updateEmployeeStatus(employeeIds, newStatus);
return res.status(200).json({ message: 'Status updated successfully' });
} catch (error) {
console.error('Error updating status:', error);
return res.status(500).json({ message: 'Internal server error' });
}
} else {
res.setHeader('Allow', ['POST']);
return res.status(405).json({ message: `Method ${req.method} Not Allowed` });
}
}

View File

@ -0,0 +1,30 @@
"use server";
import { NextRequest, NextResponse } from 'next/server';
import { updateEmployeeStatus } from '~/server/functions';
import { auth } from '~/auth';
type UpdateStatusBody = {
employeeIds: string[];
newStatus: string;
};
export const POST = async (req: NextRequest) => {
const session = await auth();
if (!session)
return NextResponse.json({ message: 'Unauthorized' }, { status: 401 });
const { employeeIds, newStatus } = await req.json() as UpdateStatusBody;
if (!Array.isArray(employeeIds) || typeof newStatus !== 'string') {
return NextResponse.json({ message: 'Invalid input' }, { status: 400 });
}
try {
await updateEmployeeStatus(employeeIds, newStatus);
return NextResponse.json({ message: 'Status updated successfully' }, { status: 200 });
} catch (error) {
console.error('Error updating status:', error);
return NextResponse.json({ message: 'Internal server error' }, { status: 500 });
}
};