Fixes after changing api names
This commit is contained in:
parent
a849b065a1
commit
8a00507431
@ -1,17 +1,21 @@
|
|||||||
"use server";
|
"use server";
|
||||||
import { NextResponse } from 'next/server';
|
import { NextResponse } from 'next/server';
|
||||||
import { getHistory } from '~/server/functions';
|
import { getHistory } from '~/server/functions';
|
||||||
|
import { auth } from '~/auth';
|
||||||
|
|
||||||
export const GET = async (request: Request) => {
|
export const GET = async (request: Request) => {
|
||||||
try {
|
try {
|
||||||
const url = new URL(request.url);
|
const url = new URL(request.url);
|
||||||
const apiKey = url.searchParams.get('apikey');
|
const apiKey = url.searchParams.get('apikey');
|
||||||
const page = Number(url.searchParams.get('page')) || 1;
|
const page = Number(url.searchParams.get('page')) || 1;
|
||||||
if (apiKey !== process.env.API_KEY)
|
if (apiKey !== process.env.API_KEY) {
|
||||||
return NextResponse.json(
|
const session = await auth();
|
||||||
{ message: 'Unauthorized' },
|
if (!session)
|
||||||
{ status: 401 }
|
return NextResponse.json(
|
||||||
);
|
{ message: 'Unauthorized' },
|
||||||
|
{ status: 401 }
|
||||||
|
);
|
||||||
|
}
|
||||||
const perPage = 50;
|
const perPage = 50;
|
||||||
const historyData = await getHistory(page, perPage);
|
const historyData = await getHistory(page, perPage);
|
||||||
return NextResponse.json(historyData, { status: 200 });
|
return NextResponse.json(historyData, { status: 200 });
|
||||||
|
@ -56,7 +56,7 @@ export const updateEmployeeStatusByName =
|
|||||||
interface HistoryEntry {
|
interface HistoryEntry {
|
||||||
name: string;
|
name: string;
|
||||||
status: string;
|
status: string;
|
||||||
time: Date;
|
updatedAt: Date;
|
||||||
}
|
}
|
||||||
interface PaginatedHistory {
|
interface PaginatedHistory {
|
||||||
data: HistoryEntry[];
|
data: HistoryEntry[];
|
||||||
@ -96,7 +96,7 @@ export const getHistory =
|
|||||||
const formattedResults: HistoryEntry[] = historyRows.map(row => ({
|
const formattedResults: HistoryEntry[] = historyRows.map(row => ({
|
||||||
name: row.name,
|
name: row.name,
|
||||||
status: row.status,
|
status: row.status,
|
||||||
time: new Date(row.updatedAt),
|
updatedAt: new Date(row.updatedAt),
|
||||||
}));
|
}));
|
||||||
return {
|
return {
|
||||||
data: formattedResults,
|
data: formattedResults,
|
||||||
|
Loading…
Reference in New Issue
Block a user