Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f015445

Browse files
committed
Cleanup and refactoring
1 parent d2288d0 commit f015445

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

week3/lecture/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "hyf-node-week-3-todo",
33
"version": "1.0.0",
4-
"description": "HackYourFuture Node.js Week 3 - Todo App",
4+
"description": "HackYourFuture Node.js Week 3 - To-Do App",
55
"repository": "https://github.com/HackYourFuture/nodejs.git",
66
"main": "src/index.js",
77
"author": "George Sapkin",

week3/lecture/src/actions/deserializeTodo.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ function setError(response, error) {
77
}
88

99
function deserializeTodo(request, response) {
10-
const todo = request.body.todo;
10+
const { todo } = request.body;
1111
if (todo == null) {
12-
setError(response, 'Specify a todo');
12+
setError(response, 'Specify a to-do');
1313
return null;
1414
}
1515

week3/lecture/src/todo.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
12
'use strict';
23

34
const fs = require('fs');
45
const uuid = require('uuid/v4');
56

7+
const DEFAULT_ENCODING = 'utf8';
8+
69
class Todo {
710
constructor(filename) {
811
this._filename = filename;
@@ -27,7 +30,7 @@ class Todo {
2730

2831
read() {
2932
return new Promise(resolve => {
30-
fs.readFile(this._filename, 'utf-8', (error, data) => {
33+
fs.readFile(this._filename, DEFAULT_ENCODING, (error, data) => {
3134
if (error)
3235
return resolve([]);
3336

@@ -41,7 +44,7 @@ class Todo {
4144

4245
const todo = todos.find(t => t.id === id);
4346
if (todo == null) {
44-
const error = new Error(`Todo with ID ${id} does not exist`);
47+
const error = new Error(`To-do with ID ${id} does not exist`);
4548
error.code = 'not-found';
4649
throw error;
4750
}

0 commit comments

Comments
 (0)