import { getDb, ObjectId, Group } from "../index"; import { Collection, Filter } from "mongodb"; export const getGroupsCollection = (): Collection => { return getDb().collection("groups"); }; export const findGroups = async (filter: Filter): Promise => { return await getGroupsCollection().find(filter).toArray(); }; export const createGroup = async (group: Group) => { const { insertedId } = await getGroupsCollection().insertOne(group); return insertedId; }; export const updateGroup = async ( filter: Filter, data: Partial, ) => { return await getGroupsCollection().findOneAndUpdate( filter, { $set: { ...data, updatedAt: new Date() } }, { returnDocument: "after" }, ); }; export const removeGroup = async (groupId: string) => { return await getGroupsCollection().deleteOne({ _id: new ObjectId(groupId) }); };