From a975b89a851f23e6fc496adaaf75813f4c552696 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Wed, 22 Oct 2025 11:16:38 -0600 Subject: [PATCH] change format name --- src/persona/google.strategy.ts | 2 ++ src/persona/persona.service.ts | 30 ++++++++++++++++++++---------- 2 files changed, 22 insertions(+), 10 deletions(-) diff --git a/src/persona/google.strategy.ts b/src/persona/google.strategy.ts index c2c2a65..691eb97 100644 --- a/src/persona/google.strategy.ts +++ b/src/persona/google.strategy.ts @@ -44,10 +44,12 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { ): Promise { try { const email = profile.emails?.[0]?.value || ''; + const nombre = profile.name?.givenName || ''; const apellido = profile.name?.familyName || ''; const user = await this.personaService.validateOrCreateGoogleUser({ email, + nombre, apellido, }); diff --git a/src/persona/persona.service.ts b/src/persona/persona.service.ts index 6bfa11d..2441028 100644 --- a/src/persona/persona.service.ts +++ b/src/persona/persona.service.ts @@ -52,32 +52,42 @@ export class PersonaService { }; } - async validateOrCreateGoogleUser(data: { email: string; apellido: string }) { + async validateOrCreateGoogleUser(data: { + email: string; + nombre: string; + apellido: string; + }) { let persona = await this.findByEmail(data.email); if (!persona) { const apellidoArray = data.apellido.split(' '); + const apellidoP = apellidoArray[0] || ''; const apellidoM = apellidoArray[1] || ''; - const nombre = apellidoArray.slice(2).join(' ') || ''; - + let realName; const numeroIdentificar = data.email.split('@')[0]; - const password = await passwordRand(12); - let hash = await bcrypt.hashSync(password, 13); + let tipo; + if (Number(numeroIdentificar) === 9) { + tipo = 'Alumno'; + realName = apellidoArray.slice(2).join(' ') || ''; + } else { + tipo = 'Academico'; + realName = data.nombre; + } persona = await this.create({ - nombre: nombre || '', + nombre: realName || '', apellidoP: apellidoP || '', apellidoM: apellidoM || '', - password: hash, + password: '', fechaPasswordTem: new Date(), correo: data.email, - carreraAds: 'Mac', + carreraAds: '', cantidadCuenta: 0, - usuario: numeroIdentificar || '', + usuario: numeroIdentificar, numeroIdentificar: numeroIdentificar || '', - tipoUsuario: 'Alumno', + tipoUsuario: tipo, correoEnviado: false, fechaRegistro: new Date(), cambioPasswordReq: true,