-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from PBTP/feature/chat
DMVM-177 feature: 채팅
- Loading branch information
Showing
65 changed files
with
1,715 additions
and
269 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,19 @@ | ||
import { CustomerDto } from 'src/customer/presentation/customer.dto'; | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsOptional } from 'class-validator'; | ||
import { UserDto } from './user.dto'; | ||
|
||
export class AuthDto extends CustomerDto { | ||
export class AuthDto extends UserDto { | ||
@ApiProperty({ | ||
description: 'Access Token', | ||
type: String, | ||
}) | ||
accessToken: string; | ||
@IsOptional() | ||
accessToken?: string; | ||
|
||
@ApiProperty({ | ||
description: 'Refresh Token', | ||
type: String, | ||
}) | ||
@IsOptional() | ||
refreshToken: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IsNotEmpty, IsOptional } from 'class-validator'; | ||
import { Group } from '../../common/validation/validation.data'; | ||
|
||
export class UserDto { | ||
@IsNotEmpty({ groups: [Group.create] }) | ||
@IsOptional() | ||
userType?: UserType; | ||
|
||
@IsNotEmpty({ groups: [Group.create] }) | ||
@IsOptional() | ||
userId?: number; | ||
uuid?: string; | ||
name?: string; | ||
} | ||
|
||
// 고객, 업체, 기사 공통 사용 DTO | ||
export type UserType = 'customer' | 'driver' | 'business'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { UserDto } from './presentation/user.dto'; | ||
|
||
export interface IUserService { | ||
findOne(dto: Partial<UserDto>): Promise<UserDto>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { IUserService } from '../../auth/user.interface'; | ||
import { UserDto } from '../../auth/presentation/user.dto'; | ||
import { Business } from '../../schemas/business.entity'; | ||
|
||
@Injectable() | ||
export class BusinessService implements IUserService { | ||
constructor( | ||
@InjectRepository(Business) | ||
private readonly businessRepository: Repository<Business>, | ||
) {} | ||
|
||
async signUp(dto: Business): Promise<Business> { | ||
const newDriver = this.businessRepository.create(dto); | ||
return await this.businessRepository.save(newDriver); | ||
} | ||
|
||
async findOne(dto: Partial<UserDto>): Promise<Business> { | ||
const where = {}; | ||
|
||
dto.userId && (where['driverId'] = dto.userId); | ||
dto.uuid && (where['uuid'] = dto.uuid); | ||
|
||
return await this.businessRepository.findOne({ | ||
where: where, | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { BusinessService } from './application/business.service'; | ||
import { Business } from '../schemas/business.entity'; | ||
|
||
@Module({ | ||
imports: [TypeOrmModule.forFeature([Business])], | ||
exports: [BusinessService], | ||
providers: [BusinessService], | ||
}) | ||
export class BusinessModule {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Repository } from 'typeorm'; | ||
import { BusinessChatRoom } from '../../schemas/business-chat-room.entity'; | ||
import { IChatService } from './chat.interface'; | ||
import { UserDto } from '../../auth/presentation/user.dto'; | ||
import { plainToInstance as toDto } from 'class-transformer'; | ||
import { ChatRoomDto } from '../presentation/chat.dto'; | ||
|
||
@Injectable() | ||
export class BusinessChatService implements IChatService { | ||
private readonly logger = new Logger(BusinessChatService.name); | ||
|
||
constructor( | ||
@InjectRepository(BusinessChatRoom) | ||
private readonly businessChatRoomRepository: Repository<BusinessChatRoom>, | ||
) {} | ||
|
||
async exitsUserRoom(user: UserDto, chatRoomId: number): Promise<boolean> { | ||
return await this.businessChatRoomRepository.exists({ | ||
where: { businessId: user.userId, chatRoomId }, | ||
}); | ||
} | ||
|
||
async findChatRooms(user: UserDto): Promise<ChatRoomDto[]> { | ||
const businessChatRooms = await this.businessChatRoomRepository.find({ | ||
where: { businessId: user.userId }, | ||
}); | ||
|
||
return await Promise.all( | ||
businessChatRooms.map((room) => room.chatRoom), | ||
).then((rooms) => { | ||
return rooms.map((room) => { | ||
return toDto(ChatRoomDto, room); | ||
}); | ||
}); | ||
} | ||
|
||
async getChatRoomById( | ||
businessId: number, | ||
chatRoomId: number, | ||
): Promise<BusinessChatRoom> { | ||
return await this.businessChatRoomRepository.findOne({ | ||
where: { businessId, chatRoomId }, | ||
}); | ||
} | ||
|
||
async createChatRoom(dto: ChatRoomDto): Promise<ChatRoomDto> { | ||
const newRoom = this.businessChatRoomRepository.create({ | ||
chatRoomId: dto.chatRoomId, | ||
businessId: dto.inviteUser.userId, | ||
}); | ||
|
||
return await this.businessChatRoomRepository.save(newRoom).then((room) => { | ||
this.logger.log(`Business Chat room created: ${room.chatRoomId}`); | ||
return toDto(ChatRoomDto, room.chatRoom); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { UserDto } from '../../auth/presentation/user.dto'; | ||
import { ChatRoomDto } from '../presentation/chat.dto'; | ||
|
||
export interface IChatService { | ||
exitsUserRoom(user: UserDto, chatRoomId: number): Promise<boolean>; | ||
findChatRooms(user: UserDto): Promise<ChatRoomDto[]>; | ||
createChatRoom(chatRoomDto: ChatRoomDto): Promise<ChatRoomDto>; | ||
} |
Oops, something went wrong.