boolean-uk / team-dev-server

3 stars 12 forks source link

As a user, so I can fix mistakes, I want to be able to edit my posts#47 #227

Closed ning905 closed 1 year ago

ning905 commented 2 years ago
  1. Send a PATCH request to “/post/:id” Request body sample:

    {
    "content": "Bye world!"
    }
  2. Check token validation Return errors respectively according to the auth.js middleware

  3. After passing the validation stage, the request should have a user property. User sample:

    "user": {
      "id": 8,
      "cohort_id": null,
      "role": "STUDENT",
      "first_name": "Nathan",
      "last_name": "King",
      "email": "ngk5@gmail.com",
      "biography": "Hello world",
      "github_url": "https://github.com/vherus"
    }
  4. Find the post in the database with the provided id in request params, and return the object including its user information. https://www.prisma.io/docs/concepts/components/prisma-client/crud#read Post sample:

    {
           "id": 1,
            "content": "Hello world!",
            "userId": 2,
            "createdAt": "2022-09-14T10:09:54.622Z",
            "updatedAt": "2022-09-14T10:09:54.626Z",
            "user": {
                "email": "ngk5@gmail.com",
                "id": 2,
                "cohortId": null,
                "role": "STUDENT",
                "profile": {
                    "id": 2,
                    "userId": 2,
                    "firstName": "Nathan",
                    "lastName": "King",
                    "bio": "Hello world",
                    "githubUrl": "https://github.com/vherus"
                }
            }

    If not found, return error 404, “The post with the provided id does not exist”

  5. Check if the user id in the request matches the user id that comes with the post. If not match, return error 403, “Only the post author can edit the post”

  6. Update the post content according to the request body. Include the new post object in the response. https://www.prisma.io/docs/concepts/components/prisma-client/crud#read Response sample:

    { “status”: “success”,
    “data”:{
           "id": 1,
            "content": "Bye world!",
            "userId": 2,
            "createdAt": "2022-09-14T10:09:54.622Z",
            "updatedAt": "2022-09-14T10:09:54.626Z",
            "user": {
                "email": "ngk5@gmail.com",
                "id": 2,
                "cohortId": null,
                "role": "STUDENT",
                "profile": {
                    "id": 2,
                    "userId": 2,
                    "firstName": "Nathan",
                    "lastName": "King",
                    "bio": "Hello world",
                    "githubUrl": "https://github.com/vherus"
                }
            }
vherus commented 1 year ago

Other than that, I'm happy for you to go ahead with this. Really great work on this one!

ning905 commented 1 year ago

Thanks Nathan!