created repository object to access entities

This commit is contained in:
azivner
2018-01-29 23:17:44 -05:00
parent 9a091408e3
commit 6fa6891496
12 changed files with 104 additions and 95 deletions

View File

@@ -3,7 +3,7 @@
const sql = require('./sql');
const utils = require('./utils');
const sync_table = require('./sync_table');
const protected_session = require('./protected_session');
const Repository = require('./repository');
async function getNoteAttributeMap(noteId) {
return await sql.getMap(`SELECT name, value FROM attributes WHERE noteId = ?`, [noteId]);
@@ -15,21 +15,19 @@ async function getNoteIdWithAttribute(name, value) {
}
async function getNotesWithAttribute(dataKey, name, value) {
const repository = new Repository(dataKey);
let notes;
if (value !== undefined) {
notes = await sql.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)
notes = await repository.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)
WHERE notes.isDeleted = 0 AND attributes.name = ? AND attributes.value = ?`, [name, value]);
}
else {
notes = await sql.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)
notes = await repository.getEntities(`SELECT notes.* FROM notes JOIN attributes USING(noteId)
WHERE notes.isDeleted = 0 AND attributes.name = ?`, [name]);
}
for (const note of notes) {
protected_session.decryptNote(dataKey, note);
}
return notes;
}