Files
notesnook/packages/core/api/outbox.js

39 lines
808 B
JavaScript
Raw Normal View History

2020-12-11 20:19:28 +05:00
class Outbox {
/**
*
* @param {import("./index").default} db
*/
constructor(db) {
this._db = db;
this.outbox = {};
}
async init() {
this.outbox = (await this._db.storage.read("outbox")) || {};
2020-12-11 20:19:28 +05:00
for (var id in this.outbox) {
const data = this.outbox[id];
switch (id) {
2020-12-16 12:08:39 +05:00
case "reset_password":
2020-12-22 13:13:18 +05:00
case "change_password":
if (await this._db.user._updatePassword(id, data))
await this.delete(id);
2020-12-11 20:19:28 +05:00
break;
}
}
}
async add(id, data, action) {
this.outbox[id] = data;
await this._db.storage.write("outbox", this.outbox);
2020-12-11 20:19:28 +05:00
await action();
await this.delete(id);
}
delete(id) {
delete this.outbox[id];
return this._db.storage.write("outbox", this.outbox);
2020-12-11 20:19:28 +05:00
}
}
export default Outbox;