smaller refactorings (mostly entitization)

This commit is contained in:
azivner
2018-04-01 11:05:09 -04:00
parent c9d73c6115
commit fad0ec757b
12 changed files with 69 additions and 56 deletions

View File

@@ -58,7 +58,7 @@ async function createNewNote(parentNoteId, noteOpts) {
mime: noteOpts.mime ? noteOpts.mime : 'text/html'
});
await repository.updateEntity(note);
await note.save();
const branch = new Branch({
branchId: utils.newBranchId(),
@@ -69,12 +69,13 @@ async function createNewNote(parentNoteId, noteOpts) {
isDeleted: 0
});
await repository.updateEntity(branch);
await branch.save();
return {
noteId: note.noteId,
note,
branchId: branch.branchId,
note
branch
};
}

View File

@@ -27,10 +27,6 @@ function getDataKey() {
return dataKeyMap[protectedSessionId];
}
function getDataKeyForProtectedSessionId(protectedSessionId) {
return dataKeyMap[protectedSessionId];
}
function isProtectedSessionAvailable(req) {
const protectedSessionId = getProtectedSessionId(req);
@@ -84,12 +80,6 @@ function decryptNoteRevision(hist) {
}
}
function decryptNoteRevisions(noteRevisions) {
for (const revision of noteRevisions) {
decryptNoteRevision(revision);
}
}
function encryptNote(note) {
const dataKey = getDataKey();
@@ -107,12 +97,10 @@ function encryptNoteRevision(revision) {
module.exports = {
setDataKey,
getDataKey,
getDataKeyForProtectedSessionId,
isProtectedSessionAvailable,
decryptNote,
decryptNotes,
decryptNoteRevision,
decryptNoteRevisions,
encryptNote,
encryptNoteRevision,
setProtectedSessionId

View File

@@ -33,6 +33,10 @@ async function getBranch(branchId) {
return await getEntity("SELECT * FROM branches WHERE branchId = ?", [branchId]);
}
async function getImage(imageId) {
return await getEntity("SELECT * FROM images WHERE imageId = ?", [imageId]);
}
async function updateEntity(entity) {
if (entity.beforeSaving) {
entity.beforeSaving();
@@ -54,6 +58,7 @@ module.exports = {
getEntity,
getNote,
getBranch,
getImage,
updateEntity,
setEntityConstructor
};