Skip to content

Commit

Permalink
fixes after review
Browse files Browse the repository at this point in the history
  • Loading branch information
cfaur09 committed Sep 20, 2024
1 parent effa663 commit 9c224c6
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
20 changes: 16 additions & 4 deletions src/endpoints/mex/mex.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,26 @@ export class MexController {

@Get('mex/tokens/prices/hourly/:identifier')
async getTokenPricesHourResolution(
@Param('identifier', new ParseTokenPipe) identifier: string): Promise<MexTokenChart[]> {
return await this.mexTokenChartsService.getTokenPricesHourResolution(identifier);
@Param('identifier', new ParseTokenPipe) identifier: string): Promise<MexTokenChart[] | undefined> {
const charts = await this.mexTokenChartsService.getTokenPricesHourResolution(identifier);

if(!charts){
throw new NotFoundException('Token not found');
}

return charts;
}

@Get('mex/tokens/prices/daily/:identifier')
async getTokenPricesDayResolution(
@Param('identifier',new ParseTokenPipe) identifier: string,
@Query('after') after: string): Promise<MexTokenChart[]> {
return await this.mexTokenChartsService.getTokenPricesDayResolution(identifier, after);
@Query('after') after: string): Promise<MexTokenChart[] | undefined> {
const charts = await this.mexTokenChartsService.getTokenPricesDayResolution(identifier, after);

if(!charts){
throw new NotFoundException('Token not found');
}

return charts;
}
}
22 changes: 10 additions & 12 deletions src/endpoints/mex/mex.token.charts.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,19 @@ export class MexTokenChartsService {
private readonly cachingService: CacheService,
) { }

async getTokenPricesHourResolution(tokenIdentifier: string): Promise<MexTokenChart[]> {
async getTokenPricesHourResolution(tokenIdentifier: string): Promise<MexTokenChart[] | undefined> {
return await this.cachingService.getOrSet(
CacheInfo.TokenHourChar(tokenIdentifier).key,
CacheInfo.TokenHourChart(tokenIdentifier).key,
async () => await this.getTokenPricesHourResolutionRaw(tokenIdentifier),
CacheInfo.TokenHourChar(tokenIdentifier).ttl,
CacheInfo.TokenHourChart(tokenIdentifier).ttl,
);
}

async getTokenPricesHourResolutionRaw(tokenIdentifier: string): Promise<MexTokenChart[]> {
async getTokenPricesHourResolutionRaw(tokenIdentifier: string): Promise<MexTokenChart[] | undefined> {
const tokenExists = await this.checkTokenExists(tokenIdentifier);

if (!tokenExists) {
this.logger.error(`Token ${tokenIdentifier} does not exist or has no trading pair`);
return [];
return undefined;
}

const query = gql`
Expand All @@ -54,20 +53,19 @@ export class MexTokenChartsService {
}
}

async getTokenPricesDayResolution(tokenIdentifier: string, after: string): Promise<MexTokenChart[]> {
async getTokenPricesDayResolution(tokenIdentifier: string, after: string): Promise<MexTokenChart[] | undefined> {
return await this.cachingService.getOrSet(
CacheInfo.TokenDailyChar(tokenIdentifier, after).key,
CacheInfo.TokenDailyChart(tokenIdentifier, after).key,
async () => await this.getTokenPricesDayResolutionRaw(tokenIdentifier, after),
CacheInfo.TokenDailyChar(tokenIdentifier, after).ttl,
CacheInfo.TokenDailyChart(tokenIdentifier, after).ttl,
);
}

async getTokenPricesDayResolutionRaw(tokenIdentifier: string, after: string): Promise<MexTokenChart[]> {
async getTokenPricesDayResolutionRaw(tokenIdentifier: string, after: string): Promise<MexTokenChart[] | undefined> {
const tokenExists = await this.checkTokenExists(tokenIdentifier);

if (!tokenExists) {
this.logger.error(`Token ${tokenIdentifier} does not exist or has no trading pair`);
return [];
return undefined;
}

const query = gql`
Expand Down
4 changes: 2 additions & 2 deletions src/utils/cache.info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ export class CacheInfo {
};
}

static TokenHourChar(tokenIdentifier: string): CacheInfo {
static TokenHourChart(tokenIdentifier: string): CacheInfo {
return {
key: `tokenHourChart:${tokenIdentifier}`,
ttl: Constants.oneMinute() * 10,
};
}

static TokenDailyChar(tokenIdentifier: string, after: string): CacheInfo {
static TokenDailyChart(tokenIdentifier: string, after: string): CacheInfo {
return {
key: `tokenDailyChart:${tokenIdentifier}:${after}`,
ttl: Constants.oneDay(),
Expand Down

0 comments on commit 9c224c6

Please sign in to comment.