HistoryService: Remove getEntryByNoteIdOrAlias

As we now have a GetNotePipe, we can easily get rid of this function.
All clients can directly provide a `Note` instance
and use `getEntryByNote`.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2021-08-29 21:57:35 +02:00
parent d2b60a316f
commit 341e3a3e5a
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
3 changed files with 3 additions and 52 deletions

View file

@ -95,13 +95,10 @@ export class MeController {
@ApiNotFoundResponse({ description: notFoundDescription })
async getHistoryEntry(
@RequestUser() user: User,
@Param('note') note: string,
@Param('note', GetNotePipe) note: Note,
): Promise<HistoryEntryDto> {
try {
const foundEntry = await this.historyService.getEntryByNoteIdOrAlias(
note,
user,
);
const foundEntry = await this.historyService.getEntryByNote(note, user);
return this.historyService.toHistoryEntryDto(foundEntry);
} catch (e) {
if (e instanceof NotInDBError) {

View file

@ -135,30 +135,6 @@ describe('HistoryService', () => {
});
});
describe('getEntryByNoteIdOrAlias', () => {
const user = {} as User;
const alias = 'alias';
describe('works', () => {
it('with history entry', async () => {
const note = Note.create(user, alias);
const historyEntry = HistoryEntry.create(user, note);
jest.spyOn(historyRepo, 'findOne').mockResolvedValueOnce(historyEntry);
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(note);
expect(await service.getEntryByNoteIdOrAlias(alias, user)).toEqual(
historyEntry,
);
});
});
describe('fails', () => {
it('with an non-existing note', async () => {
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
await expect(
service.getEntryByNoteIdOrAlias(alias, {} as User),
).rejects.toThrow(NotInDBError);
});
});
});
describe('updateHistoryEntryTimestamp', () => {
describe('works', () => {
const user = {} as User;
@ -325,12 +301,6 @@ describe('HistoryService', () => {
NotInDBError,
);
});
it('without a note', async () => {
jest.spyOn(noteRepo, 'findOne').mockResolvedValueOnce(undefined);
await expect(
service.getEntryByNoteIdOrAlias(alias, {} as User),
).rejects.toThrow(NotInDBError);
});
});
});

View file

@ -45,22 +45,6 @@ export class HistoryService {
});
}
/**
* @async
* Get a history entry by the user and note, which is specified via id or alias
* @param {string} noteIdOrAlias - the id or alias specifying the note
* @param {User} user - the user that the note belongs to
* @throws {NotInDBError} the specified note does not exist
* @return {HistoryEntry} the requested history entry
*/
async getEntryByNoteIdOrAlias(
noteIdOrAlias: string,
user: User,
): Promise<HistoryEntry> {
const note = await this.notesService.getNoteByIdOrAlias(noteIdOrAlias);
return await this.getEntryByNote(note, user);
}
/**
* @async
* Get a history entry by the user and note
@ -68,7 +52,7 @@ export class HistoryService {
* @param {User} user - the user that the history entry belongs to
* @return {HistoryEntry} the requested history entry
*/
private async getEntryByNote(note: Note, user: User): Promise<HistoryEntry> {
async getEntryByNote(note: Note, user: User): Promise<HistoryEntry> {
const entry = await this.historyEntryRepository.findOne({
where: {
note: note,