Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Edit InviteLink #49

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/entities/invite-link.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 7 additions & 1 deletion src/invite-link/invite-link.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
InviteLink,
InviteLinkRepository,
User,
UserMapRoleValueType,
} from 'src/entities';
import {
InviteLinkInvalidException,
Expand All @@ -26,7 +27,11 @@ export class InviteLinkService {
private readonly utilService: UtilService,
) {}

async create(mapId: string, by: User): Promise<InviteLink> {
async create(
mapId: string,
role: UserMapRoleValueType,
by: User,
): Promise<InviteLink> {
const map = await this.mapRepository.findOne({ id: mapId });
if (map == null) {
throw new MapNotFoundException();
Expand All @@ -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);
Expand Down
15 changes: 15 additions & 0 deletions src/map/dtos/create-invite-link.dto.ts
Original file line number Diff line number Diff line change
@@ -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])
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADMIN으로 초대할 수 없도록 제한

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오잉! 우리 READ로만 일단 가기로 하지 않았었나요?

확장성을 위한 설계인가요?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

맞습니당~~ 기본이 READ고 WRITE로도 초대링크 생성할 수 있게 열어놔쓰예

@ApiProperty({
enum: [UserMapRole.WRITE, UserMapRole.READ], // Admin 초대 불가
default: UserMapRole.READ,
nullable: true,
})
mapRole: UserMapRoleValueType = UserMapRole.READ;
}
2 changes: 1 addition & 1 deletion src/map/dtos/invite-link-response.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class InviteLinkResponseDto {
token: string;

@ApiProperty({
enum: [UserMapRole.ADMIN, UserMapRole.READ, UserMapRole.WRITE],
enum: UserMapRole,
})
mapRole: UserMapRoleValueType;

Expand Down
11 changes: 9 additions & 2 deletions src/map/map.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -108,8 +109,13 @@ export class MapController {
async createInviteLink(
@CurrentUser() user: User,
@Param('id') id: string,
@Body() body: CreateInviteLinkDto,
): Promise<InviteLinkResponseDto> {
const entity: InviteLink = await this.inviteLinkService.create(id, user);
const entity: InviteLink = await this.inviteLinkService.create(
id,
body.mapRole,
user,
);
return new InviteLinkResponseDto(entity);
}

Expand Down Expand Up @@ -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,
Expand Down
Loading