diff --git a/src/entities/invite-link.entity.ts b/src/entities/invite-link.entity.ts index 757ec18..bfd32c9 100644 --- a/src/entities/invite-link.entity.ts +++ b/src/entities/invite-link.entity.ts @@ -20,7 +20,7 @@ export class InviteLink { @ManyToOne(() => GroupMap) map: GroupMap; - @Property({ type: 'string', default: UserMapRole.WRITE }) + @Property({ type: 'string', default: UserMapRole.READ }) @Enum({ items: [UserMapRole.ADMIN, UserMapRole.READ, UserMapRole.WRITE] }) mapRole: UserMapRoleValueType; diff --git a/src/invite-link/invite-link.service.ts b/src/invite-link/invite-link.service.ts index 6c95d68..23d9f15 100644 --- a/src/invite-link/invite-link.service.ts +++ b/src/invite-link/invite-link.service.ts @@ -9,6 +9,7 @@ import { InviteLink, InviteLinkRepository, User, + UserMapRoleValueType, } from 'src/entities'; import { InviteLinkInvalidException, @@ -26,7 +27,11 @@ export class InviteLinkService { private readonly utilService: UtilService, ) {} - async create(mapId: string, by: User): Promise { + async create( + mapId: string, + role: UserMapRoleValueType, + by: User, + ): Promise { const map = await this.mapRepository.findOne({ id: mapId }); if (map == null) { throw new MapNotFoundException(); @@ -40,6 +45,7 @@ export class InviteLinkService { inviteLink.token = token; inviteLink.createdBy = by; inviteLink.map = map; + inviteLink.mapRole = role; inviteLink.expiresAt = new Date(expiration); await this.inviteLinkRepository.persistAndFlush(inviteLink); diff --git a/src/map/dtos/create-invite-link.dto.ts b/src/map/dtos/create-invite-link.dto.ts new file mode 100644 index 0000000..c864960 --- /dev/null +++ b/src/map/dtos/create-invite-link.dto.ts @@ -0,0 +1,15 @@ +import { ApiProperty } from '@nestjs/swagger'; + +import { IsEnum } from 'class-validator'; + +import { UserMapRole, UserMapRoleValueType } from 'src/entities/index'; + +export class CreateInviteLinkDto { + @IsEnum([UserMapRole.WRITE, UserMapRole.READ]) + @ApiProperty({ + enum: [UserMapRole.WRITE, UserMapRole.READ], // Admin 초대 불가 + default: UserMapRole.READ, + nullable: true, + }) + mapRole: UserMapRoleValueType = UserMapRole.READ; +} diff --git a/src/map/dtos/invite-link-response.dto.ts b/src/map/dtos/invite-link-response.dto.ts index 4c4b9b7..ec716f5 100644 --- a/src/map/dtos/invite-link-response.dto.ts +++ b/src/map/dtos/invite-link-response.dto.ts @@ -11,7 +11,7 @@ export class InviteLinkResponseDto { token: string; @ApiProperty({ - enum: [UserMapRole.ADMIN, UserMapRole.READ, UserMapRole.WRITE], + enum: UserMapRole, }) mapRole: UserMapRoleValueType; diff --git a/src/map/map.controller.ts b/src/map/map.controller.ts index 6642946..0462a00 100644 --- a/src/map/map.controller.ts +++ b/src/map/map.controller.ts @@ -17,6 +17,7 @@ import { } from '@nestjs/swagger'; import { CheckInviteLinkResponseDto } from 'src/map/dtos/check-invite-link-response.dto'; +import { CreateInviteLinkDto } from 'src/map/dtos/create-invite-link.dto'; import { CreateTagDto } from 'src/map/dtos/create-tag.dto'; import { TagResponseDto } from 'src/map/dtos/tag-response.dto'; @@ -108,8 +109,13 @@ export class MapController { async createInviteLink( @CurrentUser() user: User, @Param('id') id: string, + @Body() body: CreateInviteLinkDto, ): Promise { - const entity: InviteLink = await this.inviteLinkService.create(id, user); + const entity: InviteLink = await this.inviteLinkService.create( + id, + body.mapRole, + user, + ); return new InviteLinkResponseDto(entity); } @@ -164,7 +170,8 @@ export class MapController { inviteLink.map, ); - const inviteLinkResponseDto = new InviteLinkResponseDto(inviteLink); + const inviteLinkResponseDto: InviteLinkResponseDto = + new InviteLinkResponseDto(inviteLink); return new CheckInviteLinkResponseDto( map, inviteLinkResponseDto,