mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-24 20:14:35 -04:00
refactor(note): lazy-load relations
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
d761ff7f4f
commit
235e4f647c
23 changed files with 343 additions and 284 deletions
|
@ -56,7 +56,7 @@ export class AliasController {
|
|||
const note = await this.noteService.getNoteByIdOrAlias(
|
||||
newAliasDto.noteIdOrAlias,
|
||||
);
|
||||
if (!this.permissionsService.isOwner(user, note)) {
|
||||
if (!(await this.permissionsService.isOwner(user, note))) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
const updatedAlias = await this.aliasService.addAlias(
|
||||
|
@ -88,7 +88,7 @@ export class AliasController {
|
|||
}
|
||||
try {
|
||||
const note = await this.noteService.getNoteByIdOrAlias(alias);
|
||||
if (!this.permissionsService.isOwner(user, note)) {
|
||||
if (!(await this.permissionsService.isOwner(user, note))) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
const updatedAlias = await this.aliasService.makeAliasPrimary(
|
||||
|
@ -115,7 +115,7 @@ export class AliasController {
|
|||
): Promise<void> {
|
||||
try {
|
||||
const note = await this.noteService.getNoteByIdOrAlias(alias);
|
||||
if (!this.permissionsService.isOwner(user, note)) {
|
||||
if (!(await this.permissionsService.isOwner(user, note))) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
await this.aliasService.removeAlias(note, alias);
|
||||
|
|
|
@ -45,8 +45,10 @@ export class HistoryController {
|
|||
async getHistory(@RequestUser() user: User): Promise<HistoryEntryDto[]> {
|
||||
try {
|
||||
const foundEntries = await this.historyService.getEntriesByUser(user);
|
||||
return foundEntries.map((entry) =>
|
||||
this.historyService.toHistoryEntryDto(entry),
|
||||
return await Promise.all(
|
||||
foundEntries.map((entry) =>
|
||||
this.historyService.toHistoryEntryDto(entry),
|
||||
),
|
||||
);
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
|
@ -96,7 +98,7 @@ export class HistoryController {
|
|||
user,
|
||||
entryUpdateDto,
|
||||
);
|
||||
return this.historyService.toHistoryEntryDto(newEntry);
|
||||
return await this.historyService.toHistoryEntryDto(newEntry);
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
|
|
|
@ -69,7 +69,7 @@ export class AliasController {
|
|||
const note = await this.noteService.getNoteByIdOrAlias(
|
||||
newAliasDto.noteIdOrAlias,
|
||||
);
|
||||
if (!this.permissionsService.isOwner(user, note)) {
|
||||
if (!(await this.permissionsService.isOwner(user, note))) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
const updatedAlias = await this.aliasService.addAlias(
|
||||
|
@ -107,7 +107,7 @@ export class AliasController {
|
|||
}
|
||||
try {
|
||||
const note = await this.noteService.getNoteByIdOrAlias(alias);
|
||||
if (!this.permissionsService.isOwner(user, note)) {
|
||||
if (!(await this.permissionsService.isOwner(user, note))) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
const updatedAlias = await this.aliasService.makeAliasPrimary(
|
||||
|
@ -139,7 +139,7 @@ export class AliasController {
|
|||
): Promise<void> {
|
||||
try {
|
||||
const note = await this.noteService.getNoteByIdOrAlias(alias);
|
||||
if (!this.permissionsService.isOwner(user, note)) {
|
||||
if (!(await this.permissionsService.isOwner(user, note))) {
|
||||
throw new UnauthorizedException('Reading note denied!');
|
||||
}
|
||||
await this.aliasService.removeAlias(note, alias);
|
||||
|
|
|
@ -101,7 +101,7 @@ export class MeController {
|
|||
): Promise<HistoryEntryDto> {
|
||||
try {
|
||||
const foundEntry = await this.historyService.getEntryByNote(note, user);
|
||||
return this.historyService.toHistoryEntryDto(foundEntry);
|
||||
return await this.historyService.toHistoryEntryDto(foundEntry);
|
||||
} catch (e) {
|
||||
if (e instanceof NotInDBError) {
|
||||
throw new NotFoundException(e.message);
|
||||
|
@ -126,7 +126,7 @@ export class MeController {
|
|||
): Promise<HistoryEntryDto> {
|
||||
// ToDo: Check if user is allowed to pin this history entry
|
||||
try {
|
||||
return this.historyService.toHistoryEntryDto(
|
||||
return await this.historyService.toHistoryEntryDto(
|
||||
await this.historyService.updateHistoryEntry(
|
||||
note,
|
||||
user,
|
||||
|
|
|
@ -16,7 +16,7 @@ import {
|
|||
Post,
|
||||
Put,
|
||||
UseGuards,
|
||||
UseInterceptors
|
||||
UseInterceptors,
|
||||
} from '@nestjs/common';
|
||||
import {
|
||||
ApiCreatedResponse,
|
||||
|
@ -26,17 +26,24 @@ import {
|
|||
ApiProduces,
|
||||
ApiSecurity,
|
||||
ApiTags,
|
||||
ApiUnauthorizedResponse
|
||||
ApiUnauthorizedResponse,
|
||||
} from '@nestjs/swagger';
|
||||
|
||||
import { TokenAuthGuard } from '../../../auth/token.strategy';
|
||||
import { AlreadyInDBError, ForbiddenIdError, NotInDBError } from '../../../errors/errors';
|
||||
import {
|
||||
AlreadyInDBError,
|
||||
ForbiddenIdError,
|
||||
NotInDBError,
|
||||
} from '../../../errors/errors';
|
||||
import { HistoryService } from '../../../history/history.service';
|
||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||
import { MediaUploadDto } from '../../../media/media-upload.dto';
|
||||
import { MediaService } from '../../../media/media.service';
|
||||
import { NoteMetadataDto } from '../../../notes/note-metadata.dto';
|
||||
import { NotePermissionsDto, NotePermissionsUpdateDto } from '../../../notes/note-permissions.dto';
|
||||
import {
|
||||
NotePermissionsDto,
|
||||
NotePermissionsUpdateDto,
|
||||
} from '../../../notes/note-permissions.dto';
|
||||
import { NoteDto } from '../../../notes/note.dto';
|
||||
import { Note } from '../../../notes/note.entity';
|
||||
import { NoteMediaDeletionDto } from '../../../notes/note.media-deletion.dto';
|
||||
|
@ -50,7 +57,7 @@ import { User } from '../../../users/user.entity';
|
|||
import {
|
||||
forbiddenDescription,
|
||||
successfullyDeletedDescription,
|
||||
unauthorizedDescription
|
||||
unauthorizedDescription,
|
||||
} from '../../utils/descriptions';
|
||||
import { FullApi } from '../../utils/fullapi-decorator';
|
||||
import { GetNoteInterceptor } from '../../utils/get-note.interceptor';
|
||||
|
@ -230,7 +237,7 @@ export class NotesController {
|
|||
@RequestNote() note: Note,
|
||||
@Body() updateDto: NotePermissionsUpdateDto,
|
||||
): Promise<NotePermissionsDto> {
|
||||
return this.noteService.toNotePermissionsDto(
|
||||
return await this.noteService.toNotePermissionsDto(
|
||||
await this.noteService.updateNotePermissions(note, updateDto),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue