程序代写|COMP2406 Assignment 4 – Community fridge web application with MongoDB

这是一篇加拿大的应用服务编程开发程序代写

In the past three assignments, we have been building various parts of a community fridge web application. In Assignment 1, we built the client-side functionality of the application, to allow users to browse the list of fridges, browse items in a fridge, and pickup items from a fridge. In Assignment 2, we built the server-side component of the web application.Specifically, we created a Node.js server to serve all the resources associated with the application (e.g., HTML, CSS, JavaScript, CSS, and JSON). In addition to this, we also added persistence in our application. In Assignment 3, we further built the assignment in Express,specifically focusing on building a REST API.

In this assignment, we will connect our Express application to a MongoDB database. This involves moving all of the data from our JSON files into the MongoDB database and performing queries on this data.

We have provided the solution for Part 1 of assignment 3 as starting code for this assignment. If you were unable to fully complete assignment 3, you can use the provided solution as a starting point for this assignment. We made some slight changes to the Express routes from A3, so if you would like to use your own Assignment 3, please make the required changes. These changes are highlighted in the specification by the marker[***updated].

All of the application resources should be placed on the Node.js web server. You should not save any resources on the client-side. With regards to resources, we mean all assets associated with the application such as HTML files, CSS files, JavaScript files, images, and any other such assets used by your web application.

All data associated with the application should be stored in a MongoDB database as specified in the following sections. Questions that are implemented without utilizing the database will receive a mark of 0. For example, if any of the JSON files are updated instead of the database, a mark of 0 will be given for that question. Similarly, the solution must be implemented using a REST API created in Assignment 3. This API must be updated with the necessary changes required for this assignment.

Requirements

The primary requirements of the assignment involve implementing a database for our Express application. All routes will implemented on the server-side and tested using Post-man. You do not need to implement the client-side HTML/JavaScript code associated with the routes. However, there is a bonus question, which involves implementing a client-side component of the “Search feature”. As this is a bonus, it is optional for the assignment. It is meant for those who would like more practice working with the client-side code.

Part 1: Setting up a database

Begin by setting up your MongoAtlas cloud database account as explained in the lectures.We also used this account in Tutorial 9. If you did not get a chance to complete the tutorial, please watch the “Setting up a MongoDB Cloud account” video from week 10. We recommend you complete this step well in advance of completing the assignment, as not being able to setup the account will hinder your ability to successfully complete the assignment.

As shown in the lectures, your code should have a config.js file, which includes the connection information for your MongoDB database.

You must update the following information in the file to correspond to your assignment

username: update the value in this variable to your MongoDB username

password: update the value in this variable to your MongoDB password

dbname: update the dbname to community-fridge-stdnumber”, where stdnumber is equal to your student number. For example, if your student number is 100978291,then the value of the dbname variable should be “community-fridge-100978291”

Failure to update any of these values correctly will result in a mark of 0 for the assignment. The TAs need to be able to execute the code for a large number of students and completing this part incorrectly will affect their ability to mark the assignment in a timely manner.

NOTE: when you make changes to the database, you must “refresh” the MongoDB Atlas page to see the new changes. Similarly, you must restart the Node.js server anytime you make changes to your server-side code.

Part 2: Creating database schemas (6-marks)

Once the MongoDB database is setup, you need to use Mongoose to create three schemas for your database. These schemas will be used to add elements into the database.Specifically, the database should have the following three schemas:

Remember, that schemas in Mongoose are used to create Models, which are used to add documents (i.e., rows) into your database. Thus, each schema will correspond to a collection in the database.

2.1: Creating a database schema for Fridges

The following are the schema requirements for a fridge and this schema should be stored in a file called fridgeModel.js

id: stores a unique ID for the fridge (e.g., fg-1). The type for the id should be a String and it is a required field with a minimum length of 4 and a maximum length of 6.

name: stores the name of the fridge. The type for the name should be a String. It is a required field with a reasonable minimum and maximum length. The minimum and maximums must be implemented using the built-in scheme validation in Mongoose.

numItemsAccepted: indicates the number of items accepted by the fridge. It should be a number and have a default value of 0.

canAcceptItems: indicates the maximum number of items that the fridge can accept.It is a required field and should have a minimum value of 1 and a maximum value of The minimum and maximums must be implemented using the built-in scheme validation in Mongoose.

contactInfo: specifies the contact info for a fridge. It should be an object consisting of two properties: contactPerson and contactPhone. The type of both ofthese properties should be a String. As you can see from the comm-fridge-data.json file, the structure of this field has been modified compared to previous assignments.Please update this field in your code if not using the starter-code.

address: specifies the address information for a fridge. It is a required object with the following five fields{

street: type of String

postalCode: type of String

city: type of String

province: type of String,

country: type of String

[***updated] acceptedTypes: an array indicating the types of items accepted by the fridge. This field is required. The types of items accepted in previous assignments included a name (e.g., dairy, produce). We will now create a types collection, which will store all of the types available in our application. So, the acceptedTypes array now will have a list of ids instead of the names of the types (e.g., 839201, 1801920).

items: an array of item objects. Each item object has two properties: id and quantity.The id of the item in the array must correspond to its id in the items collection. The quantity field should be a number.