added endpoint for retrieving users' posts, updated userShouldExist middleware to account userId param.
This commit is contained in:
@@ -4,6 +4,7 @@ import jwt from 'jsonwebtoken';
|
||||
|
||||
import { AppDataSource } from '../data-source';
|
||||
import { User } from "../entity/User";
|
||||
import { Post } from "../entity/Post";
|
||||
|
||||
class UserController {
|
||||
async register(req: Request, res: Response): Promise<void> {
|
||||
@@ -30,6 +31,15 @@ class UserController {
|
||||
res.cookie("jwt", jwt.sign({ username, id: savedUser.id }, process.env.JWT_SECRET));
|
||||
res.status(200).redirect("/");
|
||||
}
|
||||
|
||||
async getPosts(req: Request, res: Response): Promise<void> {
|
||||
const { userId } = req.params;
|
||||
|
||||
const posts = await AppDataSource.manager.findBy(Post, {authorId: Number.parseInt(userId)});
|
||||
console.log(posts);
|
||||
|
||||
res.status(200).send(posts);
|
||||
}
|
||||
}
|
||||
|
||||
export default new UserController();
|
||||
Reference in New Issue
Block a user