31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { z } from "zod";
|
|
import { ISignInUseCase } from "@/src/application/use-cases/auth/sign-in.use-case";
|
|
import { IInstrumentationService } from "@/src/application/services/instrumentation.service.interface";
|
|
import { InputParseError } from "@/src/entities/errors/common";
|
|
|
|
// Sign In Controller
|
|
const signInInputSchema = z.object({
|
|
email: z.string().min(1, "Email is Required").email("Please enter a valid email address"),
|
|
})
|
|
|
|
export type ISignInController = ReturnType<typeof signInController>
|
|
|
|
export const signInController =
|
|
(
|
|
instrumentationService: IInstrumentationService,
|
|
signInUseCase: ISignInUseCase
|
|
) =>
|
|
async (input: Partial<z.infer<typeof signInInputSchema>>) => {
|
|
return await instrumentationService.startSpan({ name: "signIn Controller" }, async () => {
|
|
const { data, error: inputParseError } = signInInputSchema.safeParse(input)
|
|
|
|
if (inputParseError) {
|
|
throw new InputParseError(inputParseError.errors[0].message)
|
|
}
|
|
|
|
return await signInUseCase({
|
|
email: data.email
|
|
})
|
|
})
|
|
}
|