starting state fixed
This commit is contained in:
parent
281735374c
commit
bb5dc8c803
@ -8,7 +8,7 @@ const app = express();
|
|||||||
|
|
||||||
app.get('/api/tasks', getTasks);
|
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) {
|
function getTasks(request, response) {
|
||||||
dao.getTasks()
|
dao.getTasks()
|
||||||
|
@ -11,43 +11,15 @@ class MemTaskService {
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
clone(what) {
|
|
||||||
return JSON.parse(JSON.stringify(what));
|
|
||||||
}
|
|
||||||
|
|
||||||
getTasks() {
|
getTasks() {
|
||||||
return Promise.resolve(this.clone(this.tasks));
|
return Promise.resolve(this.clone(this.tasks));
|
||||||
}
|
}
|
||||||
|
|
||||||
getTask(id) {
|
clone(what) {
|
||||||
let found = this.clone(this.tasks)
|
return JSON.parse(JSON.stringify(what));
|
||||||
.filter(each => each._id === id)
|
|
||||||
.pop();
|
|
||||||
|
|
||||||
return found ? Promise.resolve(found) : Promise.reject('no task with id: ' + id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
saveTask(task) {
|
getNewId() {
|
||||||
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() {
|
|
||||||
return (Math.random() + 'A').substr(2);
|
return (Math.random() + 'A').substr(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user