telegram_notes_bot/notes/Implementation/attribute changed/reconcileAssignments.js
2021-04-23 10:48:42 +02:00

25 lines
980 B
JavaScript

module.exports = async function(note, categoryRootNote, assignedCategories, labelName, isTaskDone) {
const found = {};
for (const categoryNote of await categoryRootNote.getChildNotes()) {
const label = await categoryNote.getLabel(labelName);
if (label) {
found[label.value] = !isTaskDone && assignedCategories.includes(label.value);
await api.toggleNoteInParent(found[label.value], note.noteId, categoryNote.noteId);
}
}
if (!isTaskDone) {
for (const assignedCategory of assignedCategories) {
if (!found[assignedCategory]) {
const categoryNote = (await api.createNote(categoryRootNote.noteId, assignedCategory, "", {
attributes: [ { type: "label", name: labelName, value: assignedCategory } ]
})).note;
await api.ensureNoteIsPresentInParent(note.noteId, categoryNote.noteId);
}
}
}
}