From 13284b26cbde2f901ad730439d22d99e8aaf3a77 Mon Sep 17 00:00:00 2001 From: David Mehren Date: Sun, 16 Jan 2022 22:24:54 +0100 Subject: [PATCH] refactor(note-user-permission-entry-dto): 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 --- src/notes/note-permissions.dto.ts | 8 ++++---- src/notes/notes.service.spec.ts | 10 +++++----- src/notes/notes.service.ts | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/notes/note-permissions.dto.ts b/src/notes/note-permissions.dto.ts index 7594c8cf2..753344c91 100644 --- a/src/notes/note-permissions.dto.ts +++ b/src/notes/note-permissions.dto.ts @@ -17,11 +17,11 @@ import { UserInfoDto } from '../users/user-info.dto'; export class NoteUserPermissionEntryDto { /** - * User this permission applies to + * Username of the User this permission applies to */ - @ValidateNested() - @ApiProperty({ type: UserInfoDto }) - user: UserInfoDto; + @IsString() + @ApiProperty() + username: string; /** * True if the user is allowed to edit the note diff --git a/src/notes/notes.service.spec.ts b/src/notes/notes.service.spec.ts index 901c1dcdb..17f7a072f 100644 --- a/src/notes/notes.service.spec.ts +++ b/src/notes/notes.service.spec.ts @@ -688,7 +688,7 @@ describe('NotesService', () => { const permissions = await service.toNotePermissionsDto(note); expect(permissions.owner).toEqual(user.username); expect(permissions.sharedToUsers).toHaveLength(1); - expect(permissions.sharedToUsers[0].user.username).toEqual(user.username); + expect(permissions.sharedToUsers[0].username).toEqual(user.username); expect(permissions.sharedToUsers[0].canEdit).toEqual(true); expect(permissions.sharedToGroups).toHaveLength(1); expect(permissions.sharedToGroups[0].group.displayName).toEqual( @@ -778,7 +778,7 @@ describe('NotesService', () => { expect(metadataDto.editedBy[0]).toEqual(user.username); expect(metadataDto.permissions.owner).toEqual(user.username); expect(metadataDto.permissions.sharedToUsers).toHaveLength(1); - expect(metadataDto.permissions.sharedToUsers[0].user.username).toEqual( + expect(metadataDto.permissions.sharedToUsers[0].username).toEqual( user.username, ); expect(metadataDto.permissions.sharedToUsers[0].canEdit).toEqual(true); @@ -880,9 +880,9 @@ describe('NotesService', () => { expect(noteDto.metadata.editedBy[0]).toEqual(user.username); expect(noteDto.metadata.permissions.owner).toEqual(user.username); expect(noteDto.metadata.permissions.sharedToUsers).toHaveLength(1); - expect( - noteDto.metadata.permissions.sharedToUsers[0].user.username, - ).toEqual(user.username); + expect(noteDto.metadata.permissions.sharedToUsers[0].username).toEqual( + user.username, + ); expect(noteDto.metadata.permissions.sharedToUsers[0].canEdit).toEqual( true, ); diff --git a/src/notes/notes.service.ts b/src/notes/notes.service.ts index cfa1668b7..e89730eea 100644 --- a/src/notes/notes.service.ts +++ b/src/notes/notes.service.ts @@ -375,7 +375,7 @@ export class NotesService { return { owner: owner ? owner.username : null, sharedToUsers: userPermissions.map((noteUserPermission) => ({ - user: this.usersService.toUserDto(noteUserPermission.user), + username: noteUserPermission.user.username, canEdit: noteUserPermission.canEdit, })), sharedToGroups: groupPermissions.map((noteGroupPermission) => ({