mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-27 12:08:02 -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
99dccc0567
commit
e43008c627
1 changed files with 18 additions and 5 deletions
|
@ -70,16 +70,29 @@ export class NotesController {
|
|||
}
|
||||
|
||||
@Delete(':noteIdOrAlias')
|
||||
deleteNote(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||
return this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
||||
async deleteNote(@Param('noteIdOrAlias') noteIdOrAlias: string) {
|
||||
this.logger.debug('Deleting note: ' + noteIdOrAlias);
|
||||
await this.noteService.deleteNoteByIdOrAlias(noteIdOrAlias);
|
||||
this.logger.debug('Successfully deleted ' + noteIdOrAlias);
|
||||
return;
|
||||
}
|
||||
|
||||
@Put(':noteIdOrAlias')
|
||||
updateNote(
|
||||
async updateNote(
|
||||
@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')
|
||||
|
|
Loading…
Reference in a new issue