-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: implement control plane #4
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Casi lo tienes ! espero que mis comentarios te sirvan para entender más a profundidad los conceptos y poder superar el desafío !
No te preocupes por Zod, porque en este caso como la comunicación no se realizaría entre este servicio y la app de Front End no es necesario. Zod lo usamos para TRPC.
PD: no mergear, es solo a fines de aprendizaje
import { ForManagerAuthentication } from '../../ports/drivers'; | ||
|
||
export class ManagerAuthenticationProxyAdapter implements ForManagerAuthentication{ | ||
constructor(private readonly controlPlane: ControlPlane){} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar espacios entre unidades lógicas
constructor(private readonly controlPlane: ControlPlane){} | |
constructor(private readonly controlPlane: ControlPlane){} | |
constructor(private readonly controlPlane: ControlPlane){} | ||
async getAuthDetails(email: string, password: string): Promise<AuthDetails>{ | ||
return this.controlPlane.getAuthDetails(email,password); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar espacios entre unidades lógicas
} | |
} | |
|
||
//Los driveR de los Puertos son los que describen mi hexagono, mis CONTRATOS | ||
//en este caso el hexagono de control plane tiene dar detalles de autenticacion y los permisos de los usuarios | ||
export interface ForManagerAuthentication{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debería de ser igual al nombre del file, "ForMangingAuthentication"
export interface AuthDetails{ | ||
token:string; | ||
refreshToken:string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar espacios entre unidades lógicas
} | |
} | |
|
||
// const authDetails = await this. | ||
return Promise.resolve({token:"123", refreshToken:"1234"}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar espacios entre unidades lógicas
} | |
} | |
import { AuthDetails,Permissions } from "./schemas"; | ||
//Mi hexagono que tiene implementado los puertos de los driveR, en este caso es solo uno pero podrian ser mas | ||
export class ControlPlane implements ForManagerAuthentication{ | ||
//el Constructor los DriverN del puerto, osea que son los recurson necesario para que mi hexagono funcione |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ojo con los errores de ortografía en los comments y siempre en inglés
async getAuthDetails(email: string, password: string): Promise<AuthDetails> { | ||
|
||
// const authDetails = await this. | ||
return Promise.resolve({token:"123", refreshToken:"1234"}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aquí te faltan los adapters que te resuelven la authentication, normalmente utilizarías una tecnología como jwt o similares y para comunicarte con la misma necesitas de un adapter, así de esta manera la información que entra en la app y la que sale hacia afuera siguen útiles y sin conflictos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahora mismo solo tienes los puertos de entrada al hexágono, que no esta mal, pero faltarían los puertos driven que se comunican con otros hexágonos o herramientas a nivel interno para obtener los recursos.
En tu caso te faltaría un for-authenticating al que luego le generarás un adapter que lo implemente de tipo stub y que este devuelva si está o no authenticado el user.
La lógica que guardas en el servicio en sí, en tu caso el control plane, siempre es de negocio. Por ejemplo y fuera de este contexto, si la persona esta logueada generar un log, guardar en una base de datos aparte y devolver esta informacion al usuario es parte de la lógica de negocios; Pero cómo se realiza el log, cómo se guarda en la base de datos, es algo externo a la lógica de negocios, y es responsabilidad de otro servicio o herramienta aparte, en nuestro caso el logger es una herramienta y el manejo en la base de datos lo haría el servicio repository que ya tenemos hecho. Y para cada uno de estos casos deberíamos de tener un adapter que comunique la información
// const managerAuthenticationProxy = new ManagerAuthenticationProxyAdapter(controlPlaneMock) | ||
|
||
it.concurrent("should get auth description", async()=>{ | ||
const mockedUser = {email:"[email protected]",password:"123"} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agregar los
// GIVEN
// WHEN
// THEN
No es mucho es trabajo honesto,es la primera vez que hago algo como esto y me costo un rato entender para que se utilizaban los drivers y los drivens de ports y también los de adapters, pero al final se podría decir que lo conseguí, me falta agregar el tipado con zod, en cuanto tenga tiempo aprendo que es zod y lo hago, espero me puedas dar retro para ver que me falta, gracias saluditos