fixed slice
This commit is contained in:
@@ -38,22 +38,11 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
|
||||
): Promise<any> {
|
||||
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);
|
||||
|
||||
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user