change format name

This commit is contained in:
2025-10-22 11:16:38 -06:00
parent 496b3ab367
commit a975b89a85
2 changed files with 22 additions and 10 deletions
+2
View File
@@ -44,10 +44,12 @@ export class GoogleStrategy extends PassportStrategy(Strategy, 'google') {
): Promise<any> {
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,
});
+20 -10
View File
@@ -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,