ekyc

Electronic KYC process with uploading ID document using OAuth 2.1 (experimental)
Log | Files | Refs | README | LICENSE

phone.ts (999B)


      1 import { PhoneRepository } from "#core/application/phone/phone_repository.ts";
      2 import { EntityLocked } from "#core/application/repository_error.ts";
      3 import { PhoneEKYC } from "#core/domain/phone_ekyc.ts";
      4 import { UUID } from "#core/domain/uuid.ts";
      5 import {
      6   mapFromPhoneEKYC,
      7   mapToPhoneEKYC,
      8   PhoneEKYCDto,
      9 } from "#infrastructure/memory/mapper/phone.ts";
     10 
     11 export class MemoryPhoneRepositoryAdapter implements PhoneRepository {
     12   constructor(private readonly entities: Map<string, PhoneEKYCDto>) {
     13   }
     14 
     15   findOrCreate(id: UUID): PhoneEKYC {
     16     const entity = this.entities.get(id.toString());
     17     if (entity !== undefined) {
     18       return mapToPhoneEKYC(entity);
     19     }
     20     return new PhoneEKYC(id);
     21   }
     22 
     23   store(entity: PhoneEKYC): void {
     24     const dto = mapFromPhoneEKYC(entity);
     25     const latest = this.entities.get(dto.uuid)?.version ?? 0;
     26     if (latest > dto.version) {
     27       throw new EntityLocked();
     28     }
     29     entity.version = ++dto.version;
     30     this.entities.set(dto.uuid, dto);
     31   }
     32 }