users ({
},{timestamps: true, });
name{type: String, required: true},
key {type: String, required: true},
},{timestamps: true, });
Task 01 (1.0 mark). Using the Express generator for developing the new REST API server, create the related nations, and
migrate them to a database named SDN302_FA25_StudentCodeDB (MongoDB).
Task 02 (5.0 marks) Create a new REST API server to the nation collection, you must use JSON Web Token (JWT) for
authenticating API. The secret key of JWT must be your StudentCode!@ (e.g., se171234!@) and store in the .env file.
The route path will match requests to:
Visit
http://yourdomain/auth/signin to generate the JWT. The account credentials are stored in the users.json
file (name: foodreviewer, key: 123456789)
http://yourdomain/api/v1/nations and
http://yourdomain/api/v1/nations/:id for all methods related to nations.
Implement CRUD actions with nation collection.
For the DELETE operation, ensure a nation cannot be deleted if any foods are associated with it (i.e., if there are
documents in the food collection referencing the nation's _id). Return an appropriate error message (e.g.,
"Cannot delete nation because it has associated foods") if deletion is attempted in such cases.
Zoom
+ 100%
Close