NotesService: Replace noteByIdOrAlias with note as parameter

As the NotesController has the note already, because it checked with it if the user has the permission to perform the action, it's not necessary to get the note from the DB again, instead we should just provide the note to the functions directly.

Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
Philip Molares 2021-02-20 16:50:11 +01:00
parent c9b05b3c44
commit 5f49cb8d48
5 changed files with 50 additions and 107 deletions

View file

@ -12,6 +12,7 @@ import { NotesService } from '../notes/notes.service';
import { RevisionMetadataDto } from './revision-metadata.dto';
import { RevisionDto } from './revision.dto';
import { Revision } from './revision.entity';
import { Note } from '../notes/note.entity';
@Injectable()
export class RevisionsService {
@ -24,8 +25,7 @@ export class RevisionsService {
this.logger.setContext(RevisionsService.name);
}
async getAllRevisions(noteIdOrAlias: string): Promise<Revision[]> {
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
async getAllRevisions(note: Note): Promise<Revision[]> {
return await this.revisionRepository.find({
where: {
note: note,
@ -33,11 +33,7 @@ export class RevisionsService {
});
}
async getRevision(
noteIdOrAlias: string,
revisionId: number,
): Promise<Revision> {
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
async getRevision(note: Note, revisionId: number): Promise<Revision> {
return await this.revisionRepository.findOne({
where: {
id: revisionId,