Skip to content

Commit

Permalink
Merge pull request #39 from axone-protocol/refactor/supply-charts
Browse files Browse the repository at this point in the history
refactor: merged supply charts into one endpoint
  • Loading branch information
yevhen-burkovskyi authored Jun 20, 2024
2 parents 656d0f0 + 63dd31b commit 98f3627
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions src/modules/supply/enums/supply-endpoints.enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ export enum SupplyEndpoints {
CHANGE = '/change',
BURNT = '/burnt',
GROWTH = '/growth',
CHARTS = '/charts',
}
6 changes: 6 additions & 0 deletions src/modules/supply/schemas/charts-range.schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { Range } from "@core/enums/range.enum";
import * as Joi from "joi";

export const ChartsRangeSchema = Joi.string()
.valid(Range.FIVE_MIN, Range.HOUR, Range.DAY, Range.WEEK, Range.MONTH)
.required();
4 changes: 0 additions & 4 deletions src/modules/supply/schemas/growth-range.schema.ts

This file was deleted.

12 changes: 12 additions & 0 deletions src/modules/supply/services/supply.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,16 @@ export class SupplyService implements OnModuleInit {

return 0;
}

async getCharts(range: Range) {
const issuance = await this.getSupplyChange(range);
const growth = await this.getSupplyGrowth(range);
const burnt = 0;

return {
issuance,
growth,
burnt,
}
}
}
25 changes: 10 additions & 15 deletions src/modules/supply/supply.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ import { HistoricalRangeSchema } from "./schemas/historical-range.schema";
import { SupplyService } from "./services/supply.service";
import { ChangeRangeSchema } from "./schemas/change-range.schema";
import { Range } from "@core/enums/range.enum";
import { GrowthRangeSchema } from "./schemas/growth-range.schema";
import { ChartsRangeSchema } from "./schemas/charts-range.schema";

@Controller(Routes.SUPPLY)
export class SupplyController {
constructor(
private readonly cache: SupplyCache,
private readonly service: SupplyService,
) {}

@Get(SupplyEndpoints.HISTORICAL)
async getHistoricalSupply(
@Query(QueryParam.RANGE, new SchemaValidatePipe(HistoricalRangeSchema))
range: Range,
range: Range
) {
return this.cache.getSupplyHistorical(range);
}
Expand All @@ -33,21 +33,16 @@ export class SupplyController {
@Get(SupplyEndpoints.CHANGE)
async getSupplyChange(
@Query(QueryParam.RANGE, new SchemaValidatePipe(ChangeRangeSchema))
range: Range,
range: Range
) {
return this.service.getSupplyChange(range);
}

@Get(SupplyEndpoints.BURNT)
async getSupplyBurnt() {
return 0;
}

@Get(SupplyEndpoints.GROWTH)
async getSupplyGrowth(
@Query(QueryParam.RANGE, new SchemaValidatePipe(GrowthRangeSchema))
range: Range,
@Get(SupplyEndpoints.CHARTS)
async getCharts(
@Query(QueryParam.RANGE, new SchemaValidatePipe(ChartsRangeSchema))
range: Range
) {
return this.service.getSupplyGrowth(range);
return this.service.getCharts(range);
}
}
}

0 comments on commit 98f3627

Please sign in to comment.