From 5d7e4dd40316f0bf052aea0dd1448ef1933b2fb8 Mon Sep 17 00:00:00 2001 From: bojana-petroska Date: Wed, 11 Dec 2024 15:12:34 +0100 Subject: [PATCH] add a comment Endpoint tested with postman --- src/entities/Comment.ts | 2 +- src/entities/index.ts | 2 ++ src/modules/Comment/controller.ts | 3 --- src/modules/Comment/routes.ts | 2 +- src/modules/Comment/validation.ts | 2 +- src/routes.ts | 1 - 6 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/entities/Comment.ts b/src/entities/Comment.ts index 8dda9f4..1b078be 100644 --- a/src/entities/Comment.ts +++ b/src/entities/Comment.ts @@ -13,7 +13,7 @@ export class Comment { @ManyToOne(() => News) news!: News; - @Column({ nullable: false }) + @Column() content!: string; @Column({ type: 'timestamp', nullable: true }) diff --git a/src/entities/index.ts b/src/entities/index.ts index ba67347..b02113a 100644 --- a/src/entities/index.ts +++ b/src/entities/index.ts @@ -1,9 +1,11 @@ import { User } from './User.js'; import { News } from './News.js'; import { Bookmark } from './Bookmark.js'; +import { Comment } from './Comment.js'; export default { User, News, Bookmark, + Comment, }; diff --git a/src/modules/Comment/controller.ts b/src/modules/Comment/controller.ts index f734d0a..cae810c 100644 --- a/src/modules/Comment/controller.ts +++ b/src/modules/Comment/controller.ts @@ -11,9 +11,6 @@ const commentOnNewsArticle = async (req: Request, res: Response) => { const { title, description, source, url, publishedAt, content, timeStamp } = req.body; - console.log('Request body:', req.body); - console.log('Content:', content); - if (!user) { res.status(401).send({ message: 'Unauthorized' }); return; diff --git a/src/modules/Comment/routes.ts b/src/modules/Comment/routes.ts index 3b206d1..baac1f7 100644 --- a/src/modules/Comment/routes.ts +++ b/src/modules/Comment/routes.ts @@ -4,7 +4,7 @@ import commentsController from '../Comment/controller.js'; import { validateRequest } from '../../middleware/validateRequest.js'; import commentsValidationSchema from './validation.js'; -const router = Router({ mergeParams: true }); +const router = Router(); router.post( '/', diff --git a/src/modules/Comment/validation.ts b/src/modules/Comment/validation.ts index ae0a9c9..8daa27a 100644 --- a/src/modules/Comment/validation.ts +++ b/src/modules/Comment/validation.ts @@ -7,7 +7,7 @@ const comments = { source: Joi.string().required(), url: Joi.string().required(), publishedAt: Joi.string().required(), - content: Joi.string().required(), + content: Joi.string().required().min(2), }), }; diff --git a/src/routes.ts b/src/routes.ts index 7ce8009..41b16b6 100644 --- a/src/routes.ts +++ b/src/routes.ts @@ -3,7 +3,6 @@ import Router from 'express'; import userRoutes from './modules/User/routes.js'; import newsRoutes from './modules/News/routes.js'; import bookmarkRouter from './modules/Bookmark/routes.js'; - import commentsRoutes from './modules/Comment/routes.js'; const router = Router();