New endpoints; New tests; Version 0.3.0

This commit is contained in:
Aslan 2025-12-28 04:29:42 +01:00
parent 4bc3be87b4
commit 1f3a94cf38
27 changed files with 551 additions and 72 deletions

View file

@ -4,6 +4,7 @@ import { getDB } from "../../store/store.js";
import { getUserFromAuth, isUserAllowed } from "../auth/helpers.js";
import { PERMISSION } from "../auth/permission.js";
import { getCommunityById } from "../community/community.js";
import type { ICreateChannel } from "./types.js";
const getChannelById = async (id: string): Promise<Channel | null> => {
return await getDB().channel.findUnique({
@ -35,4 +36,35 @@ const getChannelByIdAuth = async (
return channel;
};
export { getChannelById, getChannelByIdAuth };
const createChannel = async (create: ICreateChannel): Promise<Channel> => {
return await getDB().channel.create({
data: {
...create,
},
});
};
const createChannelAuth = async (
create: ICreateChannel,
authHeader: string | undefined,
): Promise<Channel | API_ERROR.ACCESS_DENIED> => {
const authUser = await getUserFromAuth(authHeader);
const community = await getCommunityById(create.communityId);
if (
!(await isUserAllowed(
authUser,
{
community: community,
},
community,
[PERMISSION.CHANNELS_MANAGE],
))
) {
return API_ERROR.ACCESS_DENIED;
}
return await createChannel(create);
};
export { getChannelById, getChannelByIdAuth, createChannel, createChannelAuth };