-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #985 from parlemonde/ft/VIL-573
Ft/vil 573
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }; |