From 122ff3bb1dc35abe8e1f62d2b9503f20f522e277 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 5 Apr 2024 20:47:07 +0300 Subject: [PATCH] server-ts: Convert routes/api/cloning --- src/routes/api/{cloning.js => cloning.ts} | 13 +++++++------ src/services/cloning.ts | 4 ++-- 2 files changed, 9 insertions(+), 8 deletions(-) rename src/routes/api/{cloning.js => cloning.ts} (71%) diff --git a/src/routes/api/cloning.js b/src/routes/api/cloning.ts similarity index 71% rename from src/routes/api/cloning.js rename to src/routes/api/cloning.ts index 75a42e675..8ab02900d 100644 --- a/src/routes/api/cloning.js +++ b/src/routes/api/cloning.ts @@ -1,34 +1,35 @@ "use strict"; -const cloningService = require('../../services/cloning'); +import { Request } from 'express'; +import cloningService = require('../../services/cloning'); -function cloneNoteToBranch(req) { +function cloneNoteToBranch(req: Request) { const {noteId, parentBranchId} = req.params; const {prefix} = req.body; return cloningService.cloneNoteToBranch(noteId, parentBranchId, prefix); } -function cloneNoteToParentNote(req) { +function cloneNoteToParentNote(req: Request) { const {noteId, parentNoteId} = req.params; const {prefix} = req.body; return cloningService.cloneNoteToParentNote(noteId, parentNoteId, prefix); } -function cloneNoteAfter(req) { +function cloneNoteAfter(req: Request) { const {noteId, afterBranchId} = req.params; return cloningService.cloneNoteAfter(noteId, afterBranchId); } -function toggleNoteInParent(req) { +function toggleNoteInParent(req: Request) { const {noteId, parentNoteId, present} = req.params; return cloningService.toggleNoteInParent(present === 'true', noteId, parentNoteId); } -module.exports = { +export = { cloneNoteToBranch, cloneNoteToParentNote, cloneNoteAfter, diff --git a/src/services/cloning.ts b/src/services/cloning.ts index bb21425bc..36c61a653 100644 --- a/src/services/cloning.ts +++ b/src/services/cloning.ts @@ -58,7 +58,7 @@ function cloneNoteToBranch(noteId: string, parentBranchId: string, prefix: strin return ret; } -function ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefix: string) { +function ensureNoteIsPresentInParent(noteId: string, parentNoteId: string, prefix?: string) { if (!(noteId in becca.notes)) { return { branch: null, success: false, message: `Note '${noteId}' is deleted.` }; } else if (!(parentNoteId in becca.notes)) { @@ -109,7 +109,7 @@ function ensureNoteIsAbsentFromParent(noteId: string, parentNoteId: string) { } } -function toggleNoteInParent(present: boolean, noteId: string, parentNoteId: string, prefix: string) { +function toggleNoteInParent(present: boolean, noteId: string, parentNoteId: string, prefix?: string) { if (present) { return ensureNoteIsPresentInParent(noteId, parentNoteId, prefix); }