Skip to content
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: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import S3Module from './providers/storage/s3/s3.module';
import PointLogModule from './modules/pointLog/pointLog.module';
import { LoggerModule } from './common/logger/winston/logger.module';
import TransactionModule from './providers/database/transaction/transaction.module';
import ProfileModule from './modules/profile/profile.module';

@Module({
imports: [
Expand All @@ -39,6 +40,7 @@ import TransactionModule from './providers/database/transaction/transaction.modu
PrismaModule,
AuthModule,
UserModule,
ProfileModule,
NotificationModule,
FollowModule,
PlanModule,
Expand Down
10 changes: 5 additions & 5 deletions src/modules/auth/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export default class AuthController {
const { accessToken, refreshToken } = this.service.createTokens(tokenPayload);

res.cookie('refreshToken', refreshToken, {
path: '/user/token/refresh',
path: '/auth/refresh/token',
httpOnly: true,
sameSite: 'lax',
secure: true,
Expand Down Expand Up @@ -80,7 +80,7 @@ export default class AuthController {

// 기존 회원의 경우 토큰 반환
res.cookie('refreshToken', tokens.refreshToken, {
path: '/user/token/refresh',
path: '/auth/refresh/token',
httpOnly: true,
sameSite: 'lax',
secure: true,
Expand Down Expand Up @@ -108,7 +108,7 @@ export default class AuthController {
}

res.cookie('refreshToken', tokens.refreshToken, {
path: '/user/token/refresh',
path: '/auth/refresh/token',
httpOnly: true,
sameSite: 'lax',
secure: true,
Expand Down Expand Up @@ -138,7 +138,7 @@ export default class AuthController {
}

res.cookie('refreshToken', tokens.refreshToken, {
path: '/user/token/refresh',
path: '/auth/refresh/token',
httpOnly: true,
sameSite: 'lax',
secure: true,
Expand All @@ -162,7 +162,7 @@ export default class AuthController {
const { accessToken, refreshToken: newRefreshToken } = this.service.createNewToken(refreshToken);

res.cookie('refreshToken', newRefreshToken, {
path: '/user/token/refresh',
path: '/auth/refresh/token',
httpOnly: true,
sameSite: 'lax',
secure: true,
Expand Down
2 changes: 2 additions & 0 deletions src/modules/auth/auth.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ import { GoogleStrategy } from './strategy/google.strategy';
import AuthController from './auth.controller';
import { KakaoStrategy } from './strategy/kakao.strategy';
import { NaverStrategy } from './strategy/naver.strategy';
import ProfileModule from '../profile/profile.module';

@Module({
imports: [
PassportModule,
JwtModule.register({
secret: process.env.JWT_SECRET
}),
ProfileModule,
UserStatsModule
],
controllers: [AuthController],
Expand Down
32 changes: 0 additions & 32 deletions src/modules/auth/auth.repository.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Injectable } from '@nestjs/common';
import { IDreamerProfile, IMakerProfile } from 'src/modules/user/domain/profile.interface';
import { DreamerProfileMapper, MakerProfileMapper } from 'src/modules/user/domain/profile.mapper';
import { IUser } from 'src/modules/user/domain/user.interface';
import UserMapper from 'src/modules/user/domain/user.mapper';
import { DreamerProfileProperties, MakerProfileProperties } from 'src/modules/user/types/profile.types';
import { OAuthProperties, SignupProperties } from 'src/modules/user/types/user.types';
import DBClient from 'src/providers/database/prisma/DB.client';

Expand Down Expand Up @@ -40,33 +37,4 @@ export default class AuthRepository {

return new UserMapper(data).toDomain();
}

async createDreamer(user: Partial<DreamerProfileProperties>): Promise<IDreamerProfile> {
const profile = await this.db.dreamerProfile.create({
data: {
user: { connect: { id: user.userId } },
tripTypes: user.tripTypes,
serviceArea: user.serviceArea,
image: user.image
}
});

return new DreamerProfileMapper(profile).toDomain();
}

async createMaker(user: Partial<MakerProfileProperties>): Promise<IMakerProfile> {
const profile = await this.db.makerProfile.create({
data: {
user: { connect: { id: user.userId } },
serviceArea: user.serviceArea,
serviceTypes: user.serviceTypes,
gallery: user.gallery,
description: user.description,
detailDescription: user.detailDescription,
image: user.image
}
});

return new MakerProfileMapper(profile).toDomain();
}
}
15 changes: 5 additions & 10 deletions src/modules/auth/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,22 @@ import BadRequestError from 'src/common/errors/badRequestError';
import { JwtService } from '@nestjs/jwt';
import { Injectable } from '@nestjs/common';
import User from 'src/modules/user/domain/user.domain';
import { DreamerProfile, MakerProfile } from 'src/modules/user/domain/profile.domain';
import { DreamerProfile, MakerProfile } from 'src/modules/profile/domain/profile.domain';
import UserStatsService from '../userStats/userStats.service';
import { FilteredUserProperties, OAuthProperties, UserProperties } from 'src/modules/user/types/user.types';
import AuthRepository from './auth.repository';
import { Role, RoleValues } from 'src/common/constants/role.type';
import { DreamerProfileProperties, MakerProfileProperties } from 'src/modules/user/types/profile.types';
import { DreamerProfileProperties, MakerProfileProperties } from 'src/modules/profile/types/profile.types';
import { OAuthProvider } from 'src/common/constants/oauth.type';
import UnauthorizedError from 'src/common/errors/unauthorizedError';
import ProfileService from '../profile/profile.service';

@Injectable()
export default class AuthService {
constructor(
private readonly repository: AuthRepository,
private readonly jwt: JwtService,
private readonly profile: ProfileService,
private readonly userStats: UserStatsService
) {}

Expand Down Expand Up @@ -44,14 +46,7 @@ export default class AuthService {
const userData = await User.create(user);
const savedUser = await this.repository.create(userData.signupData());

// 역할에 따라 프로필 등록
if (savedUser.getRole() === RoleValues.DREAMER) {
const profileData = DreamerProfile.create({ ...profile, userId: savedUser.getId() });
await this.repository.createDreamer(profileData);
} else {
const profileData = MakerProfile.create({ ...profile, userId: savedUser.getId() });
await this.repository.createMaker(profileData.get());
}
await this.profile.createProfile(savedUser.getId(), savedUser.getRole(), profile);

// 유저 생성시 기본값으로 UserStats 생성
await this.userStats.create(savedUser.getId(), {});
Expand Down
4 changes: 3 additions & 1 deletion src/modules/chatRoom/chatRoom.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import ChatModule from '../chat/chat.module';
import ChatRoomGateway from './chatRoom.gateway';
import WebSocketJwtGuard from 'src/common/guards/webSocket.guard';
import UserModule from '../user/user.module';
import ProfileModule from '../profile/profile.module';

@Module({
imports: [
Expand All @@ -17,7 +18,8 @@ import UserModule from '../user/user.module';
}),
MongooseModule.forFeature([{ name: ChatRoom.name, schema: ChatRoomSchema }]),
ChatModule,
UserModule
UserModule,
ProfileModule
],
controllers: [ChatRoomController],

Expand Down
4 changes: 3 additions & 1 deletion src/modules/chatRoom/chatRoom.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { ChatReference, FileUploadData, FindChatRoomByIdOptions } from 'src/modu
import NotFoundError from 'src/common/errors/notFoundError';
import IChatRoom from './domain/chatRoom.interface';
import BadRequestError from 'src/common/errors/badRequestError';
import ProfileService from '../profile/profile.service';
import TransactionManager from 'src/providers/database/transaction/transaction.manager';
import Transactional from 'src/common/decorators/transaction.decorator';

Expand All @@ -23,6 +24,7 @@ export default class ChatRoomService {
private readonly repository: ChatRoomRepository,
private readonly chatService: ChatService,
private readonly userService: UserService,
private readonly profileService: ProfileService,
private readonly transactionManager: TransactionManager
) {}

Expand Down Expand Up @@ -153,7 +155,7 @@ export default class ChatRoomService {
const users = await Promise.all(
userIds?.map(async (userId) => {
const userData = await this.userService.getUser(userId);
const userProfile = await this.userService.getProfile(userData.role, userId);
const userProfile = await this.profileService.getProfile(userData.role, userId);

const user = {
id: userId,
Expand Down
3 changes: 2 additions & 1 deletion src/modules/plan/plan.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import PlanRepository from './plan.repository';
import PlanService from './plan.service';
import ChatRoomModule from '../chatRoom/chatRoom.module';
import { BullModule } from '@nestjs/bullmq';
import ProfileModule from '../profile/profile.module';

@Module({
imports: [BullModule.registerQueue({ name: 'points' }), UserModule, QuoteModule, ChatRoomModule],
imports: [BullModule.registerQueue({ name: 'points' }), UserModule, ProfileModule, QuoteModule, ChatRoomModule],
controllers: [PlanController],
providers: [PlanRepository, PlanService],
exports: [PlanRepository, PlanService]
Expand Down
6 changes: 4 additions & 2 deletions src/modules/plan/plan.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Queue } from 'bullmq';
import { PointEventEnum } from 'src/common/constants/pointEvent.type';
import TransactionManager from 'src/providers/database/transaction/transaction.manager';
import Transactional from 'src/common/decorators/transaction.decorator';
import ProfileService from '../profile/profile.service';

@Injectable()
export default class PlanService {
Expand All @@ -32,6 +33,7 @@ export default class PlanService {
private readonly repository: PlanRepository,
private readonly quoteService: QuoteService,
private readonly userService: UserService,
private readonly profileService: ProfileService,
private readonly chatRoomService: ChatRoomService,
private readonly transactionManager: TransactionManager,
private readonly eventEmitter: EventEmitter2
Expand All @@ -54,7 +56,7 @@ export default class PlanService {
userId: string,
options: PlanQueryOptions
): Promise<{ totalCount: number; groupByCount: GroupByCount; list: PlanToClientProperties[] }> {
const makerProfile = await this.userService.getProfile(RoleValues.MAKER, userId);
const makerProfile = await this.profileService.getProfile(RoleValues.MAKER, userId);
const serviceArea: ServiceArea[] = options.isAssigned === true ? undefined : makerProfile.serviceArea;

options.serviceArea = serviceArea; //NOTE. 메이커의 서비스지역 필터링
Expand Down Expand Up @@ -181,7 +183,7 @@ export default class PlanService {
throw new BadRequestError(ErrorMessage.PLAN_ASSIGN_NOT_MAKER);
}

const assigneeServiceArea = (await this.userService.getProfile(RoleValues.MAKER, assigneeId)).serviceArea;
const assigneeServiceArea = (await this.profileService.getProfile(RoleValues.MAKER, assigneeId)).serviceArea;
if (!assigneeServiceArea.includes(plan.getServiceArea())) {
throw new BadRequestError(ErrorMessage.PLAN_MAKER_NOT_IN_SERVICE_AREA);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DreamerProfileProperties, MakerProfileProperties } from 'src/modules/user/types/profile.types';
import { DreamerProfileProperties, MakerProfileProperties } from 'src/modules/profile/types/profile.types';

export interface IDreamerProfile {
update(data: Partial<DreamerProfileProperties>): DreamerProfileProperties;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DreamerProfileProperties, MakerProfileProperties } from '../types/profile.types';
import { DreamerProfile, MakerProfile } from './profile.domain';
import { DreamerProfile, MakerProfile } from '../../profile/domain/profile.domain';

export class DreamerProfileMapper {
constructor(private readonly dreamer: DreamerProfileProperties) {}
Expand All @@ -21,6 +21,7 @@ export class MakerProfileMapper {
constructor(private readonly maker: MakerProfileProperties) {}

toDomain() {
if (!this.maker) return null;
return new MakerProfile({
userId: this.maker.userId,
image: this.maker.image,
Expand Down
49 changes: 49 additions & 0 deletions src/modules/profile/profile.controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { Body, Controller, Get, Patch } from '@nestjs/common';
import ProfileService from './profile.service';
import {
ApiBearerAuth,
ApiBody,
ApiOkResponse,
ApiOperation,
ApiResponse,
ApiUnauthorizedResponse
} from '@nestjs/swagger';
import { DreamerProfileResponseDTO, MakerProfileResponseDTO } from '../user/types/user.response.dto';
import { UserRole } from 'src/common/decorators/role.decorator';
import { UserId } from 'src/common/decorators/user.decorator';
import { DreamerProfileProperties, MakerProfileProperties } from './types/profile.types';
import UpdateProfileDTO from './types/updateProfile.dto';

@Controller('profile')
export default class ProfileController {
constructor(private readonly service: ProfileService) {}

@Get()
@ApiBearerAuth('accessToken')
@ApiOperation({ summary: '프로필 정보 조회', description: '로그인한 유저의 프로필을 조회합니다' })
@ApiOkResponse({ type: MakerProfileResponseDTO || DreamerProfileResponseDTO })
@ApiUnauthorizedResponse({ description: 'Access Token이 없거나 만료되었습니다' })
async getProfile(
@UserRole() role: string,
@UserId() userId: string
): Promise<MakerProfileProperties | DreamerProfileProperties> {
return await this.service.getProfile(role, userId);
}

@Patch('update')
@ApiBearerAuth('accessToken')
@ApiOperation({ summary: '프로필 수정', description: '로그인한 유저의 프로필을 수정합니다' })
@ApiBody({ type: UpdateProfileDTO })
@ApiResponse({ type: MakerProfileResponseDTO || DreamerProfileResponseDTO })
@ApiUnauthorizedResponse({ description: 'Access Token이 없거나 만료되었습니다' })
async updateProfile(
@UserRole() role: string,
@Body() data: Partial<MakerProfileProperties | DreamerProfileProperties>,
@UserId() userId: string
) {
if (role === 'DREAMER') {
return await this.service.updateDreamerProfile(userId, data);
}
return await this.service.updateMakerProfile(userId, data);
}
}
Comment on lines +43 to +49
Copy link
Contributor

Choose a reason for hiding this comment

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

Dreamer 하드코딩되어있어요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

앗, 예전 코드 그대로 가져오다보니 ㅠㅠ 수정해서 올릴게요~

12 changes: 12 additions & 0 deletions src/modules/profile/profile.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Module } from '@nestjs/common';
import ProfileController from './profile.controller';
import ProfileService from './profile.service';
import ProfileRepository from './profile.repository';

@Module({
imports: [],
controllers: [ProfileController],
providers: [ProfileService, ProfileRepository],
exports: [ProfileService]
})
export default class ProfileModule {}
Loading