Skip to content

Commit

Permalink
Merge branch 'dev' into front/main
Browse files Browse the repository at this point in the history
  • Loading branch information
dannysir authored Nov 28, 2024
2 parents 576c292 + 3fe9d95 commit 5710b6a
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 4 deletions.
6 changes: 6 additions & 0 deletions BE/src/auth/dto/rename-user.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { ApiProperty } from '@nestjs/swagger';

export class RenameUserDto {
@ApiProperty({ description: '변경할 닉네임' })
nickname: string;
}
20 changes: 19 additions & 1 deletion BE/src/auth/user.controller.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { Controller, Get, Req, UseGuards } from '@nestjs/common';
import { Body, Controller, Get, Patch, Req, UseGuards } from '@nestjs/common';
import { Request } from 'express';
import {
ApiBearerAuth,
ApiBody,
ApiOperation,
ApiResponse,
ApiTags,
} from '@nestjs/swagger';
import { UserService } from './user.service';
import { JwtAuthGuard } from './jwt-auth-guard';
import { ProfileResponseDto } from './dto/profile-response.dto';
import { RenameUserDto } from './dto/rename-user.dto';

@Controller('/api/user')
@ApiTags('프로필 API')
Expand All @@ -27,4 +29,20 @@ export class UserController {
getProfile(@Req() request: Request) {
return this.userService.getProfile(parseInt(request.user.userId, 10));
}

@Patch('/rename')
@UseGuards(JwtAuthGuard)
@ApiOperation({
summary: '유저 닉네임 변경 API',
})
@ApiBody({
type: RenameUserDto,
})
@ApiBearerAuth()
renameUser(@Req() request: Request, @Body() body: RenameUserDto) {
const userId = parseInt(request.user.userId, 10);
const newName = body.nickname;

return this.userService.renameUser(userId, newName);
}
}
8 changes: 8 additions & 0 deletions BE/src/auth/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class UserRepository extends Repository<User> {
const hashedPassword: string = await bcrypt.hash(password, salt);
const user = this.create({ email, password: hashedPassword });
await queryRunner.manager.save(user);

user.nickname = `익명의 투자자${user.id}`;
await queryRunner.manager.save(user);

const asset = this.assetRepository.create({ user_id: user.id });
await queryRunner.manager.save(asset);

Expand All @@ -52,6 +56,10 @@ export class UserRepository extends Repository<User> {
password: hashedPassword,
});
await this.save(user);

user.nickname = `익명의 투자자${user.id}`;
await queryRunner.manager.save(user);

const asset = this.assetRepository.create({ user_id: user.id });
await queryRunner.manager.save(asset);

Expand Down
38 changes: 37 additions & 1 deletion BE/src/auth/user.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
import { Injectable } from '@nestjs/common';
import {
BadRequestException,
Injectable,
NotFoundException,
} from '@nestjs/common';
import { UserRepository } from './user.repository';
import { ProfileResponseDto } from './dto/profile-response.dto';

Expand All @@ -10,4 +14,36 @@ export class UserService {
const user = await this.userRepository.findOneBy({ id: userId });
return new ProfileResponseDto(user.nickname, user.email);
}

async renameUser(userId: number, newName: string) {
const user = await this.userRepository.findOneBy({ id: userId });
if (!user) {
throw new NotFoundException('존재하지 않는 유저입니다.');
}

this.validateName(newName);
await this.checkNameDuplicate(newName);

return this.userRepository.update({ id: userId }, { nickname: newName });
}

private validateName(nickname: string) {
const regex = /^[-a-zA-Z0-9]+$/;
if (!regex.test(nickname)) {
throw new BadRequestException('한글, 영문, 숫자만 사용 가능합니다.');
}

if (nickname.includes('익명의투자자')) {
throw new BadRequestException('사용 불가능한 단어가 포함되어 있습니다.');
}
}

private async checkNameDuplicate(nickname: string) {
const isDuplicated = await this.userRepository.existsBy({
nickname,
});
if (isDuplicated) {
throw new BadRequestException('이미 존재하는 닉네임입니다.');
}
}
}
2 changes: 1 addition & 1 deletion BE/src/ranking/ranking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export class RankingService {
};
}

@Cron('*/1 * * * 1-5')
@Cron('0 16 * * 1-5')
async updateRanking() {
const [profitRateRanking, assetRanking] = await Promise.all([
this.calculateRanking(SortType.PROFIT_RATE),
Expand Down
2 changes: 1 addition & 1 deletion BE/src/stockSocket/stock-execute-order.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export class StockExecuteOrderRepository extends Repository<Order> {

async checkExecutableOrder(stockCode, value) {
const queryRunner = this.dataSource.createQueryRunner();
await queryRunner.startTransaction();
await queryRunner.startTransaction('SERIALIZABLE');

try {
const buyOrders = await queryRunner.manager.find(Order, {
Expand Down
3 changes: 3 additions & 0 deletions FE/src/utils/chart/drawUpperYAxis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export const drawUpperYAxis = (
) => {
const values = data
.map((d) => {

if (d.mov_avg_20 && d.mov_avg_5) {
return [
+d.stck_hgpr,
Expand All @@ -25,6 +26,7 @@ export const drawUpperYAxis = (
Math.floor(+d.mov_avg_5),
Math.floor(+d.mov_avg_20),
];

} else if (d.mov_avg_5) {
return [
+d.stck_hgpr,
Expand All @@ -33,6 +35,7 @@ export const drawUpperYAxis = (
+d.stck_oprc,
Math.floor(+d.mov_avg_5),
];

} else if (d.mov_avg_20) {
return [
+d.stck_hgpr,
Expand Down

0 comments on commit 5710b6a

Please sign in to comment.