CS546 – Lab 4 (Solution)

$ 20.99
Category:

Description

CS­546 Lab 4
Our First ToDo
For this lab, we’re going to embark on a very common path that web developers start off on new technologies with: creating a to­do list! You will create a to­do list data module for this lab lab, and test it yourself.
The major concepts of this lab are:
Seperating concerns into different modules:
Database connection in one module
Collections defined in another
Data manipulation in another
Further practicing the usage of promises for asynchronous code
Continuing our exercises of only linking these modules together as needed
Packages you will use:
You will also use the mongodb (https://mongodb.github.io/node­mongodb­native/) package.
You must save all dependencies to your package.json file
Database Structure

You will use a database with the following organization:
The database will be called lab4
The collection for todo items will be called todoItems
todo.js

In todo.js, you will create and export four methods:
createTask(title, description);
This function will return a promise that resolves to a newly created to­do list object, with the following properties:

This task will be stored in the todoItems collection.
Important Note: you will create and set the _id field in the createTask method.
Important Note: as you can tell, the parameters only provide a title and description. You must still set the other fields before inserting them into the database.
If the task cannot be created, the method should reject.
You would use it as:

getAllTasks();
This function will return a promise that resolves to an array of all tasks in the database.
getTask(id);
This function will return a promise that resolves to a task from the database, when given an id. For example, you would use this method as:
If no id is provided, the method should return a rejected promise.
If the task does not exist, the method should return a rejected promise.

completeTask(taskId)
If no id is provided, the method should return a rejected promise.
If the task cannot be updated (does not exist, etc), the method should reject.

and then run the update command.
(https://docs.mongodb.com/manual/reference/operator/update/set/) command to accomplish this as well.
removeTask(id)
This function will remove the task from the database.
If no id is provided, the method should return a rejected promise.
If the task cannot be removed (does not exist), the method should reject.

app.js

For your app.js file, you will:
1. Create a task with the following details:

2. Log the task, and then create a new task with the following details:

3. After the task is inserted, query all tasks and log them
4. After all the tasks are logged, remove the first task
5. Query all tasks and log them
6. Complete the remaining task
7. Query and log the remaining task.
General Requirements

1. You must not submit your node_modules folder
2. You must remember to save your dependencies to your package.json folder
3. You must do basic error checking in each function 1. Check for arguments existing and of proper type.
2. Throw if anything is out of bounds (ie, trying to perform an incalculable math operation or accessing data that does not exist)
3. If a function should return a promise, you will either throw inside of the Promise constructor or return a rejected promise (https://developer.mozilla.org/en­
US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject) .
4. You must remember to update your package.json file to set app.js as your starting script!
5. You must submit a zip, rar, tar.gz, or .7z archive or you will lose points, named in the followign format:

Reviews

There are no reviews yet.

Be the first to review “CS546 – Lab 4 (Solution)”

Your email address will not be published. Required fields are marked *