import { db } from "../db/db.controller.js";

export const getRecentDockScans = ({
	loadingOrder,
	limit = 200,
}: {
	loadingOrder: string;
	limit?: number | undefined;
}) => {
	return db.query.dockDoorScans.findMany({
		//where: (scans, { eq }) => eq(scans.status, "active"),
		where: (scans, { and, eq }) =>
			and(
				eq(scans.status, "active"),
				loadingOrder
					? eq(scans.loadingOrder, loadingOrder)
					: eq(scans.loadingOrder, "0"),
			),
		orderBy: (scans, { desc }) => [desc(scans.upd_date)],
		limit,
	});
};
