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

@ -3,8 +3,14 @@ import type {
IGetChannelParams,
IGetChannelResponseError,
IGetChannelResponseSuccess,
IPostCreateChannelRequest,
IPostCreateChannelResponseError,
IPostCreateChannelResponseSuccess,
} from "./types.js";
import { getChannelByIdAuth } from "../../services/channel/channel.js";
import {
createChannelAuth,
getChannelByIdAuth,
} from "../../services/channel/channel.js";
import { API_ERROR } from "../errors.js";
const getChannel = async (request: FastifyRequest, reply: FastifyReply) => {
@ -35,4 +41,26 @@ const getChannel = async (request: FastifyRequest, reply: FastifyReply) => {
} as IGetChannelResponseSuccess;
};
export { getChannel };
const postCreateChannel = async (
request: FastifyRequest,
reply: FastifyReply,
) => {
const createChannelRequest = request.body as IPostCreateChannelRequest;
const authHeader = request.headers["authorization"];
const channel = await createChannelAuth(createChannelRequest, authHeader);
if (channel === API_ERROR.ACCESS_DENIED) {
reply.status(403);
return {
error: API_ERROR.ACCESS_DENIED,
} as IPostCreateChannelResponseError;
}
return {
id: channel.id,
name: channel.name,
communityId: channel.communityId,
} as IPostCreateChannelResponseSuccess;
};
export { getChannel, postCreateChannel };