From ed371ee4977f0263e051ba0c8dcffd1a35adea37 Mon Sep 17 00:00:00 2001 From: IO420 <320154041@pcpuma.acatlan.unam.mx> Date: Fri, 17 Oct 2025 12:07:10 -0600 Subject: [PATCH] fixed slice --- src/persona/google.strategy.ts | 15 ++------------- src/persona/persona.service.ts | 24 +++++++++++++----------- 2 files changed, 15 insertions(+), 24 deletions(-) diff --git a/src/persona/google.strategy.ts b/src/persona/google.strategy.ts index 0cd630a..0edcdce 100644 --- a/src/persona/google.strategy.ts +++ b/src/persona/google.strategy.ts @@ -38,22 +38,11 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') { ): Promise { try { const email = profile.emails?.[0]?.value || ''; - - // Separar apellidos - const apellidos = (profile.name?.familyName || '').trim().split(' '); - const apellidoP = apellidos[0] || ''; - const apellidoM = apellidos[1] || ''; - const nombre = apellidos.slice(2).join(' ') || ''; - - // Número identificador del correo - const numeroIdentificar = email.split('@')[0]; + const apellido = profile.name?.familyName || ''; const user = await this.personaService.validateOrCreateGoogleUser({ email, - nombre, - apellidoP, - apellidoM, - numeroIdentificar, + apellido, }); done(null, user); diff --git a/src/persona/persona.service.ts b/src/persona/persona.service.ts index 7c0a3b9..19dc39a 100644 --- a/src/persona/persona.service.ts +++ b/src/persona/persona.service.ts @@ -32,20 +32,22 @@ export class PersonaService { } // Opción: validateOrCreateGoogleUser para usar en GoogleStrategy - async validateOrCreateGoogleUser(data: { - email: string; - nombre: string; - apellidoP: string; - apellidoM: string; - numeroIdentificar: string; - }) { + async validateOrCreateGoogleUser(data: { email: string; apellido: string }) { let persona = await this.findByEmail(data.email); if (!persona) { + const apellidoArray = data.apellido.trim().split(' '); + const apellidoP = data.apellido[0] || ''; + const apellidoM = data.apellido[1] || ''; + const nombre = apellidoArray.slice(2).join(' ') || ''; + + // Número identificador del correo + const numeroIdentificar = data.email.split('@')[0]; + persona = await this.create({ - nombre: data.nombre || '', - apellidoP: data.apellidoP || '', - apellidoM: data.apellidoM || '', + nombre: nombre || '', + apellidoP: apellidoP || '', + apellidoM: apellidoM || '', password: '', passwordTem: '', fechaPasswordTem: new Date(), @@ -53,7 +55,7 @@ export class PersonaService { carreraAds: '', cantidadCuenta: 0, usuario: '', - numeroIdentificar: data.numeroIdentificar || '', + numeroIdentificar: numeroIdentificar || '', tipoUsuario: '', correoEnviado: false, fechaRegistro: new Date(),