27 lines
773 B
TypeScript
27 lines
773 B
TypeScript
import { type FastifyReply, type FastifyRequest } from "fastify";
|
|
import type {
|
|
ICommunityParams,
|
|
ICommunityResponseError,
|
|
ICommunityResponseSuccess,
|
|
} from "./types.js";
|
|
import { getCommunityById } from "../../services/community/community.js";
|
|
|
|
const getCommunity = async (request: FastifyRequest, _reply: FastifyReply) => {
|
|
const { id } = request.params as ICommunityParams;
|
|
|
|
const community = await getCommunityById(id);
|
|
if (!community) {
|
|
return {
|
|
id: id,
|
|
error: "community does not exist",
|
|
} as ICommunityResponseError;
|
|
}
|
|
|
|
return {
|
|
id: community.id,
|
|
name: community.name,
|
|
description: community.description,
|
|
} as ICommunityResponseSuccess;
|
|
};
|
|
|
|
export { getCommunity };
|