Merge pull request #993 from hedgedoc/publicApi/me

This commit is contained in:
David Mehren 2021-03-14 16:28:49 +01:00 committed by GitHub
commit b67ec817e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 217 additions and 49 deletions

View file

@ -59,6 +59,26 @@ export class MeController {
);
}
@UseGuards(TokenAuthGuard)
@Get('history/:note')
async getHistoryEntry(
@Req() req: Request,
@Param('note') note: string,
): Promise<HistoryEntryDto> {
try {
const foundEntry = await this.historyService.getEntryByNoteIdOrAlias(
note,
req.user,
);
return this.historyService.toHistoryEntryDto(foundEntry);
} catch (e) {
if (e instanceof NotInDBError) {
throw new NotFoundException(e.message);
}
throw e;
}
}
@UseGuards(TokenAuthGuard)
@Put('history/:note')
async updateHistoryEntry(
@ -86,13 +106,13 @@ export class MeController {
@UseGuards(TokenAuthGuard)
@Delete('history/:note')
@HttpCode(204)
deleteHistoryEntry(
async deleteHistoryEntry(
@Req() req: Request,
@Param('note') note: string,
): Promise<void> {
// ToDo: Check if user is allowed to delete note
try {
return this.historyService.deleteHistoryEntry(note, req.user);
await this.historyService.deleteHistoryEntry(note, req.user);
} catch (e) {
if (e instanceof NotInDBError) {
throw new NotFoundException(e.message);