Agrego frontend app
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
class Usuario {
|
||||
final String id;
|
||||
final String dni;
|
||||
final String nombre;
|
||||
final String? apellido;
|
||||
final double? peso;
|
||||
final int? altura;
|
||||
final String rol;
|
||||
final bool isActive;
|
||||
final DateTime? fechaCreacion;
|
||||
final DateTime? fechaModificacion;
|
||||
final String? mail;
|
||||
final String? telefono;
|
||||
final double? fuerzaMax;
|
||||
final String? sexo;
|
||||
final String? tipoCuota;
|
||||
|
||||
const Usuario({
|
||||
required this.id,
|
||||
required this.dni,
|
||||
required this.nombre,
|
||||
this.apellido,
|
||||
this.peso,
|
||||
this.altura,
|
||||
required this.rol,
|
||||
this.isActive = true,
|
||||
this.fechaCreacion,
|
||||
this.fechaModificacion,
|
||||
this.mail,
|
||||
this.telefono,
|
||||
this.fuerzaMax,
|
||||
this.sexo,
|
||||
this.tipoCuota,
|
||||
});
|
||||
|
||||
factory Usuario.fromMap(Map<String, dynamic> map) {
|
||||
return Usuario(
|
||||
id: map['id'] as String,
|
||||
dni: map['dni'] as String? ?? '',
|
||||
nombre: map['nombre'] as String? ?? '',
|
||||
apellido: map['apellido'] as String?,
|
||||
peso: (map['peso'] as num?)?.toDouble(),
|
||||
altura: (map['altura'] as num?)?.toInt(),
|
||||
rol: map['rol'] as String? ?? 'cliente',
|
||||
isActive: map['isactive'] as bool? ?? map['isActive'] as bool? ?? true,
|
||||
fechaCreacion: map['fecha_creacion'] != null
|
||||
? DateTime.tryParse(map['fecha_creacion'].toString())
|
||||
: null,
|
||||
fechaModificacion: map['fecha_modificacion'] != null
|
||||
? DateTime.tryParse(map['fecha_modificacion'].toString())
|
||||
: null,
|
||||
mail: map['mail'] as String?,
|
||||
telefono: map['telefono'] as String?,
|
||||
fuerzaMax: (map['fuerza_max'] as num?)?.toDouble(),
|
||||
sexo: map['sexo'] as String?,
|
||||
tipoCuota: map['tipo_cuota'] as String?,
|
||||
);
|
||||
}
|
||||
|
||||
String get displayName {
|
||||
if (nombre.isNotEmpty && apellido != null && apellido!.isNotEmpty) {
|
||||
return '$nombre $apellido';
|
||||
}
|
||||
return nombre.isNotEmpty ? nombre : dni;
|
||||
}
|
||||
|
||||
String get rolDisplay {
|
||||
return switch (rol) {
|
||||
'superadmin' || 'admin' || 'profesor' => 'Admin',
|
||||
'cliente' => 'Cliente',
|
||||
_ => rol,
|
||||
};
|
||||
}
|
||||
|
||||
String get initials {
|
||||
if (nombre.isNotEmpty && apellido != null && apellido!.isNotEmpty) {
|
||||
return '${nombre[0]}${apellido![0]}'.toUpperCase();
|
||||
}
|
||||
if (nombre.isNotEmpty) return nombre[0].toUpperCase();
|
||||
if (dni.length >= 2) return dni.substring(0, 2);
|
||||
return '?';
|
||||
}
|
||||
|
||||
/// Para fc_insertar_usuario (p_datos jsonb).
|
||||
Map<String, dynamic> toInsertMap(String password) {
|
||||
return {
|
||||
'dni': dni,
|
||||
'nombre': nombre,
|
||||
if (apellido != null) 'apellido': apellido,
|
||||
if (peso != null) 'peso': peso,
|
||||
if (altura != null) 'altura': altura,
|
||||
'rol': rol,
|
||||
if (mail != null && mail!.isNotEmpty) 'mail': mail,
|
||||
if (telefono != null && telefono!.isNotEmpty) 'telefono': telefono,
|
||||
if (fuerzaMax != null) 'fuerza_max': fuerzaMax,
|
||||
if (sexo != null) 'sexo': sexo,
|
||||
if (tipoCuota != null) 'tipo_cuota': tipoCuota,
|
||||
if (password.isNotEmpty) 'password': password,
|
||||
'isActive': isActive,
|
||||
};
|
||||
}
|
||||
|
||||
/// Para fc_modificar_usuario (p_datos jsonb). Sin password.
|
||||
Map<String, dynamic> toUpdateMap() {
|
||||
return {
|
||||
'dni': dni,
|
||||
'nombre': nombre,
|
||||
if (apellido != null) 'apellido': apellido,
|
||||
if (peso != null) 'peso': peso,
|
||||
if (altura != null) 'altura': altura,
|
||||
'rol': rol,
|
||||
if (mail != null) 'mail': mail,
|
||||
if (telefono != null) 'telefono': telefono,
|
||||
if (fuerzaMax != null) 'fuerza_max': fuerzaMax,
|
||||
if (sexo != null) 'sexo': sexo,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
import 'package:gimnasio_soma/features/usuarios/domain/entities/usuario.dart';
|
||||
|
||||
abstract class UsuariosRepository {
|
||||
Future<List<Usuario>> getUsuarios({
|
||||
int pagina = 1,
|
||||
int cantidad = 50,
|
||||
String? dni,
|
||||
});
|
||||
|
||||
Future<void> insertUsuario(Map<String, dynamic> datos);
|
||||
|
||||
Future<void> updateUsuario(Map<String, dynamic> datos);
|
||||
|
||||
Future<void> toggleUsuarioStatus(String id, bool estado);
|
||||
|
||||
Future<bool> deleteUsuario(String dni);
|
||||
|
||||
/// Reset administrativo de contraseña (solo superadmin). No requiere la
|
||||
/// contraseña actual del usuario objetivo.
|
||||
Future<void> resetearContrasena(String usuarioId, String passwordNueva);
|
||||
|
||||
/// Obtener mapping usuario → tipo de cuota.
|
||||
Future<List<Map<String, dynamic>>> getUsuariosTipoCuota({String? dni});
|
||||
}
|
||||
Reference in New Issue
Block a user