mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-23 02:06:29 -05:00
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:
parent
b552fc10b6
commit
279d90dad1
3 changed files with 3 additions and 52 deletions
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue