import { getDb, Agent, ObjectId } from "../index"; export const getAgentsCollection = () => { return getDb().collection("agents"); }; export const findAgents = async (filter: any = {}) => { return getAgentsCollection().find(filter).toArray(); }; export const findAgentById = (agentId: string) => { return getAgentsCollection().findOne({ _id: new ObjectId(agentId) }); }; export const findAgentsByClientId = (clientId: string) => { return getAgentsCollection().find({ clientId }).toArray(); }; export const createAgent = async (agent: Agent) => { const { insertedId } = await getAgentsCollection().insertOne(agent); return findAgentById(String(insertedId)); }; export const updateAgent = (agentId: string, data: Partial) => { return getAgentsCollection().findOneAndUpdate( { _id: new ObjectId(agentId) }, { $set: data }, { returnDocument: "after" }, ); }; export const removeAgent = (agentId: string) => { return getAgentsCollection().deleteOne({ _id: new ObjectId(agentId) }); };