Conversation
| }); | ||
| }, | ||
| findAll: () => { | ||
| return prisma.posts.findMany({ |
There was a problem hiding this comment.
Right now I'm pretty sure you are sending regular IDs back to the frontend. We are trying to avoid this in this project.
We only want to send GUIDs back and only use IDs on the backend.
There was a problem hiding this comment.
Ahhh I didn't see the issue description you gave -- I'll fix this evening when I'm able to get on my PC!
| @@ -2,16 +2,14 @@ import { prisma } from "../config/prisma"; | |||
| import { Prisma } from "../../generated/prisma"; | |||
|
|
|||
There was a problem hiding this comment.
No worries about the formatting! I don't mind this.
| import { Request, Response } from "express"; | ||
| import { PostRepository } from "../repositories/post.repository"; | ||
| import { Prisma } from "../../generated/prisma"; | ||
|
|
There was a problem hiding this comment.
I see that the service layer is missing in this pull request. If you are unfamiliar, the controller layer do the following: handle parsing inputs (e.g. req.params.id), handle HTTP details (status codes, error responses), call business logic (service layer methods), format outputs.
| }; | ||
|
|
||
| export const updatePost = async (req: Request, res: Response) => { | ||
| try { |
There was a problem hiding this comment.
It is good that we used authGuard on this endpoint, but we also need to verify that the user is only deleting / updating their own posts.
To do this, you will need to use the user's session token (which we also expect to be sent to the API from the frontend) along with the JWT library. You can decode the users information doing something along the lines of
req.user = jwt.verify(token, JWT_SECRET); <- this is just a generic example
You should do this for adding and deleting posts as well.
| @@ -0,0 +1,74 @@ | |||
| import { Request, Response } from "express"; | |||
There was a problem hiding this comment.
I have created an issue that goes into more detail on what we need out of this. A lot of what you have is solid but there is still additional work that needs to be done! The issue should have all of the information you need. Let me know if you run into any issues or have any questions!
This adds basic CRUD functionality for managing posts.
Changes include:
Implemented post.repository.ts with Prisma methods for creating, reading, updating, and deleting posts.
Added post.controller.ts for handling HTTP requests and responses for post-related operations.
Created post.routes.ts that defines Express routes for post endpoints, applying authentication middleware where necessary.
Updated main route index to include post routes.
You'll see it also modified user.respository.ts -
Prettier felt like formatting it, couldn't figure out how to change it back!
I've been struggling a bit to get this set up properly and I may have 100% messed it up, but thought I would at least add the changes here and go from there with what needs to be fixed.