Skip to content

Commit

Permalink
Bug/#242 - 커밋되지 않는 상수 추가 (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
xjfcnfw3 authored Nov 25, 2024
2 parents e82a6dd + 44bb8ec commit 46a9b28
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
61 changes: 30 additions & 31 deletions packages/backend/src/stock/stock.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ export class StockService {
}

async searchStock(stockName: string) {
const queryBuilder = this.datasource
const result = await this.datasource
.getRepository(Stock)
.createQueryBuilder();
const result = await queryBuilder
.where('stock.stock_name LIKE :name', {
.createQueryBuilder('stock')
.where('stock.is_trading = :isTrading and stock.stock_name LIKE :name', {
isTrading: true,
name: `%${stockName}%`,
})
Expand All @@ -94,6 +93,33 @@ export class StockService {
}
}

async getTopStocksByViews(limit: number) {
const rawData = await this.StocksQuery()
.orderBy('stock.views', 'DESC')
.limit(limit)
.getRawMany();

return plainToInstance(StocksResponse, rawData);
}

async getTopStocksByGainers(limit: number) {
const rawData = await this.StocksQuery()
.orderBy('stockLiveData.changeRate', 'DESC')
.limit(limit)
.getRawMany();

return plainToInstance(StocksResponse, rawData);
}

async getTopStocksByLosers(limit: number) {
const rawData = await this.StocksQuery()
.orderBy('stockLiveData.changeRate', 'ASC')
.limit(limit)
.getRawMany();

return plainToInstance(StocksResponse, rawData);
}

private async validateStockExists(stockId: string, manager: EntityManager) {
if (!(await this.existsStock(stockId, manager))) {
throw new BadRequestException('not exists stock');
Expand Down Expand Up @@ -150,31 +176,4 @@ export class StockService {
'stockDetail.marketCap AS marketCap',
]);
}

async getTopStocksByViews(limit: number) {
const rawData = await this.StocksQuery()
.orderBy('stock.views', 'DESC')
.limit(limit)
.getRawMany();

return plainToInstance(StocksResponse, rawData);
}

async getTopStocksByGainers(limit: number) {
const rawData = await this.StocksQuery()
.orderBy('stockLiveData.changeRate', 'DESC')
.limit(limit)
.getRawMany();

return plainToInstance(StocksResponse, rawData);
}

async getTopStocksByLosers(limit: number) {
const rawData = await this.StocksQuery()
.orderBy('stockLiveData.changeRate', 'ASC')
.limit(limit)
.getRawMany();

return plainToInstance(StocksResponse, rawData);
}
}
16 changes: 16 additions & 0 deletions packages/backend/src/user/constants/randomNickname.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
export const status = [
'신중한',
'과감한',
'공부하는',
'성장하는',
'주춤거리는',
];
export const subject = [
'병아리',
'햄스터',
'다람쥐',
'거북이',
'판다',
'주린이',
'투자자',
];

0 comments on commit 46a9b28

Please sign in to comment.