refactor(note-metadata): do not embed User objects

This is part of an effort to consistently not embed User objects
in API responses. Usernames are returned instead.

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-01-16 22:54:53 +01:00
parent cdd4f58746
commit f63c15c1ab
No known key found for this signature in database
GPG key ID: 185982BA4C42B7C3
5 changed files with 8 additions and 11 deletions

View file

@ -77,10 +77,10 @@ export class NoteMetadataDto {
/** /**
* User that last edited the note * User that last edited the note
*/ */
@ValidateNested() @IsString()
@ApiPropertyOptional({ type: UserInfoDto }) @ApiPropertyOptional()
@IsOptional() @IsOptional()
updateUser: UserInfoDto | null; updateUsername: string | null;
/** /**
* Counts how many times the published note has been viewed * Counts how many times the published note has been viewed

View file

@ -790,7 +790,7 @@ describe('NotesService', () => {
expect(metadataDto.tags).toHaveLength(1); expect(metadataDto.tags).toHaveLength(1);
expect(metadataDto.tags[0]).toEqual((await note.tags)[0].name); expect(metadataDto.tags[0]).toEqual((await note.tags)[0].name);
expect(metadataDto.updatedAt).toEqual(revisions[0].createdAt); expect(metadataDto.updatedAt).toEqual(revisions[0].createdAt);
expect(metadataDto.updateUser.username).toEqual(user.username); expect(metadataDto.updateUsername).toEqual(user.username);
expect(metadataDto.viewCount).toEqual(note.viewCount); expect(metadataDto.viewCount).toEqual(note.viewCount);
}); });
}); });
@ -896,7 +896,7 @@ describe('NotesService', () => {
expect(noteDto.metadata.tags).toHaveLength(1); expect(noteDto.metadata.tags).toHaveLength(1);
expect(noteDto.metadata.tags[0]).toEqual((await note.tags)[0].name); expect(noteDto.metadata.tags[0]).toEqual((await note.tags)[0].name);
expect(noteDto.metadata.updatedAt).toEqual(revisions[0].createdAt); expect(noteDto.metadata.updatedAt).toEqual(revisions[0].createdAt);
expect(noteDto.metadata.updateUser.username).toEqual(user.username); expect(noteDto.metadata.updateUsername).toEqual(user.username);
expect(noteDto.metadata.viewCount).toEqual(note.viewCount); expect(noteDto.metadata.viewCount).toEqual(note.viewCount);
expect(noteDto.content).toEqual(content); expect(noteDto.content).toEqual(content);
}); });

View file

@ -406,7 +406,7 @@ export class NotesService {
permissions: await this.toNotePermissionsDto(note), permissions: await this.toNotePermissionsDto(note),
tags: await this.toTagList(note), tags: await this.toTagList(note),
updatedAt: (await this.getLatestRevision(note)).createdAt, updatedAt: (await this.getLatestRevision(note)).createdAt,
updateUser: updateUser ? this.usersService.toUserDto(updateUser) : null, updateUsername: updateUser ? updateUser.username : null,
viewCount: note.viewCount, viewCount: note.viewCount,
}; };
} }

View file

@ -175,7 +175,7 @@ describe('Me', () => {
const noteMetaDtos = response.body as NoteMetadataDto[]; const noteMetaDtos = response.body as NoteMetadataDto[];
expect(noteMetaDtos).toHaveLength(1); expect(noteMetaDtos).toHaveLength(1);
expect(noteMetaDtos[0].primaryAlias).toEqual(noteName); expect(noteMetaDtos[0].primaryAlias).toEqual(noteName);
expect(noteMetaDtos[0].updateUser?.username).toEqual(user.username); expect(noteMetaDtos[0].updateUsername).toEqual(user.username);
}); });
it('GET /me/media', async () => { it('GET /me/media', async () => {

View file

@ -281,10 +281,7 @@ describe('Notes', () => {
expect(metadata.body.permissions.sharedToUsers).toEqual([]); expect(metadata.body.permissions.sharedToUsers).toEqual([]);
expect(metadata.body.tags).toEqual([]); expect(metadata.body.tags).toEqual([]);
expect(typeof metadata.body.updatedAt).toEqual('string'); expect(typeof metadata.body.updatedAt).toEqual('string');
expect(typeof metadata.body.updateUser.displayName).toEqual('string'); expect(typeof metadata.body.updateUsername).toEqual('string');
expect(typeof metadata.body.updateUser.username).toEqual('string');
expect(typeof metadata.body.updateUser.email).toEqual('string');
expect(typeof metadata.body.updateUser.photo).toEqual('string');
expect(typeof metadata.body.viewCount).toEqual('number'); expect(typeof metadata.body.viewCount).toEqual('number');
expect(metadata.body.editedBy).toEqual([]); expect(metadata.body.editedBy).toEqual([]);
}); });