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

export const getRecentLogs = ({
	module,
	submodule,
	limit = 200,
}: {
	module?: string | undefined;
	submodule?: string | undefined;
	limit?: number | undefined;
}) => {
	return db.query.logs.findMany({
		where: (logs, { and, eq }) =>
			and(
				module ? eq(logs.module, module) : undefined,
				submodule ? eq(logs.subModule, submodule) : undefined,
			),
		orderBy: (logs, { desc }) => [desc(logs.createdAt)],
		limit,
	});
};
