ekyc

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

exists.ts (1085B)


      1 import { AuthRepository } from "#core/application/authn/auth_repository.ts";
      2 import { EntityNotFound } from "#core/application/repository_error.ts";
      3 import { Email, InvalidEmail } from "#core/domain/email.ts";
      4 
      5 export type AuthExistsUseCaseRequest = {
      6   email: string;
      7 };
      8 
      9 export type AuthExistsUseCaseResponse = {
     10   status: "found" | "unknown" | "invalid";
     11   uuid: string | null;
     12 };
     13 
     14 export class AuthExistsUseCase {
     15   constructor(readonly authRepo: AuthRepository) {
     16   }
     17 
     18   async execute(
     19     request: AuthExistsUseCaseRequest,
     20   ): Promise<AuthExistsUseCaseResponse> {
     21     try {
     22       const email = new Email(request.email);
     23       const auth = await this.authRepo.findByEmail(email);
     24       return {
     25         status: "found",
     26         uuid: auth.id.toString(),
     27       };
     28     } catch (error) {
     29       if (error instanceof InvalidEmail) {
     30         return {
     31           status: "invalid",
     32           uuid: null,
     33         };
     34       }
     35       if (error instanceof EntityNotFound) {
     36         return {
     37           status: "unknown",
     38           uuid: null,
     39         };
     40       }
     41       throw error;
     42     }
     43   }
     44 }