diff --git a/src/auth/auth-token.dto.ts b/src/auth/auth-token.dto.ts index 38fb1d1d7..9f00fb33f 100644 --- a/src/auth/auth-token.dto.ts +++ b/src/auth/auth-token.dto.ts @@ -16,5 +16,5 @@ export class AuthTokenDto { validUntil: Date; @IsDate() @IsOptional() - lastUsed: Date | null; + lastUsedAt: Date | null; } diff --git a/src/auth/auth-token.entity.ts b/src/auth/auth-token.entity.ts index 668956813..cabae5547 100644 --- a/src/auth/auth-token.entity.ts +++ b/src/auth/auth-token.entity.ts @@ -42,7 +42,7 @@ export class AuthToken { nullable: true, type: 'date', }) - lastUsed: Date | null; + lastUsedAt: Date | null; public static create( keyId: string, @@ -57,7 +57,7 @@ export class AuthToken { newToken.label = label; newToken.accessTokenHash = accessToken; newToken.validUntil = validUntil; - newToken.lastUsed = null; + newToken.lastUsedAt = null; return newToken; } } diff --git a/src/auth/auth.service.spec.ts b/src/auth/auth.service.spec.ts index f4276744b..e21842d88 100644 --- a/src/auth/auth.service.spec.ts +++ b/src/auth/auth.service.spec.ts @@ -143,14 +143,14 @@ describe('AuthService', () => { jest.spyOn(authTokenRepo, 'findOne').mockResolvedValueOnce({ ...authToken, user: Promise.resolve(user), - lastUsed: new Date(1549312452000), + lastUsedAt: new Date(1549312452000), }); jest .spyOn(authTokenRepo, 'save') .mockImplementationOnce( async (authTokenSaved, _): Promise => { expect(authTokenSaved.keyId).toEqual(authToken.keyId); - expect(authTokenSaved.lastUsed).not.toEqual(1549312452000); + expect(authTokenSaved.lastUsedAt).not.toEqual(1549312452000); return authToken; }, ); @@ -242,7 +242,7 @@ describe('AuthService', () => { .spyOn(authTokenRepo, 'save') .mockImplementationOnce( async (authTokenSaved: AuthToken, _): Promise => { - expect(authTokenSaved.lastUsed).toBeNull(); + expect(authTokenSaved.lastUsedAt).toBeNull(); return authTokenSaved; }, ); @@ -252,7 +252,7 @@ describe('AuthService', () => { token.validUntil.getTime() - (new Date().getTime() + 2 * 365 * 24 * 60 * 60 * 1000), ).toBeLessThanOrEqual(10000); - expect(token.lastUsed).toBeNull(); + expect(token.lastUsedAt).toBeNull(); expect(token.secret.startsWith(token.keyId)).toBeTruthy(); }); it('with validUntil not 0', async () => { @@ -261,7 +261,7 @@ describe('AuthService', () => { .spyOn(authTokenRepo, 'save') .mockImplementationOnce( async (authTokenSaved: AuthToken, _): Promise => { - expect(authTokenSaved.lastUsed).toBeNull(); + expect(authTokenSaved.lastUsedAt).toBeNull(); return authTokenSaved; }, ); @@ -273,7 +273,7 @@ describe('AuthService', () => { ); expect(token.label).toEqual(identifier); expect(token.validUntil.getTime()).toEqual(validUntil); - expect(token.lastUsed).toBeNull(); + expect(token.lastUsedAt).toBeNull(); expect(token.secret.startsWith(token.keyId)).toBeTruthy(); }); }); @@ -290,7 +290,7 @@ describe('AuthService', () => { authToken.validUntil = new Date(); const tokenDto = service.toAuthTokenDto(authToken); expect(tokenDto.keyId).toEqual(authToken.keyId); - expect(tokenDto.lastUsed).toBeNull(); + expect(tokenDto.lastUsedAt).toBeNull(); expect(tokenDto.label).toEqual(authToken.label); expect(tokenDto.validUntil.getTime()).toEqual( authToken.validUntil.getTime(), diff --git a/src/auth/auth.service.ts b/src/auth/auth.service.ts index 430ea02db..fcb555cb1 100644 --- a/src/auth/auth.service.ts +++ b/src/auth/auth.service.ts @@ -108,7 +108,7 @@ export class AuthService { if (accessToken === undefined) { throw new NotInDBError(`AuthToken for key '${keyId}' not found`); } - accessToken.lastUsed = new Date(); + accessToken.lastUsedAt = new Date(); await this.authTokenRepository.save(accessToken); } @@ -175,11 +175,11 @@ export class AuthService { keyId: authToken.keyId, createdAt: authToken.createdAt, validUntil: authToken.validUntil, - lastUsed: null, + lastUsedAt: null, }; - if (authToken.lastUsed) { - tokenDto.lastUsed = new Date(authToken.lastUsed); + if (authToken.lastUsedAt) { + tokenDto.lastUsedAt = new Date(authToken.lastUsedAt); } return tokenDto; diff --git a/src/history/history-entry.dto.ts b/src/history/history-entry.dto.ts index 12d51e416..eeaf24d75 100644 --- a/src/history/history-entry.dto.ts +++ b/src/history/history-entry.dto.ts @@ -29,7 +29,7 @@ export class HistoryEntryDto { */ @IsDate() @ApiProperty() - lastVisited: Date; + lastVisitedAt: Date; @IsArray() @IsString({ each: true }) diff --git a/src/history/history.service.ts b/src/history/history.service.ts index c4081d3bc..3cdea5269 100644 --- a/src/history/history.service.ts +++ b/src/history/history.service.ts @@ -189,7 +189,7 @@ export class HistoryService { async toHistoryEntryDto(entry: HistoryEntry): Promise { return { identifier: await getIdentifier(entry), - lastVisited: entry.updatedAt, + lastVisitedAt: entry.updatedAt, tags: await this.notesService.toTagList(entry.note), title: entry.note.title ?? '', pinStatus: entry.pinStatus, diff --git a/src/notes/note-metadata.dto.ts b/src/notes/note-metadata.dto.ts index 137e92ce2..e41433720 100644 --- a/src/notes/note-metadata.dto.ts +++ b/src/notes/note-metadata.dto.ts @@ -72,7 +72,7 @@ export class NoteMetadataDto { */ @IsDate() @ApiProperty() - updateTime: Date; + updatedAt: Date; /** * User that last edited the note @@ -96,7 +96,7 @@ export class NoteMetadataDto { */ @IsDate() @ApiProperty() - createTime: Date; + createdAt: Date; /** * List of usernames that edited the note diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index 76ec8e1bc..8ebd3f04d 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -773,7 +773,7 @@ describe('NotesService', () => { expect(metadataDto.aliases).toHaveLength(1); expect(metadataDto.aliases[0]).toEqual((await note.aliases)[0].name); expect(metadataDto.title).toEqual(note.title); - expect(metadataDto.createTime).toEqual(revisions[0].createdAt); + expect(metadataDto.createdAt).toEqual(revisions[0].createdAt); expect(metadataDto.description).toEqual(note.description); expect(metadataDto.editedBy).toHaveLength(1); expect(metadataDto.editedBy[0]).toEqual(user.username); @@ -790,7 +790,7 @@ describe('NotesService', () => { expect(metadataDto.permissions.sharedToGroups[0].canEdit).toEqual(true); expect(metadataDto.tags).toHaveLength(1); expect(metadataDto.tags[0]).toEqual((await note.tags)[0].name); - expect(metadataDto.updateTime).toEqual(revisions[0].createdAt); + expect(metadataDto.updatedAt).toEqual(revisions[0].createdAt); expect(metadataDto.updateUser.username).toEqual(user.username); expect(metadataDto.viewCount).toEqual(note.viewCount); }); @@ -875,7 +875,7 @@ describe('NotesService', () => { expect(noteDto.metadata.aliases).toHaveLength(1); expect(noteDto.metadata.aliases[0]).toEqual((await note.aliases)[0].name); expect(noteDto.metadata.title).toEqual(note.title); - expect(noteDto.metadata.createTime).toEqual(revisions[0].createdAt); + expect(noteDto.metadata.createdAt).toEqual(revisions[0].createdAt); expect(noteDto.metadata.description).toEqual(note.description); expect(noteDto.metadata.editedBy).toHaveLength(1); expect(noteDto.metadata.editedBy[0]).toEqual(user.username); @@ -898,7 +898,7 @@ describe('NotesService', () => { ); expect(noteDto.metadata.tags).toHaveLength(1); expect(noteDto.metadata.tags[0]).toEqual((await note.tags)[0].name); - expect(noteDto.metadata.updateTime).toEqual(revisions[0].createdAt); + expect(noteDto.metadata.updatedAt).toEqual(revisions[0].createdAt); expect(noteDto.metadata.updateUser.username).toEqual(user.username); expect(noteDto.metadata.viewCount).toEqual(note.viewCount); expect(noteDto.content).toEqual(content); diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index 0eee31428..c66d6102e 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -400,12 +400,12 @@ export class NotesService { ), primaryAlias: (await getPrimaryAlias(note)) ?? null, title: note.title ?? '', - createTime: (await this.getFirstRevision(note)).createdAt, + createdAt: (await this.getFirstRevision(note)).createdAt, description: note.description ?? '', editedBy: (await this.getAuthorUsers(note)).map((user) => user.username), permissions: await this.toNotePermissionsDto(note), tags: await this.toTagList(note), - updateTime: (await this.getLatestRevision(note)).createdAt, + updatedAt: (await this.getLatestRevision(note)).createdAt, updateUser: updateUser ? this.usersService.toUserDto(updateUser) : null, viewCount: note.viewCount, }; diff --git a/test/private-api/history.e2e-spec.ts b/test/private-api/history.e2e-spec.ts index 0da6cf547..f8735bd77 100644 --- a/test/private-api/history.e2e-spec.ts +++ b/test/private-api/history.e2e-spec.ts @@ -79,8 +79,8 @@ describe('History', () => { expect(response.body[0].title).toEqual(entryDto.title); expect(response.body[0].tags).toEqual(entryDto.tags); expect(response.body[0].pinStatus).toEqual(entryDto.pinStatus); - expect(response.body[0].lastVisited).toEqual( - entryDto.lastVisited.toISOString(), + expect(response.body[0].lastVisitedAt).toEqual( + entryDto.lastVisitedAt.toISOString(), ); }); @@ -218,7 +218,7 @@ describe('History', () => { expect(userEntryDto.title).toEqual(entryDto.title); expect(userEntryDto.tags).toEqual(entryDto.tags); expect(userEntryDto.pinStatus).toEqual(entryDto.pinStatus); - expect(userEntryDto.lastVisited).toEqual(entryDto.lastVisited); + expect(userEntryDto.lastVisitedAt).toEqual(entryDto.lastVisitedAt); }); afterAll(async () => { diff --git a/test/private-api/tokens.e2e-spec.ts b/test/private-api/tokens.e2e-spec.ts index d3b140932..d73aeb5ff 100644 --- a/test/private-api/tokens.e2e-spec.ts +++ b/test/private-api/tokens.e2e-spec.ts @@ -47,7 +47,7 @@ describe('Tokens', () => { keyId = response.body.keyId; expect(response.body.label).toBe(tokenName); expect(response.body.validUntil).toBe(null); - expect(response.body.lastUsed).toBe(null); + expect(response.body.lastUsedAt).toBe(null); expect(response.body.secret.length).toBe(98); }); @@ -59,7 +59,7 @@ describe('Tokens', () => { .expect(200); expect(response.body[0].label).toBe(tokenName); expect(response.body[0].validUntil).toBe(null); - expect(response.body[0].lastUsed).toBe(null); + expect(response.body[0].lastUsedAt).toBe(null); expect(response.body[0].secret).not.toBeDefined(); }); it(`DELETE /tokens/:keyid`, async () => { diff --git a/test/public-api/me.e2e-spec.ts b/test/public-api/me.e2e-spec.ts index 3e947933b..e2d42fcb1 100644 --- a/test/public-api/me.e2e-spec.ts +++ b/test/public-api/me.e2e-spec.ts @@ -59,8 +59,8 @@ describe('Me', () => { expect(historyEntry.title).toEqual(historyDto.title); expect(historyEntry.tags).toEqual(historyDto.tags); expect(historyEntry.pinStatus).toEqual(historyDto.pinStatus); - expect(historyEntry.lastVisited).toEqual( - historyDto.lastVisited.toISOString(), + expect(historyEntry.lastVisitedAt).toEqual( + historyDto.lastVisitedAt.toISOString(), ); } }); @@ -83,8 +83,8 @@ describe('Me', () => { expect(historyEntry.title).toEqual(historyEntryDto.title); expect(historyEntry.tags).toEqual(historyEntryDto.tags); expect(historyEntry.pinStatus).toEqual(historyEntryDto.pinStatus); - expect(historyEntry.lastVisited).toEqual( - historyEntryDto.lastVisited.toISOString(), + expect(historyEntry.lastVisitedAt).toEqual( + historyEntryDto.lastVisitedAt.toISOString(), ); }); it('fails with a non-existing note', async () => { diff --git a/test/public-api/notes.e2e-spec.ts b/test/public-api/notes.e2e-spec.ts index d5dd441bc..a120ee8c3 100644 --- a/test/public-api/notes.e2e-spec.ts +++ b/test/public-api/notes.e2e-spec.ts @@ -274,13 +274,13 @@ describe('Notes', () => { expect(metadata.body.primaryAlias).toEqual('test5'); expect(metadata.body.title).toEqual(''); expect(metadata.body.description).toEqual(''); - expect(typeof metadata.body.createTime).toEqual('string'); + expect(typeof metadata.body.createdAt).toEqual('string'); expect(metadata.body.editedBy).toEqual([]); expect(metadata.body.permissions.owner.username).toEqual('hardcoded'); expect(metadata.body.permissions.sharedToUsers).toEqual([]); expect(metadata.body.permissions.sharedToUsers).toEqual([]); expect(metadata.body.tags).toEqual([]); - expect(typeof metadata.body.updateTime).toEqual('string'); + expect(typeof metadata.body.updatedAt).toEqual('string'); expect(typeof metadata.body.updateUser.displayName).toEqual('string'); expect(typeof metadata.body.updateUser.username).toEqual('string'); expect(typeof metadata.body.updateUser.email).toEqual('string'); @@ -320,7 +320,7 @@ describe('Notes', () => { const metadata = await request(testSetup.app.getHttpServer()) .get('/api/v2/notes/test5a/metadata') .expect(200); - expect(metadata.body.createTime).toEqual(createDate.toISOString()); + expect(metadata.body.createdAt).toEqual(createDate.toISOString()); expect(metadata.body.updateTime).not.toEqual(createDate.toISOString()); }); });