Skip to content

Commit

Permalink
Merge pull request #6 from boostcampwm-2024/tradelogic
Browse files Browse the repository at this point in the history
트랜잭션 범위 축소 및 커넥션 풀 제한 증가
  • Loading branch information
SeongHyeon0409 authored Jan 22, 2025
2 parents 29ee20d + d0c6c08 commit c429ae9
Show file tree
Hide file tree
Showing 30 changed files with 1,949 additions and 275 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/CICD.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ name: Build and Deploy

on:
push:
branches:
- dev
- dev-be
# branches:
# - dev
# - dev-be
jobs:
build_and_deploy:
runs-on: ubuntu-latest
Expand Down
20 changes: 12 additions & 8 deletions packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,19 +92,23 @@
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
"js",
"json",
"ts"
],
"rootDir": "src",
"rootDir": "test",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
}
"testEnvironment": "node",
"moduleNameMapper": {
"^@src/(.*)$": "<rootDir>/../src/$1",
"^src/(.*)$": "<rootDir>/../src/$1"
}
}
}
3 changes: 2 additions & 1 deletion packages/server/src/account/account.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module, forwardRef } from '@nestjs/common';
import { Logger, Module, forwardRef } from '@nestjs/common';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Account } from './account.entity';
import { AccountRepository } from './account.repository';
Expand All @@ -18,6 +18,7 @@ import { CoinListService } from '@src/upbit/coin-list.service';
AssetRepository,
AssetService,
CoinListService,
Logger
],
})
export class AccountModule {}
71 changes: 59 additions & 12 deletions packages/server/src/account/account.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,36 @@ export class AccountRepository extends Repository<Account> {
throw error;
}
}

async updateAccountCurrencyWithBid(
typeGiven: string,
change: number,
availableBalance: number,
accountId: number,
){
this.logger.log(
`계정 통화 업데이트 시작: accountId=${accountId}, type=${typeGiven}`,
);
try {
await this
.createQueryBuilder()
.update(Account)
.set({
// 직접 연산 처리: ()로 감싸 동적 SQL 계산
[typeGiven]: () => `${typeGiven} + ${change}`,
availableKRW: () => `availableKRW + ${availableBalance}`,
})
.where('id = :id', { id: accountId })
.execute();
this.logger.log(`계정 통화 업데이트 완료: accountId=${accountId}`);
} catch (error) {
this.logger.error(
`계정 통화 업데이트 실패: ${error.message}`,
error.stack,
);
throw error;
}
}
async updateAccountAvailableCurrency(
change: number,
accountId: number,
Expand Down Expand Up @@ -157,21 +187,23 @@ export class AccountRepository extends Repository<Account> {
}
}

async validateUserAccount(userId: number): Promise<Account> {
this.logger.log(`사용자 계정 검증 시작: userId=${userId}`);
const userAccount = await this.findOne({
where: { user: { id: userId } },
});

if (!userAccount) {
this.logger.warn(`존재하지 않는 사용자 계정: userId=${userId}`);
throw new UnprocessableEntityException('유저가 존재하지 않습니다.');
async validateUserAccount(userId: number, queryRunner): Promise<Account> {
try{
this.logger.log(`사용자 계정 검증 시작: userId=${userId}`);
const userAccount = await queryRunner.manager.findOne(Account, {
where: { user: { id: userId } },
});
if (!userAccount) {
this.logger.warn(`존재하지 않는 사용자 계정: userId=${userId}`);
throw new UnprocessableEntityException('유저가 존재하지 않습니다.');
}
return userAccount;
} catch (error) {
this.logger.error(`계좌 조회 실패: ${error.message}`, error.stack);
}

return userAccount;
}

async getAccount(id: number, queryRunner: QueryRunner): Promise<Account> {
async getAccountWithQueryRunner(id: number, queryRunner: QueryRunner): Promise<Account> {
this.logger.log(`계정 조회 시작: userId=${id}`);
try {
const account = await queryRunner.manager.findOne(Account, {
Expand All @@ -185,4 +217,19 @@ export class AccountRepository extends Repository<Account> {
throw error;
}
}

async getAccount(id: number): Promise<Account> {
this.logger.log(`계정 조회 시작: userId=${id}`);
try {
const account = await this.findOne({
where: { user: { id } },
});

this.logger.log(`계정 조회 완료: userId=${id}`);
return account;
} catch (error) {
this.logger.error(`계정 조회 실패: ${error.message}`, error.stack);
throw error;
}
}
}
22 changes: 0 additions & 22 deletions packages/server/src/app.controller.spec.ts

This file was deleted.

3 changes: 2 additions & 1 deletion packages/server/src/asset/asset.module.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Module } from '@nestjs/common';
import { Logger, Module } from '@nestjs/common';
import { AssetService } from './asset.service';
import { AssetRepository } from './asset.repository';
import { TypeOrmModule } from '@nestjs/typeorm';
Expand All @@ -11,6 +11,7 @@ import { HttpModule } from '@nestjs/axios';
providers: [
AssetService,
AssetRepository,
Logger
],
exports: [AssetRepository],
})
Expand Down
Loading

0 comments on commit c429ae9

Please sign in to comment.