Skip to content

Commit

Permalink
feat: 모임 편집자/조회자 초대
Browse files Browse the repository at this point in the history
  • Loading branch information
w8385 committed May 25, 2024
1 parent 92394e8 commit e781410
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
29 changes: 29 additions & 0 deletions src/group/group.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { Member } from '../member/member.decorators';
import { GetTransactionsPeriodDto } from '../transaction/dto/get-transaction-period-dto';
import { UploadTransactionDto } from '../transaction/dto/upload-transaction-dto';
import { Transaction } from '../transaction/transaction.decorators';
import { User } from '../user/user.decorator';
import { CreateGroupDto } from './dto/create-group.dto';
import { UpdateGroupDto } from './dto/update-group.dto';
import { UploadGroupDto } from './dto/upload-group.dto';
Expand Down Expand Up @@ -304,4 +305,32 @@ export class GroupController {
) {
return this.groupService.deleteEvent(req.userId, groupId, eventId);
}

@Post(':groupId/invite/editor')
@User()
@ApiOperation({
summary: '모임 편집자 초대',
description: '특정 모임에 편집자를 초대합니다.',
})
inviteEditor(
@Req() req: any,
@Param('groupId', new ParseObjectIdPipe()) groupId: string,
@Query('userId', new ParseObjectIdPipe()) userId: string,
) {
return this.groupService.inviteEditor(req.userId, groupId, userId);
}

@Post(':groupId/invite/viewer')
@User()
@ApiOperation({
summary: '모임 조회자 초대',
description: '특정 모임에 조회자를 초대합니다.',
})
inviteViewer(
@Req() req: any,
@Param('groupId', new ParseObjectIdPipe()) groupId: string,
@Query('userId', new ParseObjectIdPipe()) userId: string,
) {
return this.groupService.inviteViewer(req.userId, groupId, userId);
}
}
20 changes: 20 additions & 0 deletions src/group/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,26 @@ export class GroupService {
await this.groupRepository.update(groupId, group);
}

async inviteEditor(senderId: string, groupId: string, receiverId: string) {
const group = await this.groupRepository.findOne(groupId);
this.groupValidator.validateGroupOwner(group, senderId);

group.auth.editors.push(receiverId);
await this.userService.pushEditor(receiverId, groupId);

return await this.groupRepository.update(groupId, group);
}

async inviteViewer(senderId: string, groupId: string, receiverId: string) {
const group = await this.groupRepository.findOne(groupId);
this.groupValidator.validateGroupViewer(group, senderId);

group.auth.viewers.push(receiverId);
await this.userService.pushViewer(receiverId, groupId);

return await this.groupRepository.update(groupId, group);
}

private async getAllMembers(memberIds: string[]) {
const members = [];
for (const memberId of memberIds) {
Expand Down
6 changes: 6 additions & 0 deletions src/user/user.decorator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { applyDecorators } from '@nestjs/common';
import { ApiTags } from '@nestjs/swagger';

export function User() {
return applyDecorators(ApiTags('User'));
}

0 comments on commit e781410

Please sign in to comment.