1 - Models
- đź’Ż Worth: 7%
- đź“… Due: February 18, 2024 @ 23:59
- đźš« Penalty: Late submissions lose 10% per day to a maximum of 3 days. Nothing is accepted after 3 days and a grade of 0% will be given.
🎯 Objectives
- Understand the concept of the Model in MVC architecture by implementing CRUD operations.
- Use TypeScript to define and manipulate data structures for a Todo application.
- Examine the provided Todo class skeleton and determine how to implement the required methods effectively.
- Test the implemented methods using the provided Jest test suite to ensure correctness.
- Develop a fully functional model layer for a Todo application that interacts with a database.
🔨 Setup
- Clone (do not download as a zip) the starter repository from GitHub.
- Make sure Docker Desktop is open.
- Start the development container in VS Code by using the
Dev Containers: Open Folder in Container...
command from the Command Palette (CTRL/CMD+SHIFT+P) and select the cloned directory. - Run the following command in the terminal to install all necessary dependencies:
npm install
. - Verify that the database was set up properly by running:
psql
to connect to the database server.\c TodoDB
to connect to the database.\dt
to see the list of tables. There should be one calledtodos
.
🔍 Context
To complete this assignment, you should be familiar with the following concepts and theories:
- MVC Architecture: Understanding the role of the Model in the MVC (Model-View-Controller) pattern.
- TypeScript: Knowledge of basic TypeScript syntax and type system.
- Database Interaction: How to interact with a database using SQL.
- CRUD Operations: How to create, read, update, and delete data in a persistent storage system.
- Testing with Jest: Familiarity with Jest and how to run tests for TypeScript applications.
🚦 Let’s Go
Your task is to create a todo application that keeps track of a user’s task list. You will accomplish this by implementing the CRUD methods in the provided Todo.ts
class skeleton.
Todos (85%)
function create(sql: postgres.Sql<any>, props: TodoProps): Promise<Todo> {}function read(sql: postgres.Sql<any>, id: number): Promise<Todo | null> {}function update(updateProps: Partial<TodoProps>): Promise<void> {}function delete(): Promise<void> {}function markComplete(): Promise<void>{}
While implementing the methods, refer to the Jest test suite (./tests/Todo.test.ts
) to guide your development process. Make sure all tests pass before considering the assignment complete.
SubTodos (15%)
For a challenge, you can implement a subtodo feature. A subtodo is a smaller task that is part of a larger todo item. For example, if you have a todo item to “Plan a party”, you might have subtodos like “Send invitations”, “Buy decorations”, and “Plan the menu”.
-
You will need to create a new
SubTodo
class and infer the method signatures from the test suite. -
A
SubTodo
is a stripped down version of a regularTodo
. ASubTodo
should not have adescription
,editedAt
, ordueAt
props. -
Each
SubTodo
should be associated with aTodo
item. This means you will also need to modify yourTodoProps
interface to include an array ofSubTodo
items. -
Remember to update your database schema to include a new table for the subtodos.
-
There are subtodo tests in the test suite that you should uncomment.
📥 Submission
To submit your assignment, follow these steps:
-
Commit your changes to the local repository:
Terminal window git add .git commit -m "Completed Todo model implementation." -
Push your commits to the remote repository:
Terminal window git push -
Submit your assignment on Gradescope.
- Accept the invitation to Gradescope in your JAC email using your
studentid@johnabbottcollege.net
address. - Go to Gradescope (TBD, I’ll update this to a link when its ready) and click the link for this assignment.
- Select the correct repository and branch from the dropdown menus.
- Click Upload.
- Accept the invitation to Gradescope in your JAC email using your