Add more services; Version 0.3.3

This commit is contained in:
Aslan 2025-12-29 02:02:56 +01:00
parent 50348cc494
commit ddcc591d12
26 changed files with 887 additions and 38 deletions

View file

@ -6,10 +6,19 @@ import type {
IPostCreateChannelRequest,
IPostCreateChannelResponseError,
IPostCreateChannelResponseSuccess,
IPatchChannelParams,
IPatchChannelRequest,
IPatchChannelResponseError,
IPatchChannelResponseSuccess,
IDeleteChannelParams,
IDeleteChannelResponseError,
IDeleteChannelResponseSuccess,
} from "./types.js";
import {
createChannelAuth,
deleteChannelByIdAuth,
getChannelByIdAuth,
updateChannelByIdAuth,
} from "../../services/channel/channel.js";
import { API_ERROR } from "../errors.js";
@ -63,4 +72,62 @@ const postCreateChannel = async (
} as IPostCreateChannelResponseSuccess;
};
export { getChannel, postCreateChannel };
const patchChannel = async (request: FastifyRequest, reply: FastifyReply) => {
const { id } = request.params as IPatchChannelParams;
const patchChannelRequest = request.body as IPatchChannelRequest;
const authHeader = request.headers["authorization"];
const channel = await updateChannelByIdAuth(
id,
patchChannelRequest,
authHeader,
);
if (!channel) {
reply.status(404);
return {
id: id,
error: API_ERROR.NOT_FOUND,
} as IPatchChannelResponseError;
}
if (channel === API_ERROR.ACCESS_DENIED) {
reply.status(403);
return {
id: id,
error: API_ERROR.ACCESS_DENIED,
} as IPatchChannelResponseError;
}
return {
id: channel.id,
name: channel.name,
communityId: channel.communityId,
} as IPatchChannelResponseSuccess;
};
const deleteChannel = async (request: FastifyRequest, reply: FastifyReply) => {
const { id } = request.params as IDeleteChannelParams;
const authHeader = request.headers["authorization"];
const channel = await deleteChannelByIdAuth(id, authHeader);
if (!channel) {
reply.status(404);
return {
id: id,
error: API_ERROR.NOT_FOUND,
} as IDeleteChannelResponseError;
}
if (channel === API_ERROR.ACCESS_DENIED) {
reply.status(403);
return {
id: id,
error: API_ERROR.ACCESS_DENIED,
} as IDeleteChannelResponseError;
}
return {
id: channel.id,
communityId: channel.communityId,
} as IDeleteChannelResponseSuccess;
};
export { getChannel, postCreateChannel, patchChannel, deleteChannel };