29 lines
763 B
TypeScript
29 lines
763 B
TypeScript
import Elysia, { t } from "elysia";
|
|
import authMiddleware from "../middlewares/auth";
|
|
import getComments from "../services/comments/getComments";
|
|
import { createComment } from "../services/comments/createComment";
|
|
|
|
export const commentsController = new Elysia({ prefix: "comments" })
|
|
.use(authMiddleware)
|
|
.get(
|
|
"/:sessionId",
|
|
async ({ params: { sessionId }, auth: { userId } }) =>
|
|
await getComments(sessionId, userId),
|
|
{
|
|
params: t.Object({
|
|
sessionId: t.String(),
|
|
}),
|
|
}
|
|
)
|
|
.post(
|
|
"/",
|
|
async ({ auth: { userId }, body: { text, sessionId } }) =>
|
|
await createComment({ userId, text, sessionId }),
|
|
{
|
|
body: t.Object({
|
|
text: t.String(),
|
|
sessionId: t.String(),
|
|
}),
|
|
}
|
|
);
|