Closed janevalencia closed 2 years ago
Pull-requests are developed for the following dev-tickets
This pull-request setup the backend API routes to interact with User model.
Route:
Request available for api/users
Request available for api/users/[username]
{ "message": "Successfully created a new user.", "result": { "username": "amyrobson", "firstname": "Amy", "lastname": "Robson", "imageURL": "/assets/images/image-amyrobson.png", "_id": "63121c48f8da84e272c0133a", "createdAt": "2022-09-02T15:07:52.145Z", "updatedAt": "2022-09-02T15:07:52.145Z", "__v": 0 } }
{ "error": { "index": 0, "code": 11000, "keyPattern": { "username": 1 }, "keyValue": { "username": "juliusomo" } } }
{ "message": "Successfully created a new user.", "result": { "username": "maxblagun", "firstname": "Max B.", "imageURL": "/assets/images/image-maxblagun.png", "_id": "63121ceaf8da84e272c0133c", "createdAt": "2022-09-02T15:10:34.016Z", "updatedAt": "2022-09-02T15:10:34.016Z", "__v": 0 } }
{ "error": { "errors": { "firstname": { "name": "ValidatorError", "message": "Path `firstname` is required.", "properties": { "message": "Path `firstname` is required.", "type": "required", "path": "firstname" }, "kind": "required", "path": "firstname" } }, "_message": "User validation failed", "name": "ValidationError", "message": "User validation failed: firstname: Path `firstname` is required." } }
Test passed ✅ Fetching all users
[ { "_id": "6312198af8da84e272c01336", "username": "juliusomo", "firstname": "Julius", "lastname": "Omo", "imageURL": "/assets/images/image-juliusomo.png", "createdAt": "2022-09-02T14:56:10.454Z", "updatedAt": "2022-09-02T14:56:10.454Z", "__v": 0 }, { "_id": "63121c48f8da84e272c0133a", "username": "amyrobson", "firstname": "Amy", "lastname": "Robson", "imageURL": "/assets/images/image-amyrobson.png", "createdAt": "2022-09-02T15:07:52.145Z", "updatedAt": "2022-09-02T15:07:52.145Z", "__v": 0 }, { "_id": "63121ceaf8da84e272c0133c", "username": "maxblagun", "firstname": "Max B.", "imageURL": "/assets/images/image-maxblagun.png", "createdAt": "2022-09-02T15:10:34.016Z", "updatedAt": "2022-09-02T15:10:34.016Z", "__v": 0 }, { "_id": "63121fa0f8da84e272c0133f", "username": "ramsesmiron", "firstname": "Ramses", "lastname": "Miron", "imageURL": "/assets/images/image-ramsesmiron.png", "createdAt": "2022-09-02T15:22:08.730Z", "updatedAt": "2022-09-02T15:22:08.730Z", "__v": 0 } ]
Test passed ✅ Fetch a single user information provided the username on request.query param Run on postman: GET http://localhost:3000/api/users/juliusomo
{ "_id": "6312198af8da84e272c01336", "username": "juliusomo", "firstname": "Julius", "lastname": "Omo", "imageURL": "/assets/images/image-juliusomo.png", "createdAt": "2022-09-02T14:56:10.454Z", "updatedAt": "2022-09-02T14:56:10.454Z", "__v": 0 }
Test passed ✅ Calling PUT: http://localhost:3000/api/users will throw response error
http://localhost:3000/api/users
{ "error": "No response found, verify request method." }
Pull-requests are developed for the following dev-tickets
32
15
45
47
46
Description
This pull-request setup the backend API routes to interact with User model.
Route:
Request available for api/users
Request available for api/users/[username]
Testing
POST: api/users
GET: api/users
Test passed ✅ Fetching all users
GET: api/users/[username]
Test passed ✅ Fetch a single user information provided the username on request.query param Run on postman: GET http://localhost:3000/api/users/juliusomo
Route api/users cannot accept PUT, DELETE request methods
Test passed ✅ Calling PUT:
http://localhost:3000/api/users
will throw response error