Skip to content

Commit

Permalink
Fix/endpoint api 엔드포인트로 변경, bigint -> decimal로 변경 (#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
swkim12345 authored Nov 18, 2024
2 parents 9bf2e46 + 1d27504 commit 12126c9
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 14 deletions.
6 changes: 3 additions & 3 deletions packages/backend/src/app.module.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { ScheduleModule } from '@nestjs/schedule';
import { TypeOrmModule } from '@nestjs/typeorm';
import { WinstonModule } from 'nest-winston';
import { ScraperModule } from './scraper/scraper.module';
import { AuthModule } from '@/auth/auth.module';
import { SessionModule } from '@/auth/session.module';
import { ChatModule } from '@/chat/chat.module';
Expand All @@ -11,9 +14,6 @@ import {
import { logger } from '@/configs/logger.config';
import { StockModule } from '@/stock/stock.module';
import { UserModule } from '@/user/user.module';
import { ScraperModule } from './scraper/scraper.module';
import { ScheduleModule } from '@nestjs/schedule';
import { ConfigModule } from '@nestjs/config';

@Module({
imports: [
Expand Down
2 changes: 2 additions & 0 deletions packages/backend/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { useSwagger } from '@/configs/swagger.config';
async function bootstrap() {
const app = await NestFactory.create(AppModule);
const store = app.get(MEMORY_STORE);

app.setGlobalPrefix('api');
app.use(session({ ...sessionConfig, store }));
app.useGlobalPipes(new ValidationPipe({ transform: true }));
useSwagger(app);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ import {
import { openApiToken } from './openapiToken.api';
import { Stock } from '@/stock/domain/stock.entity';
import { StockData, StockMinutely } from '@/stock/domain/stockData.entity';
import { Injectable } from '@nestjs/common';

@Injectable()
export class OpenapiMinuteData {
private stock: Stock[];
private readonly entity = StockMinutely;
Expand All @@ -37,7 +39,7 @@ export class OpenapiMinuteData {
stockPeriod.open = parseInt(item.stck_oprc);
stockPeriod.high = parseInt(item.stck_hgpr);
stockPeriod.low = parseInt(item.stck_lwpr);
stockPeriod.volume = BigInt(item.cntg_vol);
stockPeriod.volume = parseInt(item.cntg_vol);
stockPeriod.createdAt = new Date();
return stockPeriod;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
StockMonthly,
StockYearly,
} from '@/stock/domain/stockData.entity';
import { Injectable } from '@nestjs/common';

const DATE_TO_ENTITY = {
D: StockDaily,
Expand All @@ -33,11 +34,12 @@ const DATE_TO_MONTH = {

const INTERVALS = 4000;

@Injectable()
export class OpenapiPeriodData {
private readonly url: string =
'/uapi/domestic-stock/v1/quotations/inquire-daily-itemchartprice';
public constructor(private readonly datasourse: DataSource) {
//this.getItemChartPriceCheck();
this.getItemChartPriceCheck();
}

@Cron('0 1 * * 1-5')
Expand Down Expand Up @@ -174,7 +176,7 @@ export class OpenapiPeriodData {
stockPeriod.open = parseInt(item.stck_oprc);
stockPeriod.high = parseInt(item.stck_hgpr);
stockPeriod.low = parseInt(item.stck_lwpr);
stockPeriod.volume = BigInt(item.acml_vol);
stockPeriod.volume = parseInt(item.acml_vol);
stockPeriod.createdAt = new Date();
await this.insertChartData(stockPeriod, entity);
}
Expand Down
12 changes: 10 additions & 2 deletions packages/backend/src/scraper/openapi/openapi-scraper.module.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import { Module } from '@nestjs/common';
import { OpenapiMinuteData } from './api/openapiMinuteData.api';
import { OpenapiPeriodData } from './api/openapiPeriodData.api';
import { OpenapiScraperService } from './openapi-scraper.service';
import { DataSource } from 'typeorm';
import { TypeOrmModule } from '@nestjs/typeorm';
import { Stock } from '@/stock/domain/stock.entity';
import { StockDaily, StockMinutely, StockMonthly, StockWeekly, StockYearly } from '@/stock/domain/stockData.entity';
import { StockLiveData } from '@/stock/domain/stockLiveData.entity';
import { StockDetail } from '@/stock/domain/stockDetail.entity';

@Module({
imports: [],
imports: [TypeOrmModule.forFeature([Stock, StockMinutely , StockDaily, StockWeekly, StockMonthly, StockYearly, StockLiveData, StockDetail])],
controllers: [],
providers: [OpenapiScraperService],
providers: [OpenapiPeriodData, OpenapiMinuteData, OpenapiScraperService],
})
export class OpenapiScraperModule {}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Inject, Injectable } from '@nestjs/common';
import { Injectable } from '@nestjs/common';
import { DataSource } from 'typeorm';
import { Logger } from 'winston';
import { OpenapiMinuteData } from './api/openapiMinuteData.api';
import { OpenapiPeriodData } from './api/openapiPeriodData.api';

Expand All @@ -10,6 +9,5 @@ export class OpenapiScraperService {
private readonly datasourse: DataSource,
private readonly openapiPeriodData: OpenapiPeriodData,
private readonly openapiMinuteData: OpenapiMinuteData,
@Inject('winston') private readonly logger: Logger,
) {}
}
6 changes: 3 additions & 3 deletions packages/backend/src/stock/domain/stockData.entity.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { applyDecorators } from '@nestjs/common';
import {
Entity,
PrimaryGeneratedColumn,
Expand All @@ -8,7 +9,6 @@ import {
ColumnOptions,
} from 'typeorm';
import { Stock } from './stock.entity';
import { applyDecorators } from '@nestjs/common';

export const GenerateBigintColumn = (
options?: ColumnOptions,
Expand Down Expand Up @@ -43,8 +43,8 @@ export class StockData {
@Column({ type: 'decimal', precision: 15, scale: 2 })
open: number;

@GenerateBigintColumn()
volume: BigInt;
@Column({ type: 'decimal', precision: 15, scale: 2 })
volume: number;

@Column({ type: 'timestamp', name: 'start_time' })
startTime: Date;
Expand Down

0 comments on commit 12126c9

Please sign in to comment.