diff --git a/src/external/dto/res/externalInfoRes.dto.ts b/src/external/dto/res/externalInfoRes.dto.ts index db37cec..f8b6bd2 100644 --- a/src/external/dto/res/externalInfoRes.dto.ts +++ b/src/external/dto/res/externalInfoRes.dto.ts @@ -1,6 +1,6 @@ import { ApiProperty } from '@nestjs/swagger'; import { Authority, Role, RoleExternalAuthority } from '@prisma/client'; -import { Exclude } from 'class-transformer'; +import { Exclude, Expose } from 'class-transformer'; import { GroupWithRole } from 'src/group/types/groupWithRole'; class RoleExternalAuthorityResDto implements RoleExternalAuthority { @@ -32,11 +32,23 @@ class RoleResDto implements Role { }) authorities: Authority[]; - @ApiProperty({ type: RoleExternalAuthorityResDto, isArray: true }) + @ApiProperty() + @Expose() + get externalAuthority(): string[] { + return this.RoleExternalAuthority.map( + (roleExternalAuthority) => roleExternalAuthority.authority, + ); + } + + @Exclude() RoleExternalAuthority: RoleExternalAuthorityResDto[]; + + constructor(partial: Partial) { + Object.assign(this, partial); + } } -class GroupWithRoleResDto implements GroupWithRole { +export class GroupWithRoleResDto implements GroupWithRole { @ApiProperty() uuid: string; @@ -66,6 +78,10 @@ class GroupWithRoleResDto implements GroupWithRole { @Exclude() deletedAt: Date | null; + + constructor(partial: Partial) { + Object.assign(this, partial); + } } export class ExternalInfoResDto { diff --git a/src/external/external.service.ts b/src/external/external.service.ts index 6d5f3e1..76f3d0d 100644 --- a/src/external/external.service.ts +++ b/src/external/external.service.ts @@ -6,7 +6,10 @@ import { UserService } from 'src/user/user.service'; import { GroupService } from 'src/group/group.service'; import { ExternalTokenResDto } from './dto/res/externalTokenRes.dto'; import { ExternalPayload } from './types/certPayload'; -import { ExternalInfoResDto } from './dto/res/externalInfoRes.dto'; +import { + ExternalInfoResDto, + GroupWithRoleResDto, +} from './dto/res/externalInfoRes.dto'; @Injectable() export class ExternalService { @@ -35,6 +38,10 @@ export class ExternalService { } async getExternalInfo(payload: ExternalPayload): Promise { - return this.groupService.getGroupListWithRole(payload.sub, payload.aud); + return { + list: ( + await this.groupService.getGroupListWithRole(payload.sub, payload.aud) + ).map((groupWithRole) => new GroupWithRoleResDto(groupWithRole)), + }; } } diff --git a/src/group/group.service.ts b/src/group/group.service.ts index 4ce74a9..a05a8e7 100644 --- a/src/group/group.service.ts +++ b/src/group/group.service.ts @@ -221,15 +221,8 @@ export class GroupService { async getGroupListWithRole( userUuid: string, clientUuid: string, - ): Promise<{ - list: GroupWithRole[]; - }> { + ): Promise { this.logger.log(`getGroupListWithRole`); - return { - list: await this.groupRepository.getGroupListWithRole( - userUuid, - clientUuid, - ), - }; + return this.groupRepository.getGroupListWithRole(userUuid, clientUuid); } }