init
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
IsEnum,
|
||||
IsNotEmpty,
|
||||
IsObject,
|
||||
Validate,
|
||||
ValidatorConstraint,
|
||||
type ValidatorConstraintInterface,
|
||||
type ValidationArguments
|
||||
} from 'class-validator';
|
||||
import { ShopFiatCurrency } from '../../../types/ShopFiatCurrency';
|
||||
|
||||
@ValidatorConstraint({ name: 'coingeckoMoneroFiat' })
|
||||
class CoingeckoMoneroFiatConstraint implements ValidatorConstraintInterface {
|
||||
validate(monero: Record<string, number>, args: ValidationArguments): boolean {
|
||||
const { shopFiatCurrency } = args.object as CoingeckoSimplePriceResponseDto;
|
||||
|
||||
if (!shopFiatCurrency) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const rate = monero[shopFiatCurrency.toLowerCase()];
|
||||
|
||||
return typeof rate === 'number' && Number.isFinite(rate) && rate > 0;
|
||||
}
|
||||
|
||||
defaultMessage(): string {
|
||||
return 'CoinGecko monero fiat rate must be a positive number';
|
||||
}
|
||||
}
|
||||
|
||||
export class CoingeckoSimplePriceResponseDto {
|
||||
@IsEnum(ShopFiatCurrency)
|
||||
shopFiatCurrency: ShopFiatCurrency;
|
||||
|
||||
@IsNotEmpty()
|
||||
@IsObject()
|
||||
@Validate(CoingeckoMoneroFiatConstraint)
|
||||
monero: Record<string, number>;
|
||||
}
|
||||
Reference in New Issue
Block a user