feat: add pinItem function

This commit is contained in:
thecodrr
2019-12-21 18:25:07 +05:00
parent 59e61d6f0a
commit c04b48667e

View File

@@ -12,7 +12,8 @@ import {
const KEYS = {
notes: "notes",
notebooks: "notebooks",
trash: "trash"
trash: "trash",
tags: "tags"
};
function checkInitialized() {
@@ -37,7 +38,7 @@ class Database {
for (let key of extractValues(KEYS)) {
this.storage.read(key).then(data => {
this[key] = data || {};
if (key === "notebooks") {
if (key === KEYS.tags) {
this.isInitialized = true;
//TODO use index here
resolve(true);
@@ -150,6 +151,22 @@ class Database {
return timestamp;
}
async pinItem(type, id) {
switch (type) {
case "notebook":
case "note":
col = type == "note" ? this.notes : this.notebooks;
func = type == "note" ? this.addNote : this.addNotebook;
if (col[id] === undefined) {
throw new Error(`Wrong ${type} id.`);
}
await func({ ...col[id], pinned: true });
break;
default:
throw new Error("Invalid type given to pinItem");
}
}
/**
* Deletes one or more notes
* @param {array} notes the notes to be deleted