PublicAPI: Add /me/history/:note

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-03-05 12:01:43 +01:00 committed by David Mehren
parent 521ddc36c6
commit 82ef4a10cb
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3

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);