starting state fixed

This commit is contained in:
Märt Kalmo 2017-05-10 09:57:37 +03:00
parent 281735374c
commit bb5dc8c803
3 changed files with 6 additions and 34 deletions

View File

@ -8,7 +8,7 @@ const app = express();
app.get('/api/tasks', getTasks);
app.listen(3000, () => console.log('Server is running...'));
app.listen(3000, () => console.log('Server is running on port 3000'));
function getTasks(request, response) {
dao.getTasks()

View File

@ -11,43 +11,15 @@ class MemTaskService {
];
}
clone(what) {
return JSON.parse(JSON.stringify(what));
}
getTasks() {
return Promise.resolve(this.clone(this.tasks));
}
getTask(id) {
let found = this.clone(this.tasks)
.filter(each => each._id === id)
.pop();
return found ? Promise.resolve(found) : Promise.reject('no task with id: ' + id);
clone(what) {
return JSON.parse(JSON.stringify(what));
}
saveTask(task) {
if (!task._id) {
task._id = this.getId();
this.tasks.push(task);
return Promise.resolve();
}
this.tasks = this.tasks
.map(each =>each._id === task._id ? task : each);
return Promise.resolve();
}
deleteTask(id) {
this.tasks = this.tasks
.filter(each => each._id !== id);
return Promise.resolve();
}
getId() {
getNewId() {
return (Math.random() + 'A').substr(2);
}

View File

@ -1,8 +1,8 @@
'use strict';
class Task {
constructor(title) {
this.title = title;
constructor(content) {
this.content = content;
}
static withId(id, title) {