We need an endpoint where a user will be able to upload images for their profile.
Acceptance criteria
Create a POST endpoint under
/users/:id/upload
Endpoint should be accessible only by the role user-ngo, and user-independent
The endpoint should also check that the id in the params is the same as the one in the jwt token. This should happen inside the endpoint, not in a middleware. If not, it should return 403 with
{
error: You are unauthorized to upload documents for this user
}
The endpoint should accept bodies with content type "multipart/form-data" (take a look in the formidable library for further info)
It should receive a file via the body, it should validate that it's filetype is image and if so it should save it under the user's document in mongodb using gridfs.
If the file is saved successfully, it should return 201, and if there is another error, it should return 400 with
{
error: Error during image upload.
}
Every validation should fail and return an error 400 with the appropriate message.
We need an endpoint where a user will be able to upload images for their profile.
Acceptance criteria Create a POST endpoint under /users/:id/upload Endpoint should be accessible only by the role user-ngo, and user-independent The endpoint should also check that the id in the params is the same as the one in the jwt token. This should happen inside the endpoint, not in a middleware. If not, it should return 403 with
The endpoint should accept bodies with content type "multipart/form-data" (take a look in the formidable library for further info) It should receive a file via the body, it should validate that it's filetype is image and if so it should save it under the user's document in mongodb using gridfs. If the file is saved successfully, it should return 201, and if there is another error, it should return 400 with
Every validation should fail and return an error 400 with the appropriate message.