Spaces:
Sleeping

File size: 968 Bytes
7f81110
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import { AuthOrchestrator } from "../orchestrator/AuthOrchestrator";
import { UnitOfWorkFactory } from "../../../../libs/shared/infrastructure/postgres/unitOfWork/UnitOfWorkFactory";
import { IUnitOfWork } from "../../../../libs/shared/infrastructure/postgres/unitOfWork/IUnitOfWork";

export interface LoginInput {
    email: string;
    password: string;
}

export interface LoginOutput {
    token: string;
    user: {
        id: string;
        email: string;
        organizationId: string;
        storeId: string;
        role: string;
    };
}

export class LoginUseCase {
    private readonly orchestrator: AuthOrchestrator;

    constructor(private readonly uowFactory: UnitOfWorkFactory) {
        this.orchestrator = new AuthOrchestrator();
    }

    async execute(input: LoginInput): Promise<LoginOutput> {
        return this.uowFactory.execute(async (uow: IUnitOfWork) => {
            return this.orchestrator.signIn(uow, input);
        });
    }
}