Revisions
-
patroza revised this gist
Mar 23, 2020 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -56,7 +56,7 @@ const getCompletedTodos = (getTodos: ReturnType<typeof getTodosApi>) => const completeTodo = (getTodo: ReturnType<typeof getTodoApi>, saveTodo: ReturnType<typeof saveTodoApi>) => async function (todoId: number): Promise<void> { const todo = await getTodo(todoId) const updatedTodo = complete(todo, new Date()) await saveTodo(updatedTodo) } @@ -74,13 +74,13 @@ type Todo = { readonly updatedAt: Date } const complete = (todo: Todo, currentDate: Date) => { if (todo.isCompleted) { throw new Error("already completed") } return { ...todo, isCompleted: true, updatedAt: currentDate, } } -
patroza revised this gist
Mar 22, 2020 . No changes.There are no files selected for viewing
-
patroza revised this gist
Mar 18, 2020 . 1 changed file with 4 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -68,10 +68,10 @@ type TodoView = { // 1. Domain type Todo = { readonly id: number readonly title: string readonly isCompleted: boolean readonly updatedAt: Date } const complete = (todo: Todo) => { -
patroza revised this gist
Mar 18, 2020 . 1 changed file with 11 additions and 7 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -24,18 +24,22 @@ const start = () => { //start() // 3. Infra let todoStubs = [ { id: 1, title: "Test", isCompleted: false, updatedAt: new Date(2020, 1, 1)}, { id: 2, title: "Test 2", isCompleted: true, updatedAt: new Date(2020, 1, 1)}, ] const getTodosApi = (url: string) => async function (userId: number): Promise<Todo[]> { return todoStubs } const getTodoApi = (url: string) => async function (todoId: number): Promise<Todo | undefined> { return todoStubs.find(x => x.id === todoId) } const saveTodoApi = (url: string) => async function (todo: Todo): Promise<void> { todoStubs = todoStubs.filter(x => x.id === todo.id).concat([todo]) } // 2. Application -
patroza revised this gist
Mar 18, 2020 . 1 changed file with 9 additions and 6 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,4 @@ // 3. Presentation/Root const start = () => { const getCompletedTodosRequestHandler = async (ctx) => { const result = await getCompletedTodosResolved(ctx.params.id) @@ -23,7 +23,7 @@ const start = () => { } //start() // 3. Infra const getTodosApi = (url: string) => async function (userId: number): Promise<Todo[]> { return [ { id: 1, title: "Test", isCompleted: false, updatedAt: new Date(2020, 1, 1)}, @@ -52,8 +52,8 @@ const getCompletedTodos = (getTodos: ReturnType<typeof getTodosApi>) => const completeTodo = (getTodo: ReturnType<typeof getTodoApi>, saveTodo: ReturnType<typeof saveTodoApi>) => async function (todoId: number): Promise<void> { const todo = await getTodo(todoId) const updatedTodo = complete(todo) await saveTodo(updatedTodo) } type TodoView = { @@ -74,6 +74,9 @@ const complete = (todo: Todo) => { if (todo.isCompleted) { throw new Error("already completed") } return { ...todo, isCompleted: true, updatedAt: new Date(), } } -
patroza created this gist
Mar 18, 2020 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,79 @@ // 4. Presentation/Root const start = () => { const getCompletedTodosRequestHandler = async (ctx) => { const result = await getCompletedTodosResolved(ctx.params.id) ctx.body = JSON.stringify(result) } const completeTodoRequestHandler = async (ctx) => { await completeTodoResolved(ctx.params.id) ctx.status = 204 } const url = "some-url" const getTodoApiResolved = getTodoApi(url) const getTodosApiResolved = getTodosApi(url) const saveTodoResolved = saveTodoApi(url) const getCompletedTodosResolved = getCompletedTodos(getTodosApiResolved) const completeTodoResolved = completeTodo(getTodoApiResolved, saveTodoResolved) app.get("/users/:id/todos", getCompletedTodosRequestHandler) app.post("/todos/:id/complete", completeTodoRequestHandler) app.listen(3000) } //start() // 4. Infra const getTodosApi = (url: string) => async function (userId: number): Promise<Todo[]> { return [ { id: 1, title: "Test", isCompleted: false, updatedAt: new Date(2020, 1, 1)}, { id: 2, title: "Test 2", isCompleted: true, updatedAt: new Date(2020, 1, 1)}, ] } const getTodoApi = (url: string) => async function (todoId: number): Promise<Todo> { return { id: todoId, title: "Test", isCompleted: false, updatedAt: new Date(2020, 1, 1)} } const saveTodoApi = (url: string) => async function (todo: Todo): Promise<void> {} // 2. Application const getCompletedTodos = (getTodos: ReturnType<typeof getTodosApi>) => async function (userId: number): Promise<TodoView> { const allTodos = await getTodos(userId) const completedTodos = allTodos.filter(x => x.isCompleted) return { items: completedTodos, userId, } } const completeTodo = (getTodo: ReturnType<typeof getTodoApi>, saveTodo: ReturnType<typeof saveTodoApi>) => async function (todoId: number): Promise<void> { const todo = await getTodo(todoId) complete(todo) await saveTodo(todo) } type TodoView = { items: Todo[] userId: number } // 1. Domain type Todo = { id: number title: string isCompleted: boolean updatedAt: Date } const complete = (todo: Todo) => { if (todo.isCompleted) { throw new Error("already completed") } todo.isCompleted = true todo.updatedAt = new Date() }