diff --git a/server/api/src/domain/auth/auth.module.ts b/server/api/src/domain/auth/auth.module.ts index 8c94a148..39ee1c3f 100644 --- a/server/api/src/domain/auth/auth.module.ts +++ b/server/api/src/domain/auth/auth.module.ts @@ -6,11 +6,12 @@ import { JwtStrategy } from './strategy/jwt.strategy'; import { AuthController } from './controller/auth.controller'; import { AuthService } from './service/auth.service'; import { UserRepository } from '../user/repository/user.repository'; +import { DevFieldRepository } from '../field/repository/dev-field.repository'; import { HistoryModule } from '../history/history.module'; @Module({ imports: [ - TypeOrmModule.forFeature([UserRepository]), + TypeOrmModule.forFeature([UserRepository, DevFieldRepository]), PassportModule, JwtModule.register({ secret: 'secretkey', diff --git a/server/api/src/domain/auth/service/auth.service.ts b/server/api/src/domain/auth/service/auth.service.ts index af08910c..33fa10af 100644 --- a/server/api/src/domain/auth/service/auth.service.ts +++ b/server/api/src/domain/auth/service/auth.service.ts @@ -4,13 +4,15 @@ import { JwtService } from '@nestjs/jwt'; import { LocalDate } from 'js-joda'; import { Bcrypt } from 'src/utils/bcrypt'; import { UserBuilder } from '../../../builder'; -import { UserException } from '../../../exception'; +import { DevFieldException, UserException } from '../../../exception'; import { User } from '../../user/user.entity'; import { HistoryService } from 'src/domain/history/service/history.service'; import { UserRepository } from '../../user/repository/user.repository'; +import { DevFieldRepository } from 'src/domain/field/repository/dev-field.repository'; import { LoginRequestDto } from '../dto/login-request.dto'; import { UserResponseDto } from '../dto/user-response.dto'; import { JoinRequestDto } from '../dto/join-request.dto'; +import { DevField } from 'src/domain/field/dev-field.entity'; @Injectable() export class AuthService { @@ -18,6 +20,9 @@ export class AuthService { @InjectRepository(UserRepository) private readonly userRepository: UserRepository, + @InjectRepository(DevFieldRepository) + private readonly devFieldRepository: DevFieldRepository, + private readonly historyService: HistoryService, private jwtService: JwtService, ) {} @@ -42,11 +47,14 @@ export class AuthService { const { nickname, email, password } = joinRequestDto; const isExistUser = await this.userRepository.exists(joinRequestDto); if (isExistUser) throw UserException.userIsExist(); + const devField: DevField = await this.devFieldRepository.findDevById(joinRequestDto.devFieldId); + if (!devField) throw DevFieldException.devFieldNotFound(); const user: User = new UserBuilder() .setNickName(nickname) .setEmail(email) .setPassword(Bcrypt.hash(password)) .setImageURL(process.env.DEFAULT_IMG) + .setDevField(devField) .build(); await this.userRepository.save(user); return true; diff --git a/server/socket/src/gateway/room.gateway.ts b/server/socket/src/gateway/room.gateway.ts index 731386d4..eb1f336f 100644 --- a/server/socket/src/gateway/room.gateway.ts +++ b/server/socket/src/gateway/room.gateway.ts @@ -31,28 +31,44 @@ export class RoomGateway implements OnGatewayInit, OnGatewayConnection, OnGatewa } @SubscribeMessage('join-room') - handleJoinRoom(client: Socket, { field, img, nickname, roomId }: IRoomRequest): void { + handleJoinRoom(client: Socket, { field, img, nickname, roomId, maxHead }: IRoomRequest): void { + client.leave(client.id); //verify-room에서 생성한 룸을 삭제합니다. 이제 사용될 일이 없어서.. client.join(roomId); - if (!this.userList[roomId]) this.userList[roomId] = {}; - this.userList[roomId][nickname] = { + if (!this.userList[roomId]) this.userList[roomId] = { list: {}, maxHead: maxHead }; + this.userList[roomId]['list'][nickname] = { field: field, img: img, }; - this.server.to(roomId).emit('user-list', this.userList[roomId]); + this.server.to(roomId).emit('user-list', this.userList[roomId]['list']); } @SubscribeMessage('leave-room') handleLeaveRoom(client: Socket, { nickname, roomId }: IRoomRequest): void { client.leave(roomId); - delete this.userList[roomId][nickname]; - this.server.to(roomId).emit('user-list', this.userList[roomId]); + delete this.userList[roomId]['list'][nickname]; + this.server.to(roomId).emit('user-list', this.userList[roomId]['list']); } @SubscribeMessage('kick-room') handleKickRoom(client: Socket, { roomId, kickNickname }: IRoomRequest): void { if (!kickNickname) return; - delete this.userList[roomId][kickNickname]; - this.server.to(roomId).emit('user-list', this.userList[roomId]); + delete this.userList[roomId]['list'][kickNickname]; + this.server.to(roomId).emit('user-list', this.userList[roomId]['list']); + } + + @SubscribeMessage('verify-room') + handleVerifyRoom(client: Socket, { roomId }: IRoomRequest): void { + client.join(client.id); //해당 사용자한테만 전송될 수 있게 + if (!this.userList[roomId]) { + this.server.to(client.id).emit('is-verify', true); + return; + } + if (Object.keys(this.userList[roomId]['list']).length < this.userList[roomId]['maxHead']) { + this.server.to(client.id).emit('is-verify', true); + return; + } + + this.server.to(client.id).emit('is-verify', false); } afterInit(server: Server) { diff --git a/server/socket/src/gateway/room.interface.ts b/server/socket/src/gateway/room.interface.ts index 4c5ee3fc..6cd938f8 100644 --- a/server/socket/src/gateway/room.interface.ts +++ b/server/socket/src/gateway/room.interface.ts @@ -6,6 +6,7 @@ export interface IRoomRequest { kickNickname?: string; field?: string; img?: string; + maxHead: number; } export enum MessageType {