Skip to content

Commit

Permalink
add a comment Endpoint tested with postman
Browse files Browse the repository at this point in the history
  • Loading branch information
bojana-petroska committed Dec 11, 2024
1 parent 549c4aa commit 5d7e4dd
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/entities/Comment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class Comment {
@ManyToOne(() => News)
news!: News;

@Column({ nullable: false })
@Column()
content!: string;

@Column({ type: 'timestamp', nullable: true })
Expand Down
2 changes: 2 additions & 0 deletions src/entities/index.ts
Original file line number Diff line number Diff line change
@@ -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,
};
3 changes: 0 additions & 3 deletions src/modules/Comment/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Comment/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
'/',
Expand Down
2 changes: 1 addition & 1 deletion src/modules/Comment/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}),
};

Expand Down
1 change: 0 additions & 1 deletion src/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5d7e4dd

Please sign in to comment.