mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 03:06:31 -05:00
refactor(history-service): use NoteService to get note
Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
5b7026758a
commit
72c354d5f6
2 changed files with 14 additions and 17 deletions
|
@ -59,6 +59,10 @@ describe('HistoryService', () => {
|
|||
provide: getRepositoryToken(HistoryEntry),
|
||||
useClass: Repository,
|
||||
},
|
||||
{
|
||||
provide: getRepositoryToken(Note),
|
||||
useClass: Repository,
|
||||
},
|
||||
],
|
||||
imports: [
|
||||
LoggerModule,
|
||||
|
@ -362,11 +366,17 @@ describe('HistoryService', () => {
|
|||
updatedAt: historyEntryImport.lastVisited,
|
||||
};
|
||||
const createQueryBuilder = {
|
||||
innerJoin: () => createQueryBuilder,
|
||||
leftJoinAndSelect: () => createQueryBuilder,
|
||||
where: () => createQueryBuilder,
|
||||
orWhere: () => createQueryBuilder,
|
||||
setParameter: () => createQueryBuilder,
|
||||
getOne: () => note,
|
||||
};
|
||||
jest
|
||||
.spyOn(noteRepo, 'createQueryBuilder')
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
.mockImplementation(() => createQueryBuilder);
|
||||
const mockedManager = {
|
||||
find: jest.fn().mockResolvedValueOnce([historyEntry]),
|
||||
createQueryBuilder: () => createQueryBuilder,
|
||||
|
|
|
@ -157,22 +157,9 @@ export class HistoryService {
|
|||
await manager.remove<HistoryEntry>(entry);
|
||||
}
|
||||
for (const historyEntry of history) {
|
||||
this.notesService.checkNoteIdOrAlias(historyEntry.note);
|
||||
const note = await manager
|
||||
.createQueryBuilder<Note>(Note, 'note')
|
||||
.innerJoin('note.aliases', 'alias')
|
||||
.where('note.id = :id', { id: historyEntry.note })
|
||||
.orWhere('alias.name = :id', { id: historyEntry.note })
|
||||
.getOne();
|
||||
if (note === undefined) {
|
||||
this.logger.debug(
|
||||
`Could not find note '${historyEntry.note}'`,
|
||||
'setHistory',
|
||||
);
|
||||
throw new NotInDBError(
|
||||
`Note with id/alias '${historyEntry.note}' not found.`,
|
||||
);
|
||||
}
|
||||
const note = await this.notesService.getNoteByIdOrAlias(
|
||||
historyEntry.note,
|
||||
);
|
||||
const entry = HistoryEntry.create(user, note) as HistoryEntry;
|
||||
entry.pinStatus = historyEntry.pinStatus;
|
||||
entry.updatedAt = historyEntry.lastVisited;
|
||||
|
|
Loading…
Reference in a new issue