import {Session} from "@/hooks/useSessions";
import {Invite, InviteWithUsers} from "@/interfaces/invite";
import {User} from "@/interfaces/user";
import client from "@/lib/mongodb";

const db = client.db(process.env.MONGODB_DB);

export const getInvitesByInvitee = async (id: string, limit?: number) =>
	await db
		.collection("invites")
		.find<Invite>({to: id})
		.limit(limit || 0)
		.toArray();

export const convertInvitersToUsers = async (invite: Invite): Promise<InviteWithUsers> => ({
	...invite,
	from: (await db.collection("users").findOne<User>({id: invite.from})) ?? undefined,
});
