mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05:00
UserService: Improve method naming
This renames `createOrUpdateHistoryEntry` to `updateHistoryEntryTimestamp`, which reduces confusion with the similarly named `updateHistoryEntry` function. Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
parent
e65c19ddd8
commit
3396d3e47d
6 changed files with 16 additions and 16 deletions
|
@ -60,7 +60,7 @@ export class NotesController {
|
||||||
if (!this.permissionsService.mayRead(user, note)) {
|
if (!this.permissionsService.mayRead(user, note)) {
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
}
|
}
|
||||||
await this.historyService.createOrUpdateHistoryEntry(note, user);
|
await this.historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
return await this.noteService.toNoteDto(note);
|
return await this.noteService.toNoteDto(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ import {
|
||||||
AlreadyInDBError,
|
AlreadyInDBError,
|
||||||
ForbiddenIdError,
|
ForbiddenIdError,
|
||||||
NotInDBError,
|
NotInDBError,
|
||||||
PermissionsUpdateInconsistentError,
|
|
||||||
} from '../../../errors/errors';
|
} from '../../../errors/errors';
|
||||||
import { HistoryService } from '../../../history/history.service';
|
import { HistoryService } from '../../../history/history.service';
|
||||||
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
import { ConsoleLoggerService } from '../../../logger/console-logger.service';
|
||||||
|
@ -112,7 +111,7 @@ export class NotesController {
|
||||||
if (!this.permissionsService.mayRead(user, note)) {
|
if (!this.permissionsService.mayRead(user, note)) {
|
||||||
throw new UnauthorizedException('Reading note denied!');
|
throw new UnauthorizedException('Reading note denied!');
|
||||||
}
|
}
|
||||||
await this.historyService.createOrUpdateHistoryEntry(note, user);
|
await this.historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
return await this.noteService.toNoteDto(note);
|
return await this.noteService.toNoteDto(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -159,7 +159,7 @@ describe('HistoryService', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('createOrUpdateHistoryEntry', () => {
|
describe('updateHistoryEntryTimestamp', () => {
|
||||||
describe('works', () => {
|
describe('works', () => {
|
||||||
const user = {} as User;
|
const user = {} as User;
|
||||||
const alias = 'alias';
|
const alias = 'alias';
|
||||||
|
@ -171,7 +171,7 @@ describe('HistoryService', () => {
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
async (entry: HistoryEntry): Promise<HistoryEntry> => entry,
|
async (entry: HistoryEntry): Promise<HistoryEntry> => entry,
|
||||||
);
|
);
|
||||||
const createHistoryEntry = await service.createOrUpdateHistoryEntry(
|
const createHistoryEntry = await service.updateHistoryEntryTimestamp(
|
||||||
Note.create(user, alias),
|
Note.create(user, alias),
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
|
@ -188,7 +188,7 @@ describe('HistoryService', () => {
|
||||||
.mockImplementation(
|
.mockImplementation(
|
||||||
async (entry: HistoryEntry): Promise<HistoryEntry> => entry,
|
async (entry: HistoryEntry): Promise<HistoryEntry> => entry,
|
||||||
);
|
);
|
||||||
const createHistoryEntry = await service.createOrUpdateHistoryEntry(
|
const createHistoryEntry = await service.updateHistoryEntryTimestamp(
|
||||||
Note.create(user, alias),
|
Note.create(user, alias),
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
|
|
|
@ -86,12 +86,13 @@ export class HistoryService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @async
|
* @async
|
||||||
* Create or update a history entry by the user and note. If the entry is merely updated the updatedAt date is set to the current date.
|
* Updates the updatedAt timestamp of a HistoryEntry.
|
||||||
|
* If no history entry exists, it will be created.
|
||||||
* @param {Note} note - the note that the history entry belongs to
|
* @param {Note} note - the note that the history entry belongs to
|
||||||
* @param {User} user - the user that the history entry belongs to
|
* @param {User} user - the user that the history entry belongs to
|
||||||
* @return {HistoryEntry} the requested history entry
|
* @return {HistoryEntry} the requested history entry
|
||||||
*/
|
*/
|
||||||
async createOrUpdateHistoryEntry(
|
async updateHistoryEntryTimestamp(
|
||||||
note: Note,
|
note: Note,
|
||||||
user: User,
|
user: User,
|
||||||
): Promise<HistoryEntry> {
|
): Promise<HistoryEntry> {
|
||||||
|
|
|
@ -87,7 +87,7 @@ describe('History', () => {
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
.expect(200);
|
.expect(200);
|
||||||
expect(emptyResponse.body.length).toEqual(0);
|
expect(emptyResponse.body.length).toEqual(0);
|
||||||
const entry = await historyService.createOrUpdateHistoryEntry(note, user);
|
const entry = await historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
const entryDto = historyService.toHistoryEntryDto(entry);
|
const entryDto = historyService.toHistoryEntryDto(entry);
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
.get('/me/history')
|
.get('/me/history')
|
||||||
|
@ -182,7 +182,7 @@ describe('History', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('PUT /me/history/:note', async () => {
|
it('PUT /me/history/:note', async () => {
|
||||||
const entry = await historyService.createOrUpdateHistoryEntry(note2, user);
|
const entry = await historyService.updateHistoryEntryTimestamp(note2, user);
|
||||||
expect(entry.pinStatus).toBeFalsy();
|
expect(entry.pinStatus).toBeFalsy();
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.put(`/me/history/${entry.note.alias || 'undefined'}`)
|
.put(`/me/history/${entry.note.alias || 'undefined'}`)
|
||||||
|
@ -195,8 +195,8 @@ describe('History', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('DELETE /me/history/:note', async () => {
|
it('DELETE /me/history/:note', async () => {
|
||||||
const entry = await historyService.createOrUpdateHistoryEntry(note2, user);
|
const entry = await historyService.updateHistoryEntryTimestamp(note2, user);
|
||||||
const entry2 = await historyService.createOrUpdateHistoryEntry(note, user);
|
const entry2 = await historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
const entryDto = historyService.toHistoryEntryDto(entry2);
|
const entryDto = historyService.toHistoryEntryDto(entry2);
|
||||||
await request(app.getHttpServer())
|
await request(app.getHttpServer())
|
||||||
.delete(`/me/history/${entry.note.alias || 'undefined'}`)
|
.delete(`/me/history/${entry.note.alias || 'undefined'}`)
|
||||||
|
|
|
@ -96,7 +96,7 @@ describe('Me', () => {
|
||||||
it(`GET /me/history`, async () => {
|
it(`GET /me/history`, async () => {
|
||||||
const noteName = 'testGetNoteHistory1';
|
const noteName = 'testGetNoteHistory1';
|
||||||
const note = await notesService.createNote('', noteName);
|
const note = await notesService.createNote('', noteName);
|
||||||
const createdHistoryEntry = await historyService.createOrUpdateHistoryEntry(
|
const createdHistoryEntry = await historyService.updateHistoryEntryTimestamp(
|
||||||
note,
|
note,
|
||||||
user,
|
user,
|
||||||
);
|
);
|
||||||
|
@ -123,7 +123,7 @@ describe('Me', () => {
|
||||||
const noteName = 'testGetNoteHistory2';
|
const noteName = 'testGetNoteHistory2';
|
||||||
const note = await notesService.createNote('', noteName);
|
const note = await notesService.createNote('', noteName);
|
||||||
const createdHistoryEntry =
|
const createdHistoryEntry =
|
||||||
await historyService.createOrUpdateHistoryEntry(note, user);
|
await historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
.get(`/me/history/${noteName}`)
|
.get(`/me/history/${noteName}`)
|
||||||
.expect('Content-Type', /json/)
|
.expect('Content-Type', /json/)
|
||||||
|
@ -151,7 +151,7 @@ describe('Me', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const noteName = 'testGetNoteHistory3';
|
const noteName = 'testGetNoteHistory3';
|
||||||
const note = await notesService.createNote('', noteName);
|
const note = await notesService.createNote('', noteName);
|
||||||
await historyService.createOrUpdateHistoryEntry(note, user);
|
await historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
const historyEntryUpdateDto = new HistoryEntryUpdateDto();
|
const historyEntryUpdateDto = new HistoryEntryUpdateDto();
|
||||||
historyEntryUpdateDto.pinStatus = true;
|
historyEntryUpdateDto.pinStatus = true;
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
|
@ -181,7 +181,7 @@ describe('Me', () => {
|
||||||
it('works', async () => {
|
it('works', async () => {
|
||||||
const noteName = 'testGetNoteHistory4';
|
const noteName = 'testGetNoteHistory4';
|
||||||
const note = await notesService.createNote('', noteName);
|
const note = await notesService.createNote('', noteName);
|
||||||
await historyService.createOrUpdateHistoryEntry(note, user);
|
await historyService.updateHistoryEntryTimestamp(note, user);
|
||||||
const response = await request(app.getHttpServer())
|
const response = await request(app.getHttpServer())
|
||||||
.delete(`/me/history/${noteName}`)
|
.delete(`/me/history/${noteName}`)
|
||||||
.expect(204);
|
.expect(204);
|
||||||
|
|
Loading…
Reference in a new issue