All files / approval-engine/mappers value.mapper.ts

12.5% Statements 1/8
100% Branches 0/0
12.5% Functions 1/8
12.5% Lines 1/8

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73                              2x                                                                                                                  
import {
  AbsoluteFixedValue,
  Amount,
  Fraction,
  RelativeValue,
} from "../../tr8-script/domain/value.js";
import {
  AbsoluteFixedValueDto,
  AmountDto,
  FractionDto,
  RelativeValueDto,
} from "../dtos/value.dto.js";
 
export class AmountValueMapper {
  static fromMessage(amountDto: AmountDto): Amount {
    return {
      amount: BigInt(amountDto.amount),
      scale: BigInt(amountDto.scale),
    };
  }
  static toMessage(amount: Amount): AmountDto {
    return {
      amount: amount.amount.toString(),
      scale: amount.scale.toString(),
    };
  }
}
 
export class FractionValueMapper {
  static fromMessage(fractionDto: FractionDto): Fraction {
    return [
      AmountValueMapper.fromMessage(fractionDto[0]),
      AmountValueMapper.fromMessage(fractionDto[1]),
    ];
  }
  static toMessage(fraction: Fraction): FractionDto {
    return [
      AmountValueMapper.toMessage(fraction[0]),
      AmountValueMapper.toMessage(fraction[1]),
    ];
  }
}
 
export class AbsoluteFixedValueMapper {
  static fromMessage(dto: AbsoluteFixedValueDto): AbsoluteFixedValue {
    return {
      type: dto.type,
      amount: AmountValueMapper.fromMessage(dto.amount),
    };
  }
  static toMessage(value: AbsoluteFixedValue): AbsoluteFixedValueDto {
    return {
      type: value.type,
      amount: AmountValueMapper.toMessage(value.amount),
    };
  }
}
 
export class RelativeValueMapper {
  static fromMessage(dto: RelativeValueDto): RelativeValue {
    return {
      ...dto,
      amount: FractionValueMapper.fromMessage(dto.amount),
    };
  }
  static toMessage(value: RelativeValue): RelativeValueDto {
    return {
      ...value,
      amount: FractionValueMapper.toMessage(value.amount),
    };
  }
}