in cli.js [92:141]
function displayTodos () {
todos.getAll(function (err, entities) {
if (err) {
throw err;
}
if (entities.length === 0) {
console.log('There are no todos!\n');
init();
return;
}
inquirer.prompt({
message: 'What have you completed?',
name: 'completed',
type: 'checkbox',
choices: entities.map(function (entity) {
return {
name: entity.title,
checked: entity.completed,
value: entity
};
})
}, function (answers) {
// Update entities model.
entities = entities.map(function (entity) {
if (answers.completed.some(function (completed) {
return completed.id === entity.id;
})) {
entity.completed = true;
} else {
entity.completed = false;
}
return entity;
});
let updated = 0;
entities.forEach(function (entity) {
const id = entity.id;
delete entity.id;
todos.update(id, entity, function (err) {
if (err) {
throw err;
}
if (++updated === entities.length) {
init();
}
});
});
});
});
}