RevisionsService: Refactor getFirst/LastRevision

The functions now expect a `Note` object instead of a noteId to
make it more consistent with other functions.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-08-29 22:45:56 +02:00
parent fe26f1689c
commit 5ecb0c0694
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
2 changed files with 8 additions and 8 deletions

View file

@ -129,7 +129,7 @@ export class NotesService {
* @return {Revision} the first revision of the note
*/
async getLatestRevision(note: Note): Promise<Revision> {
return await this.revisionsService.getLatestRevision(note.id);
return await this.revisionsService.getLatestRevision(note);
}
/**
@ -139,7 +139,7 @@ export class NotesService {
* @return {Revision} the last revision of the note
*/
async getFirstRevision(note: Note): Promise<Revision> {
return await this.revisionsService.getFirstRevision(note.id);
return await this.revisionsService.getFirstRevision(note);
}
/**

View file

@ -49,10 +49,10 @@ export class RevisionsService {
return revision;
}
async getLatestRevision(noteId: string): Promise<Revision> {
async getLatestRevision(note: Note): Promise<Revision> {
const revision = await this.revisionRepository.findOne({
where: {
note: noteId,
note: note,
},
order: {
createdAt: 'DESC',
@ -60,22 +60,22 @@ export class RevisionsService {
},
});
if (revision === undefined) {
throw new NotInDBError(`Revision for note ${noteId} not found.`);
throw new NotInDBError(`Revision for note ${note.id} not found.`);
}
return revision;
}
async getFirstRevision(noteId: string): Promise<Revision> {
async getFirstRevision(note: Note): Promise<Revision> {
const revision = await this.revisionRepository.findOne({
where: {
note: noteId,
note: note,
},
order: {
createdAt: 'ASC',
},
});
if (revision === undefined) {
throw new NotInDBError(`Revision for note ${noteId} not found.`);
throw new NotInDBError(`Revision for note ${note.id} not found.`);
}
return revision;
}