mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-20 02:05:21 -04:00
HistoryService: Add setHistory method
This is the transactional reimplementation of the business logic of the history controllers setHistory method (of the private api). This should prevent the problem that the history gets deleted, but a later error in the handling of the list of HistoryEntryImportDto let's the call fail. See also: https://docs.nestjs.com/techniques/database#transactions Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
7c648e7056
commit
524ad658d8
2 changed files with 58 additions and 19 deletions
|
@ -5,6 +5,7 @@
|
|||
*/
|
||||
|
||||
import {
|
||||
BadRequestException,
|
||||
Body,
|
||||
Controller,
|
||||
Delete,
|
||||
|
@ -16,9 +17,8 @@ import {
|
|||
} from '@nestjs/common';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
import { UsersService } from '../../../../users/users.service';
|
||||
import { NotesService } from '../../../../notes/notes.service';
|
||||
import { HistoryEntryDto } from '../../../../history/history-entry.dto';
|
||||
import { NotInDBError } from '../../../../errors/errors';
|
||||
import { ForbiddenIdError, NotInDBError } from '../../../../errors/errors';
|
||||
import { HistoryEntryImportDto } from '../../../../history/history-entry-import.dto';
|
||||
import { HistoryEntryUpdateDto } from '../../../../history/history-entry-update.dto';
|
||||
import { ConsoleLoggerService } from '../../../../logger/console-logger.service';
|
||||
|
@ -31,7 +31,6 @@ export class HistoryController {
|
|||
private readonly logger: ConsoleLoggerService,
|
||||
private historyService: HistoryService,
|
||||
private userService: UsersService,
|
||||
private noteService: NotesService,
|
||||
) {
|
||||
this.logger.setContext(HistoryController.name);
|
||||
}
|
||||
|
@ -60,21 +59,10 @@ export class HistoryController {
|
|||
try {
|
||||
// ToDo: use actual user here
|
||||
const user = await this.userService.getUserByUsername('hardcoded');
|
||||
await this.historyService.deleteHistory(user);
|
||||
for (const historyEntry of history) {
|
||||
const note = await this.noteService.getNoteByIdOrAlias(
|
||||
historyEntry.note,
|
||||
);
|
||||
await this.historyService.createOrUpdateHistoryEntry(
|
||||
note,
|
||||
user,
|
||||
historyEntry.pinStatus,
|
||||
historyEntry.lastVisited,
|
||||
);
|
||||
}
|
||||
await this.historyService.setHistory(user, history);
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
if (e instanceof NotInDBError || e instanceof ForbiddenIdError) {
|
||||
throw new BadRequestException(e.message);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue