You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

29 lines
986 B

import { listDocuments, type AgentDocumentType } from "../../service/agent-document";
import { getAgentBySlug } from "../../service/agent/agent";
import { requireUser } from "#server/utils/context";
export default defineWrappedResponseHandler(async (event) => {
const user = await requireUser(event);
const query = getQuery(event);
const page = Math.max(1, parseInt(String(query.page || "1")));
const pageSize = Math.min(100, Math.max(1, parseInt(String(query.pageSize || "20"))));
const type = query.type as AgentDocumentType | undefined;
const keyword = query.keyword as string | undefined;
const agentSlug = query.agentSlug as string | undefined;
let agentId: number | null | undefined = undefined;
if (agentSlug) {
const agent = await getAgentBySlug(agentSlug);
agentId = agent?.id ?? null;
}
const result = await listDocuments({
userId: user.id,
agentId,
type,
keyword,
page,
pageSize,
});
return R.success(result);
});