Six tasks are logically interconnected and involve writing a REST API.
-
To complete the homework assignment, use the following boilerplate.
-
A separate branch is created for each homework assignment:
- 02-express 👉
- 03-mongodb 👉
- 04-auth 👉
- 05-avatars 👉
- 06-email 👉
-
Each new branch should be created from master.
-
JS code is clean and understandable; formatting is done using Prettier.
-
Before pushing, code quality is checked using the npm run lint command.
-
Code meets the technical requirements of the project.
-
No unhandled errors occur when the code is executed.
-
The names of variables, properties, and methods start with a lowercase letter and are written in CamelCase notation. English nouns are used.
-
The name of a function or method contains a verb.
-
The project works correctly with the current LTS version of Node.
npm start— start the server in production mode.npm run start:dev— start the server in development mode.npm run lint— run code quality checks with eslint. This should be done before each PR and fix all linter errors.npm run lint:fix— the same linter check, but with automatic corrections of simple errors.npm test— start the server in test mode.
- Receives nothing.
- Returns an array of all contacts in JSON format with status
200.
- Does not receive
body. - Receives
idparameter. - If such an
idexists, returns the contact object in JSON format with status200. - If such an
iddoes not exist, returns JSON with the key"message": "Not found"and status404.
- Receives
bodyin the format{name, email, phone, favorite}(name, email, phone are mandatory fields). - If some mandatory fields are missing in
body, returns JSON with the key{"message": "missing required name field"}and status400. - If
favoriteis not specified inbody, then when saving a new contact to the database, make thefavoritefield default tofalse. - If everything is fine with
body, adds a unique identifier to the contact object. - Returns the object with the added
id{id, name, email, phone, favorite}and status201.
- Does not receive
body. - Receives
idparameter. - If such an
idexists, returns JSON format{"message": "contact deleted"}and status200. - If such an
iddoes not exist, returns JSON with the key"message": "Not found"and status404.
- Receives
idparameter. - Receives
bodyin JSON format with updates to any of the fieldsname, email, and phone. - If there is no
body, returns JSON with the key{"message": "missing fields"}and status400. - Returns the updated contact object and status
200. Otherwise, returns JSON with the key"message": "Not found"and status404.
- Receives
contactIdparameter. - Receives
bodyin JSON format with an update to thefavoritefield. - If there is no
body, returns JSON
with the key { "message": "missing field favorite"} and status 400.
- Returns the updated contact object and status
200. Otherwise, returns JSON with the key"message": "Not found"and status404.
- Receives
bodyin the format{email, password}(email, password are mandatory fields). - If some mandatory fields are missing in
body, returns JSON with the key{"message": "Missing required "..." field"}and status400. - If the
bodycontains anemailthat already exists in the database, returns JSON with the key{"message": "Email already in use!"}and status409. - If everything is fine with
body, adds a unique identifier to the user object. - Returns the object with the added
id{email, password}and status201.
- Receives
bodyin the format{email, password}(email, password are mandatory fields). - If some mandatory fields are missing in
body, returns JSON with the key{"message": "Missing required "..." field"}and status400. - If the
bodycontainsemailandpasswordthat do not match those in the database, returns JSON with the key{"message": "Email or password is wrong!"}and status401. - If everything is fine with
body, creates a token. - Returns the object with the added
tokenanduser={email, password}and status200.
- Receives a token in
Authorization: "Bearer {{token}}". - If there is no user with such a token, returns JSON with the key
{"message": "Not authorized! User not found!"}and status401. - If the user is found, deletes the token.
- Returns status
204 No Content.
- Receives a token in
Authorization: "Bearer {{token}}". - If there is no user with such a token, returns JSON with the key
{"message": "Not authorized! User not found!"}and status401. - If the user is found, returns the object
{email, subscription}with status200.
Pagination for the contacts collection.
Filtering contacts by the favorite field (GET /contacts?favorite=true).
Updating a user's subscription.
- Receives a token in
Authorization: "Bearer {{token}}". - Receives
bodyin the format{subscription}. Subscription (the{subscription}field is mandatory) must have one of the following values ['starter', 'pro', 'business']. - Returns the updated user object with status
200. Otherwise, returns JSON with the key"message": "Not found"and status404.
Updating a user's avatar.
- Receives a token in
Authorization: "Bearer {{token}}". - Receives a file in
body. - Returns the updated field (avatarURL) of the user object with status
200. - If the user is not authorized, returns JSON with the key
"message": "Not authorized"and status401.
LINKS:
👉 Main Statuses — HTTP Response Codes
👉 Unique Identifier Generators
👉 Multilingualism