Add community invites api

This commit is contained in:
Aslan 2026-01-10 19:40:44 -05:00
parent e120a12eaa
commit 23128f25e1
8 changed files with 118 additions and 15 deletions

View file

@ -9,11 +9,12 @@ import {
import { PERMISSION } from "../auth/permission.js";
import type {
ICreateCommunity,
IUpdateCommunity,
ICommunityChannel,
ICommunityMember,
ICommunityRole,
ICommunityInvite,
ICreateInvite,
IUpdateCommunity,
} from "./types.js";
const getCommunityById = async (id: string): Promise<Community | null> => {
@ -227,6 +228,42 @@ const getCommunityRolesByIdAuth = async (
return await getCommunityRolesById(id);
};
const getCommunityInvitesById = async (
id: string,
): Promise<ICommunityInvite[]> => {
return await getDB().invite.findMany({
where: {
communityId: id,
},
select: {
id: true,
},
});
};
const getCommunityInvitesByIdAuth = async (
id: string,
authHeader: string | undefined,
): Promise<ICommunityInvite[] | API_ERROR.ACCESS_DENIED> => {
const authUser = await getUserFromAuth(authHeader);
const community = await getCommunityById(id);
if (
!(await isUserAllowed(
authUser,
{
community: community,
},
community,
[PERMISSION.INVITES_CREATE],
))
) {
return API_ERROR.ACCESS_DENIED;
}
return await getCommunityInvitesById(id);
};
const createInvite = async (
id: string,
creatorId: string,
@ -280,6 +317,8 @@ export {
getCommunityChannelsByIdAuth,
getCommunityRolesById,
getCommunityRolesByIdAuth,
getCommunityInvitesById,
getCommunityInvitesByIdAuth,
createInvite,
createInviteAuth,
};