Skip to content

Commit

Permalink
Merge pull request #940 from aura-nw/baseline/main_20231002
Browse files Browse the repository at this point in the history
Baseline/main_20231002
  • Loading branch information
nhphuc2411 authored Oct 2, 2023
2 parents e3acd32 + bc6df0e commit 0fb5942
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/components/metric/controllers/metric.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export class MetricController {
query.min,
query.max,
query.rangeType,
query.step,
query.coinId,
);

Expand Down
4 changes: 4 additions & 0 deletions src/components/metric/dtos/cw20-metric-params.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export class Cw20MetricParamsDto {
@ApiProperty()
readonly rangeType: RangeType = RangeType.minute;

@ApiPropertyOptional()
@Transform(({ value }) => Number(value))
step: number;

@ApiProperty()
@IsNotEmpty()
coinId: string;
Expand Down
10 changes: 5 additions & 5 deletions src/components/metric/services/metric.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ export class MetricService {
min: number,
max: number,
rangeType: RangeType,
step: number,
coinId: string,
): Promise<TokenOutput[]> {
try {
this.logger.log(ctx, `${this.getTokenInfo.name} was called!`);
// const { step, fluxType, amount } = buildCondition(range);
const range = rangeType === RangeType.minute ? 3 : 1;
const queryStep = `${range}${rangeType}`;
const queryStep = `${step || 1}${rangeType}`;
const minDate = new Date(min),
maxDate = new Date(max);

Expand Down Expand Up @@ -162,19 +162,19 @@ export class MetricService {
const compareDate = moment(maxDate).utc();
switch (rangeType) {
case RangeType.day:
compareDate.add(-365, 'd'); // Value of 1 year
compareDate.add(-730, 'd'); // Value of 2 years
formatDate = 'YYYY-MM-DDT00:00:00.000';
break;
case RangeType.month:
compareDate.add(-60, 'M'); // Value of 5 year
formatDate = 'YYYY-MM-01T00:00:00.000';
break;
case RangeType.hour:
compareDate.add(-360, 'h'); // Value of 15 day
compareDate.add(-1440, 'h'); // Value of 60 days
formatDate = 'YYYY-MM-DDTHH:00:00.000';
break;
default:
compareDate.add(-1440, 'm'); // Value of 24 hourse
compareDate.add(-2880, 'm'); // Value of 48 hours
formatDate = 'YYYY-MM-DDTHH:mm:00.000';
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,20 @@ export class SoulboundTokenController {
minterAddress,
);
}

@Get('count/:receiverAddress')
async countTokenByReceiverAddress(
@ReqContext() ctx: RequestContext,
@Param('receiverAddress') receiverAddress: string,
) {
this.logger.log(
ctx,
`${this.countTokenByReceiverAddress.name} was called!`,
);
const token = await this.soulboundTokenService.countTokenByReceiverAddress(
ctx,
receiverAddress,
);
return { data: token };
}
}
24 changes: 24 additions & 0 deletions src/components/soulbound-token/services/soulbound-token.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { RedisUtil } from '../../../shared/utils/redis.util';
import { SoulboundWhiteListRepository } from '../repositories/soulbound-white-list.repository';
import { TokenUpdatedParasDto } from '../dtos/token-updated-paras.dto';
import { SoulboundRejectListRepository } from '../repositories/soulbound-reject-list.repository';
import { Not } from 'typeorm';

@Injectable()
export class SoulboundTokenService {
Expand Down Expand Up @@ -423,6 +424,29 @@ export class SoulboundTokenService {
return { notify: result };
}

/**
* count soulbound token of receiver address
* @param ctx
* @param receiverAddress
* @returns
*/
async countTokenByReceiverAddress(
ctx: RequestContext,
receiverAddress: string,
) {
this.logger.log(
ctx,
`============== ${this.countTokenByReceiverAddress.name} was called with paras: ${receiverAddress}! ==============`,
);
const result = await this.soulboundTokenRepos.count({
where: {
receiver_address: receiverAddress,
status: Not(SOULBOUND_TOKEN_STATUS.REJECTED),
},
});
return result;
}

/**
* Update notify of soulbound token
* @param ctx
Expand Down
1 change: 0 additions & 1 deletion src/shared/configs/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ export default () => ({
channel: process.env.REDIS_ABT_CHANNEL,
},
},
threads: process.env.THREADS,
indexer: {
url: process.env.INDEXER_URL,
chainId: process.env.INDEXER_CHAIN_ID,
Expand Down

0 comments on commit 0fb5942

Please sign in to comment.