testing-entity-id-strategy.ts 655 B

1234567891011121314151617
  1. import { IntegerIdStrategy } from '../../src/config/entity-id-strategy/entity-id-strategy';
  2. /**
  3. * A testing entity id strategy which prefixes all IDs with a constant string. This is used in the
  4. * e2e tests to ensure that all ID properties in arguments are being
  5. * correctly decoded.
  6. */
  7. export class TestingEntityIdStrategy implements IntegerIdStrategy {
  8. readonly primaryKeyType = 'increment';
  9. decodeId(id: string): number {
  10. const asNumber = parseInt(id.replace('T_', ''), 10);
  11. return Number.isNaN(asNumber) ? -1 : asNumber;
  12. }
  13. encodeId(primaryKey: number): string {
  14. return 'T_' + primaryKey.toString();
  15. }
  16. }