Skip to content

Commit

Permalink
Merge pull request #985 from parlemonde/ft/VIL-573
Browse files Browse the repository at this point in the history
Ft/vil 573
  • Loading branch information
SimNed authored Sep 9, 2024
2 parents 422cf77 + 940acbc commit 7cdb51e
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
2 changes: 2 additions & 0 deletions server/controllers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { statisticsController } from './statistics';
import { storyController } from './story';
import { studentController } from './student';
import { teacherController } from './teacher';
import { teamCommentController } from './teamComment';
import { userController } from './user';
import { videoController } from './video';
import { villageController } from './village';
Expand Down Expand Up @@ -45,6 +46,7 @@ const controllers = [
studentController,
featureFlagController,
statisticsController,
teamCommentController,
pelicoController,
mediathequeController,
];
Expand Down
33 changes: 33 additions & 0 deletions server/controllers/teamComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import type { NextFunction, Request, Response } from 'express';

import { TeamComment } from '../entities/teamComment';
import { UserType } from '../entities/user';
import { AppDataSource } from '../utils/data-source';
import { Controller } from './controller';

const teamCommentController = new Controller('/team-comments');

// --- Get all comments. ---
teamCommentController.get({ path: '', userType: UserType.ADMIN }, async (req: Request, res: Response) => {
const teamComments = await AppDataSource.getRepository(TeamComment).find();
res.sendJSON(teamComments);
});

// --- Edit one comment. ---
teamCommentController.put({ path: '/:commentId', userType: UserType.ADMIN }, async (req: Request, res: Response, next: NextFunction) => {
const data = req.body;
const id = parseInt(req.params.commentId, 10) ?? 0;
const teamComment = await AppDataSource.getRepository(TeamComment).findOne({ where: { id } });
if (!teamComment) {
next();
return;
}

const updatedTeamComment = new TeamComment();
updatedTeamComment.id = id;
updatedTeamComment.text = data.text;
await AppDataSource.getRepository(TeamComment).save(updatedTeamComment);
res.sendJSON(updatedTeamComment);
});

export { teamCommentController };

0 comments on commit 7cdb51e

Please sign in to comment.