Skip to content

Commit

Permalink
feat: 초대시 block 상황 처리
Browse files Browse the repository at this point in the history
  • Loading branch information
tomatoziyun committed Dec 14, 2023
1 parent fc70d6e commit 018532f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/game/dto/create-game-param.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class CreateGameParamDto {
gameInvitationId: number;
invitationId: number;
invitedUserId: number;
}
2 changes: 1 addition & 1 deletion src/game/dto/delete-invitation-param.dto.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export class DeleteGameInvitationParamDto {
cancelingUserId: number;
gameInvitationId: number;
invitationId: number;
}
14 changes: 7 additions & 7 deletions src/game/game.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ export class GameController {
/**
* 초대 수락
* @param user
* @param gameInvitationId 초대 테이블의 id
* @param invitationId 초대 테이블의 id
* (초대시 프론트가 이벤트를 수신하며 받은 data 입니다)
*/
@Post('/accept')
async createGame(
@GetUser() user: User,
@Body('gameInvitationId', ParseIntPipe, PositiveIntPipe)
gameInvitationId: number,
invitationId: number,
) {
const createGameParamDto: CreateGameParamDto = {
invitedUserId: user.id,
gameInvitationId: gameInvitationId,
invitationId: invitationId,
};
await this.gameService.createGame(createGameParamDto);
}
Expand All @@ -62,11 +62,11 @@ export class GameController {
async deleteInvitation(
@GetUser() user: User,
@Param('gameInvitationId', ParseIntPipe, PositiveIntPipe)
gameInvitationId: number,
invitationId: number,
) {
const deleteInvitationParamDto: DeleteGameInvitationParamDto = {
cancelingUserId: user.id,
gameInvitationId: gameInvitationId,
invitationId: invitationId,
};
await this.gameService.deleteInvitationByInvitingUserId(
deleteInvitationParamDto,
Expand All @@ -77,11 +77,11 @@ export class GameController {
async refuseInvitation(
@GetUser() user: User,
@Param('gameInvitationId', ParseIntPipe, PositiveIntPipe)
gameInvitationId: number,
invitationId: number,
) {
const deleteInvitationParamDto: DeleteGameInvitationParamDto = {
cancelingUserId: user.id,
gameInvitationId: gameInvitationId,
invitationId: invitationId,
};
await this.gameService.deleteInvitationByInvitedUserId(
deleteInvitationParamDto,
Expand Down
4 changes: 4 additions & 0 deletions src/game/game.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import { FriendsRepository } from '../users/friends.repository';
import { ChannelUser } from '../channels/entities/channel-user.entity';
import { Friend } from '../users/entities/friend.entity';
import { ChannelsModule } from '../channels/channels.module';
import { Block } from '../users/entities/block.entity';
import { BlocksRepository } from '../users/blocks.repository';

@Module({
imports: [
Expand All @@ -25,6 +27,7 @@ import { ChannelsModule } from '../channels/channels.module';
User,
ChannelUser,
Friend,
Block,
]),
ChannelsModule,
],
Expand All @@ -36,6 +39,7 @@ import { ChannelsModule } from '../channels/channels.module';
JwtService,
ChannelUsersRepository,
FriendsRepository,
BlocksRepository,
GameRepository,
GameInvitationRepository,
UsersRepository,
Expand Down
12 changes: 9 additions & 3 deletions src/game/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { CreateGameParamDto } from './dto/create-game-param.dto';
import { GatewaySendInvitationReplyDto } from './dto/gateway-send-invitation-reaponse.dto';
import { User } from '../users/entities/user.entity';
import * as moment from 'moment';
import { BlocksRepository } from '../users/blocks.repository';

@Injectable()
export class GameService {
Expand All @@ -25,6 +26,7 @@ export class GameService {
private readonly gameInvitationRepository: GameInvitationRepository,
private readonly gameGateway: GameGateway,
private readonly usersRepository: UsersRepository,
private readonly blocksRepository: BlocksRepository,
) {}

async createInvitation(invitationParamDto: CreateGameInvitationParamDto) {
Expand All @@ -47,6 +49,10 @@ export class GameService {
throw new ImATeapotException(
`초대된 유저 ${invitedUserId} 는 OFFLINE 상태입니다`,
);
const isblocked = await this.blocksRepository.findOne({
where: { fromUserId: invitedUserId, toUserId: invitingUser.id },
});
if (isblocked) return;

// game invitation DB 저장
const gameInvitation =
Expand All @@ -65,7 +71,7 @@ export class GameService {
}

async createGame(createGameParamDto: CreateGameParamDto) {
const invitationId = createGameParamDto.gameInvitationId;
const invitationId = createGameParamDto.invitationId;
const invitedUserId = createGameParamDto.invitedUserId;

const invitation = await this.gameInvitationRepository.findOne({
Expand Down Expand Up @@ -161,7 +167,7 @@ export class GameService {
async deleteInvitationByInvitingUserId(
deleteInvitationParamDto: DeleteGameInvitationParamDto,
) {
const invitationId = deleteInvitationParamDto.gameInvitationId;
const invitationId = deleteInvitationParamDto.invitationId;
const invitingUserId = deleteInvitationParamDto.cancelingUserId;

const invitation = await this.gameInvitationRepository.findOne({
Expand Down Expand Up @@ -189,7 +195,7 @@ export class GameService {
async deleteInvitationByInvitedUserId(
deleteInvitationParamDto: DeleteGameInvitationParamDto,
) {
const invitationId = deleteInvitationParamDto.gameInvitationId;
const invitationId = deleteInvitationParamDto.invitationId;
const invitedUserId = deleteInvitationParamDto.cancelingUserId;

const invitation = await this.gameInvitationRepository.findOne({
Expand Down

0 comments on commit 018532f

Please sign in to comment.