mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-13 14:44:43 -04:00
NotesService: Rename getCurrentContent to getNoteContentByNote
The new name should better explain what this functions does. Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
1df4039b79
commit
aa97a87316
3 changed files with 16 additions and 7 deletions
|
@ -164,7 +164,7 @@ export class NotesController {
|
||||||
if (!this.permissionsService.mayRead(req.user, note)) {
|
if (!this.permissionsService.mayRead(req.user, note)) {
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
}
|
}
|
||||||
return await this.noteService.getNoteContent(noteIdOrAlias);
|
return await this.noteService.getNoteContentByNote(note);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof NotInDBError) {
|
if (e instanceof NotInDBError) {
|
||||||
throw new NotFoundException(e.message);
|
throw new NotFoundException(e.message);
|
||||||
|
|
|
@ -74,10 +74,19 @@ export class NotesService {
|
||||||
newNote.historyEntries = [HistoryEntry.create(owner)];
|
newNote.historyEntries = [HistoryEntry.create(owner)];
|
||||||
newNote.owner = owner;
|
newNote.owner = owner;
|
||||||
}
|
}
|
||||||
return this.noteRepository.save(newNote);
|
try {
|
||||||
|
return await this.noteRepository.save(newNote);
|
||||||
|
} catch {
|
||||||
|
this.logger.debug(
|
||||||
|
`A note with the alias '${alias}' already exists.`,
|
||||||
|
'createNote',
|
||||||
|
);
|
||||||
|
throw new AlreadyInDBError(
|
||||||
|
`A note with the alias '${alias}' already exists.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
async getNoteContentByNote(note: Note): Promise<string> {
|
||||||
async getCurrentContent(note: Note): Promise<string> {
|
|
||||||
return (await this.getLatestRevision(note)).content;
|
return (await this.getLatestRevision(note)).content;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,7 @@ describe('Notes', () => {
|
||||||
.expect(201);
|
.expect(201);
|
||||||
expect(response.body.metadata?.id).toBeDefined();
|
expect(response.body.metadata?.id).toBeDefined();
|
||||||
expect(
|
expect(
|
||||||
await notesService.getCurrentContent(
|
await notesService.getNoteContentByNote(
|
||||||
await notesService.getNoteByIdOrAlias(response.body.metadata.id),
|
await notesService.getNoteByIdOrAlias(response.body.metadata.id),
|
||||||
),
|
),
|
||||||
).toEqual(content);
|
).toEqual(content);
|
||||||
|
@ -109,7 +109,7 @@ describe('Notes', () => {
|
||||||
.expect(201);
|
.expect(201);
|
||||||
expect(response.body.metadata?.id).toBeDefined();
|
expect(response.body.metadata?.id).toBeDefined();
|
||||||
return expect(
|
return expect(
|
||||||
await notesService.getCurrentContent(
|
await notesService.getNoteContentByNote(
|
||||||
await notesService.getNoteByIdOrAlias(response.body.metadata?.id),
|
await notesService.getNoteByIdOrAlias(response.body.metadata?.id),
|
||||||
),
|
),
|
||||||
).toEqual(content);
|
).toEqual(content);
|
||||||
|
@ -141,7 +141,7 @@ describe('Notes', () => {
|
||||||
.send(changedContent)
|
.send(changedContent)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
await expect(
|
await expect(
|
||||||
await notesService.getCurrentContent(
|
await notesService.getNoteContentByNote(
|
||||||
await notesService.getNoteByIdOrAlias('test4'),
|
await notesService.getNoteByIdOrAlias('test4'),
|
||||||
),
|
),
|
||||||
).toEqual(changedContent);
|
).toEqual(changedContent);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue