From 32e0d80f614eda1e12899f7bc74277cf0a168f7c Mon Sep 17 00:00:00 2001 From: Ourchitecture <97544811+ourchitectureio@users.noreply.github.com> Date: Fri, 29 Sep 2023 16:14:13 -0400 Subject: [PATCH] docs: contributing Signed-off-by: Ourchitecture <97544811+ourchitectureio@users.noreply.github.com> --- .github/CODEOWNERS | 1 + .github/CONTRIBUTING.md | 22 ++++++++++++++++ cspell.config.yaml | 1 + .../routes/todos/clearCompleted.js | 26 +++++++++++++++++++ .../html-and-expressjs/routes/todos/index.js | 2 ++ .../html-and-expressjs/views/index.pug | 2 +- 6 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/CONTRIBUTING.md create mode 100644 src/experiments/todo/implementations/html-and-expressjs/routes/todos/clearCompleted.js diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..b28cfad --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @ourchitectureio diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md new file mode 100644 index 0000000..4de61a2 --- /dev/null +++ b/.github/CONTRIBUTING.md @@ -0,0 +1,22 @@ +# Contributing + +👋🏽 Hello, and thank you for your interest in contributing. + +## Getting started + +### Prerequisites + +- [NodeJS LTS](https://nodejs.org/en) +- [`pnpm`](https://pnpm.io/installation) + +### Testing the project works as expected + +1. Install project dependencies with the command `pnpm install` +2. Run the tests with the command `pnpm test` + +### Start the project + +1. Run the command `pnpm --filter @our-todo/html-and-expressjs start`. +2. Browse to the website + +_\*Specify a different port number by setting the environment variable "PORT"._ diff --git a/cspell.config.yaml b/cspell.config.yaml index aadd57d..93524e7 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -27,6 +27,7 @@ ignoreWords: - MADR - msedge - nvmrc + - ourchitectureio - pnpmrc - testid import: [] diff --git a/src/experiments/todo/implementations/html-and-expressjs/routes/todos/clearCompleted.js b/src/experiments/todo/implementations/html-and-expressjs/routes/todos/clearCompleted.js new file mode 100644 index 0000000..0cb1af3 --- /dev/null +++ b/src/experiments/todo/implementations/html-and-expressjs/routes/todos/clearCompleted.js @@ -0,0 +1,26 @@ +const { TODO_STATUS } = require('./models') + +const requestHandler = function (req, res, next) { + if (!req.session.todos) { + req.session.todos = [] + } + + const originalTodos = req.session.todos + + const completedTodoIds = req.body['completed-todo-id'] + ? Array.isArray(req.body['completed-todo-id']) + ? req.body['completed-todo-id'] + : [req.body['completed-todo-id']] + : [] + + const updatedTodos = originalTodos.filter((todo) => { + const isCompleted = completedTodoIds.includes(todo.id) + return !isCompleted + }) + + req.session.todos = updatedTodos + + res.redirect('/') +} + +module.exports = requestHandler diff --git a/src/experiments/todo/implementations/html-and-expressjs/routes/todos/index.js b/src/experiments/todo/implementations/html-and-expressjs/routes/todos/index.js index 03bbc94..2633c3c 100644 --- a/src/experiments/todo/implementations/html-and-expressjs/routes/todos/index.js +++ b/src/experiments/todo/implementations/html-and-expressjs/routes/todos/index.js @@ -1,5 +1,6 @@ const express = require('express') +const clearCompleted = require('./clearCompleted') const createTodo = require('./createTodo') const removeTodo = require('./removeTodo') const saveAll = require('./saveAll') @@ -7,6 +8,7 @@ const toggleCompleted = require('./toggleCompleted') const router = express.Router() +router.post('/clear-completed', clearCompleted) router.post('/create', createTodo) router.post('/toggle-completed', toggleCompleted) router.post('/save-all', saveAll) diff --git a/src/experiments/todo/implementations/html-and-expressjs/views/index.pug b/src/experiments/todo/implementations/html-and-expressjs/views/index.pug index b793b6a..d9ca5f9 100644 --- a/src/experiments/todo/implementations/html-and-expressjs/views/index.pug +++ b/src/experiments/todo/implementations/html-and-expressjs/views/index.pug @@ -30,4 +30,4 @@ block content input(type="submit",name="button-save",value="Save") if viewModel.hasTodos footer(data-testid="footer") - input(type="submit",name="button-clear-completed",value="Clear completed") + input(type="submit",formaction="/todos/clear-completed",name="button-clear-completed",value="Clear completed")