feat: bunch of work done here, got comments and edit and delete

This commit is contained in:
2026-02-04 13:00:16 -08:00
parent b6d66d34cb
commit 318f3bc500
19 changed files with 1868 additions and 117 deletions
+38 -1
View File
@@ -5,12 +5,14 @@
*/
import { FastifyPluginAsync } from "fastify";
import { Game, CreateGameDto, UpdateGameDto } from "@library/shared-types";
import { Game, CreateGameDto, UpdateGameDto, Comment, CreateCommentDto } from "@library/shared-types";
import { GameService } from "../../services/game.service";
import { CommentService } from "../../services/comment.service";
import { adminGuard } from "../../middleware/admin-guard";
const gamesRoutes: FastifyPluginAsync = async (app) => {
const gameService = new GameService();
const commentService = new CommentService();
// Get all games (public route)
app.get<{ Reply: Game[] }>("/", async () => {
@@ -65,6 +67,41 @@ const gamesRoutes: FastifyPluginAsync = async (app) => {
return { success: true };
}
);
// Get comments for a game (public route)
app.get<{ Params: { id: string }; Reply: Comment[] }>(
"/:id/comments",
async (request) => {
const { id } = request.params;
return commentService.getCommentsForGame(id);
}
);
// Add comment to a game (authenticated users)
app.post<{ Params: { id: string }; Body: CreateCommentDto; Reply: Comment }>(
"/:id/comments",
{
preValidation: [app.authenticate],
},
async (request) => {
const { id } = request.params;
const userId = request.user.id;
return commentService.createCommentForGame(id, userId, request.body);
}
);
// Delete comment (admin only)
app.delete<{ Params: { id: string; commentId: string }; Reply: { success: boolean } }>(
"/:id/comments/:commentId",
{
preValidation: [app.authenticate, adminGuard],
},
async (request) => {
const { commentId } = request.params;
await commentService.deleteComment(commentId);
return { success: true };
}
);
};
export default gamesRoutes;