Add messaging

This commit is contained in:
Aslan 2026-01-11 14:17:13 -05:00
parent 23128f25e1
commit 5733975aa0
29 changed files with 986 additions and 8 deletions

View file

@ -13,12 +13,16 @@ import type {
IDeleteChannelParams,
IDeleteChannelResponseError,
IDeleteChannelResponseSuccess,
IGetMessagesParams,
IGetMessagesResponseError,
IGetMessagesResponseSuccess,
} from "./types.js";
import {
createChannelAuth,
deleteChannelByIdAuth,
getChannelByIdAuth,
updateChannelByIdAuth,
getChannelMessagesByIdAuth,
} from "../../services/channel/channel.js";
import { API_ERROR } from "../errors.js";
@ -135,4 +139,42 @@ const deleteChannel = async (request: FastifyRequest, reply: FastifyReply) => {
} as IDeleteChannelResponseSuccess;
};
export { getChannel, postCreateChannel, patchChannel, deleteChannel };
const getMessages = async (request: FastifyRequest, reply: FastifyReply) => {
const { id } = request.params as IGetMessagesParams;
const authHeader = request.headers["authorization"];
const messages = await getChannelMessagesByIdAuth(id, authHeader);
if (!messages) {
reply.status(404);
return {
id: id,
error: API_ERROR.NOT_FOUND,
} as IGetMessagesResponseError;
}
if (messages === API_ERROR.ACCESS_DENIED) {
reply.status(403);
return {
id: id,
error: API_ERROR.ACCESS_DENIED,
} as IGetMessagesResponseError;
}
return {
id: id,
messages: messages.map((message) => ({
id: message.id,
text: message.text,
edited: message.edited,
ownerId: message.ownerId,
creationDate: message.creationDate.getTime(),
})),
} as IGetMessagesResponseSuccess;
};
export {
getChannel,
postCreateChannel,
patchChannel,
deleteChannel,
getMessages,
};