image upload fixes + some API changes

This commit is contained in:
azivner
2018-08-11 19:45:55 +02:00
parent 9e96272eb3
commit 0f42c396f3
6 changed files with 36 additions and 8 deletions

View File

@@ -2,11 +2,13 @@
const sql = require('./sql');
const syncTable = require('./sync_table');
const tree = require('./tree');
const treeService = require('./tree');
const noteService = require('./notes');
const repository = require('./repository');
const Branch = require('../entities/branch');
async function cloneNoteToParent(noteId, parentNoteId, prefix) {
const validationResult = await tree.validateParentChild(parentNoteId, noteId);
const validationResult = await treeService.validateParentChild(parentNoteId, noteId);
if (!validationResult.success) {
return validationResult;
@@ -24,10 +26,24 @@ async function cloneNoteToParent(noteId, parentNoteId, prefix) {
return { success: true };
}
async function cloneNoteAfter(noteId, afterBranchId) {
const afterNote = await tree.getBranch(afterBranchId);
// this is identical to cloneNoteToParent except for the intention - if cloned note is already in parent,
// then this is successful result
async function ensureNoteIsPresentInParent(noteId, parentNoteId, prefix) {
await cloneNoteToParent(noteId, parentNoteId, prefix);
}
const validationResult = await tree.validateParentChild(afterNote.parentNoteId, noteId);
async function ensureNoteIsAbsentFromParent(noteId, parentNoteId) {
const branch = await repository.getEntity(`SELECT * FROM branches WHERE noteId = ? AND parentNoteId = ? AND isDeleted = 0`, [noteId, parentNoteId]);
if (branch) {
await noteService.deleteNote(branch);
}
}
async function cloneNoteAfter(noteId, afterBranchId) {
const afterNote = await treeService.getBranch(afterBranchId);
const validationResult = await treeService.validateParentChild(afterNote.parentNoteId, noteId);
if (!validationResult.result) {
return validationResult;
@@ -52,5 +68,7 @@ async function cloneNoteAfter(noteId, afterBranchId) {
module.exports = {
cloneNoteToParent,
ensureNoteIsPresentInParent,
ensureNoteIsAbsentFromParent,
cloneNoteAfter
};