11import { Injectable } from '@nestjs/common' ;
22import { ConfigService } from '@nestjs/config' ;
33import axios from 'axios' ;
4+ import type { AxiosRequestConfig } from 'axios' ;
45import { TightshortsRepository } from './tightshorts.repository' ;
56import type { ITightshorts } from './interfaces/tightshorts.interface' ;
67import type { ITightshortsChart } from './interfaces/chart.interface' ;
@@ -20,8 +21,8 @@ export class TightshortsService {
2021 return this . tightshortsRepository . set ( stockTicker , data ) ;
2122 }
2223
23- async fetch ( stockTicker : string ) : Promise < ITightshorts > {
24- const config = {
24+ async fetch ( stockTicker : string ) : Promise < ITightshorts | null > {
25+ const config : AxiosRequestConfig < any > = {
2526 method : 'get' ,
2627 url : `${ this . configService . get (
2728 'SHORT_API_URL' ,
@@ -30,9 +31,15 @@ export class TightshortsService {
3031 token : this . configService . get ( 'SHORT_API_KEY' ) ,
3132 'Content-Type' : 'application/json' ,
3233 } ,
34+ validateStatus : ( status ) =>
35+ ( status >= 200 && status < 300 ) || status === 404 ,
3336 } ;
3437
35- const api = ( await axios ( config ) ) . data ;
38+ const response = await axios ( config ) ;
39+ if ( response . status === 404 ) {
40+ return null ;
41+ }
42+ const api = response . data ;
3643
3744 const currentShortVolume =
3845 ( ( api . volume [ 0 ] . shortVolume / api . volume [ 0 ] . totalVolume ) * 100 ) . toFixed (
0 commit comments