Skip to content

add a comment Endpoint tested with postman #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 { 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 Expand Up @@ -50,7 +47,7 @@
content: comment.content,
message: 'Comment added successfully',
});
} catch (err: any) {

Check warning on line 50 in src/modules/Comment/controller.ts

View workflow job for this annotation

GitHub Actions / Lint and Test

Unexpected any. Specify a different type
res.status(500).send({
message: 'Error in commenting on the news article',
error: err.message,
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
Loading