mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 18:25:21 -04:00
refactor: replace TypeORM with knex.js
Co-authored-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Philip Molares <philip.molares@udo.edu> Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
parent
6e151c8a1b
commit
4bd49085c6
241 changed files with 4577 additions and 6636 deletions
30
backend/src/api/utils/extract-note-id-from-request.ts
Normal file
30
backend/src/api/utils/extract-note-id-from-request.ts
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*
|
||||
* SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
import { isArray } from 'class-validator';
|
||||
|
||||
import { FieldNameNote, Note } from '../../database/types';
|
||||
import { NoteService } from '../../notes/note.service';
|
||||
import { CompleteRequest } from './request.type';
|
||||
|
||||
export async function extractNoteIdFromRequest(
|
||||
request: CompleteRequest,
|
||||
noteService: NoteService,
|
||||
): Promise<Note[FieldNameNote.id] | undefined> {
|
||||
const alias = extractNoteAlias(request);
|
||||
if (alias === undefined) {
|
||||
return undefined;
|
||||
}
|
||||
return await noteService.getNoteIdByAlias(alias);
|
||||
}
|
||||
|
||||
function extractNoteAlias(request: CompleteRequest): string | undefined {
|
||||
const noteAlias =
|
||||
request.params['noteAlias'] || request.headers['hedgedoc-note'];
|
||||
if (isArray(noteAlias)) {
|
||||
return noteAlias[0];
|
||||
}
|
||||
return noteAlias;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue