mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 17:56:30 -05:00
NotesController: Get text from request body when updating and deleting a note.
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
d462a571d8
commit
05f25b92aa
1 changed files with 18 additions and 5 deletions
|
@ -70,16 +70,29 @@ export class NotesController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Delete(':noteIdOrAlias')
|
@Delete(':noteIdOrAlias')
|
||||||
deleteNote(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
async deleteNote(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||||
return this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
this.logger.debug('Deleting note: ' + noteIdOrAlias);
|
||||||
|
await this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
||||||
|
this.logger.debug('Successfully deleted ' + noteIdOrAlias);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':noteIdOrAlias')
|
@Put(':noteIdOrAlias')
|
||||||
updateNote(
|
async updateNote(
|
||||||
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
@Param('noteIdOrAlias') noteIdOrAlias: string,
|
||||||
@Body() noteContent: string,
|
@Req() req: Request,
|
||||||
) {
|
) {
|
||||||
return this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, noteContent);
|
// we have to check req.readable because of raw-body issue #57
|
||||||
|
// https://github.com/stream-utils/raw-body/issues/57
|
||||||
|
if (req.readable) {
|
||||||
|
let bodyText: string = await getRawBody(req, 'utf-8');
|
||||||
|
bodyText = bodyText.trim();
|
||||||
|
this.logger.debug('Got raw markdown:\n' + bodyText);
|
||||||
|
return this.noteService.updateNoteByIdOrAlias(noteIdOrAlias, bodyText);
|
||||||
|
} else {
|
||||||
|
// TODO: Better error message
|
||||||
|
throw new BadRequestException('Invalid body');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get(':noteIdOrAlias/content')
|
@Get(':noteIdOrAlias/content')
|
||||||
|
|
Loading…
Reference in a new issue