smaller refactorings continued

This commit is contained in:
azivner
2018-04-01 12:03:21 -04:00
parent acc82f39c4
commit 8ba830c04b
8 changed files with 41 additions and 34 deletions

View File

@@ -3,7 +3,7 @@
const changePasswordService = require('../../services/change_password');
async function changePassword(req) {
return await changePasswordService.changePassword(req.body['current_password'], req.body['new_password'], req);
return await changePasswordService.changePassword(req.body.current_password, req.body.new_password);
}
module.exports = {

View File

@@ -1,12 +1,12 @@
"use strict";
const sql = require('../../services/sql');
const repository = require('../../services/repository');
const utils = require('../../services/utils');
const sync_table = require('../../services/sync_table');
const options = require('../../services/options');
const RecentNote = require('../../entities/recent_note');
async function getRecentNotes() {
return await sql.getRows(`
return await repository.getEntities(`
SELECT
recent_notes.*
FROM
@@ -20,19 +20,18 @@ async function getRecentNotes() {
LIMIT 200`);
}
async function addRecentNote(req) {
const branchId = req.params.branchId;
const notePath = req.params.notePath;
await sql.replace('recent_notes', {
const recentNote = new RecentNote({
branchId: branchId,
notePath: notePath,
dateAccessed: utils.nowDate(),
isDeleted: 0
});
await sync_table.addRecentNoteSync(branchId);
await recentNote.save();
await options.setOption('start_note_path', notePath);

View File

@@ -5,21 +5,17 @@ const script = require('../../services/script');
const repository = require('../../services/repository');
async function exec(req) {
const ret = await script.executeScript(req, req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
const result = await script.executeScript(req.body.script, req.body.params, req.body.startNoteId, req.body.currentNoteId);
return {
executionResult: ret
};
return { executionResult: result };
}
async function run(req) {
const note = await repository.getNote(req.params.noteId);
const ret = await script.executeNote(req, note);
const result = await script.executeNote(req, note);
return {
executionResult: ret
};
return { executionResult: result };
}
async function getStartupBundles(req) {

View File

@@ -27,12 +27,10 @@ async function moveBranchToParent(req) {
const maxNotePos = await sql.getValue('SELECT MAX(notePosition) FROM branches WHERE parentNoteId = ? AND isDeleted = 0', [parentNoteId]);
const newNotePos = maxNotePos === null ? 0 : maxNotePos + 1;
const now = utils.nowDate();
await sql.execute("UPDATE branches SET parentNoteId = ?, notePosition = ?, dateModified = ? WHERE branchId = ?",
[parentNoteId, newNotePos, now, branchId]);
await sync_table.addBranchSync(branchId);
const branch = await repository.getBranch(branchId);
branch.parentNoteId = parentNoteId;
branch.notePosition = newNotePos;
await branch.save();
return { success: true };
}
@@ -57,10 +55,10 @@ async function moveBranchBeforeNote(req) {
await sync_table.addNoteReorderingSync(beforeNote.parentNoteId);
await sql.execute("UPDATE branches SET parentNoteId = ?, notePosition = ?, dateModified = ? WHERE branchId = ?",
[beforeNote.parentNoteId, beforeNote.notePosition, utils.nowDate(), branchId]);
await sync_table.addBranchSync(branchId);
const branch = await repository.getBranch(branchId);
branch.parentNoteId = beforeNote.parentNoteId;
branch.notePosition = beforeNote.notePosition;
await branch.save();
return { success: true };
}
@@ -85,10 +83,10 @@ async function moveBranchAfterNote(req) {
await sync_table.addNoteReorderingSync(afterNote.parentNoteId);
await sql.execute("UPDATE branches SET parentNoteId = ?, notePosition = ?, dateModified = ? WHERE branchId = ?",
[afterNote.parentNoteId, afterNote.notePosition + 1, utils.nowDate(), branchId]);
await sync_table.addBranchSync(branchId);
const branch = await repository.getBranch(branchId);
branch.parentNoteId = afterNote.parentNoteId;
branch.notePosition = afterNote.notePosition + 1;
await branch.save();
return { success: true };
}