Skip to content

Commit

Permalink
modify: external info
Browse files Browse the repository at this point in the history
  • Loading branch information
siwonpada committed Sep 2, 2024
1 parent 42c4dac commit e817caf
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 14 deletions.
22 changes: 19 additions & 3 deletions src/external/dto/res/externalInfoRes.dto.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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<Role>) {
Object.assign(this, partial);
}
}

class GroupWithRoleResDto implements GroupWithRole {
export class GroupWithRoleResDto implements GroupWithRole {
@ApiProperty()
uuid: string;

Expand Down Expand Up @@ -66,6 +78,10 @@ class GroupWithRoleResDto implements GroupWithRole {

@Exclude()
deletedAt: Date | null;

constructor(partial: Partial<GroupWithRole>) {
Object.assign(this, partial);
}
}

export class ExternalInfoResDto {
Expand Down
11 changes: 9 additions & 2 deletions src/external/external.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -35,6 +38,10 @@ export class ExternalService {
}

async getExternalInfo(payload: ExternalPayload): Promise<ExternalInfoResDto> {
return this.groupService.getGroupListWithRole(payload.sub, payload.aud);
return {
list: (
await this.groupService.getGroupListWithRole(payload.sub, payload.aud)
).map((groupWithRole) => new GroupWithRoleResDto(groupWithRole)),
};
}
}
11 changes: 2 additions & 9 deletions src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,15 +221,8 @@ export class GroupService {
async getGroupListWithRole(
userUuid: string,
clientUuid: string,
): Promise<{
list: GroupWithRole[];
}> {
): Promise<GroupWithRole[]> {
this.logger.log(`getGroupListWithRole`);
return {
list: await this.groupRepository.getGroupListWithRole(
userUuid,
clientUuid,
),
};
return this.groupRepository.getGroupListWithRole(userUuid, clientUuid);
}
}

0 comments on commit e817caf

Please sign in to comment.