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.listen(3000, () => console.log('Server is running...'));
|
||||
app.listen(3000, () => console.log('Server is running on port 3000'));
|
||||
|
||||
function getTasks(request, response) {
|
||||
dao.getTasks()
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user