53 lines
1.5 KiB
TypeScript
53 lines
1.5 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { AuditColumns, AuditData, AuditSearchLabels } from "./mockData";
|
|
import { formatToDateTimeString } from "@/app/utils/formatDate";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
const { searchParams } = new URL(request.url);
|
|
|
|
const actionType = searchParams.get("actionType");
|
|
const affectedUserId = searchParams.get("affectedUserId");
|
|
const adminId = searchParams.get("adminId");
|
|
const adminUsername = searchParams.get("adminUsername");
|
|
const timeStampOfTheAction = searchParams.get("dateTime");
|
|
|
|
let filteredRows = [...AuditData];
|
|
|
|
if (actionType) {
|
|
filteredRows = filteredRows.filter(
|
|
(tx) => tx.actionType.toLocaleLowerCase() === actionType.toLocaleLowerCase(),
|
|
);
|
|
}
|
|
|
|
if (affectedUserId) {
|
|
filteredRows = filteredRows.filter(
|
|
(tx) => tx.affectedUserId.toLowerCase() === affectedUserId.toLowerCase(),
|
|
);
|
|
}
|
|
|
|
if (adminId) {
|
|
filteredRows = filteredRows.filter(
|
|
(tx) => tx.adminId === adminId,
|
|
);
|
|
}
|
|
if (adminUsername) {
|
|
filteredRows = filteredRows.filter(
|
|
(tx) => tx.adminUsername === adminUsername,
|
|
);
|
|
}
|
|
|
|
if (timeStampOfTheAction) {
|
|
filteredRows = filteredRows.filter(
|
|
(tx) =>
|
|
tx.timeStampOfTheAction.split(" ")[0] ===
|
|
formatToDateTimeString(timeStampOfTheAction).split(" ")[0],
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({
|
|
tableRows: filteredRows,
|
|
tableColumns: AuditColumns,
|
|
tableSearchLabels: AuditSearchLabels,
|
|
});
|
|
}
|