refactor: enhance role management UI and integrate profile management features
- Introduced a modal for managing user profiles, allowing for the creation and editing of profiles with improved state management. - Updated the role filtering logic to enhance type safety and readability. - Refactored UI components for better user experience, including improved button states and loading indicators. - Removed outdated code related to permissions and streamlined the overall structure for maintainability.
This commit is contained in:
@@ -191,23 +191,36 @@ export const obterMetricas = query({
|
||||
})
|
||||
),
|
||||
handler: async (ctx, args) => {
|
||||
let query = ctx.db.query("systemMetrics");
|
||||
|
||||
// Filtrar por data se fornecido
|
||||
if (args.dataInicio !== undefined || args.dataFim !== undefined) {
|
||||
query = query.withIndex("by_timestamp", (q) => {
|
||||
if (args.dataInicio !== undefined && args.dataFim !== undefined) {
|
||||
return q.gte("timestamp", args.dataInicio).lte("timestamp", args.dataFim);
|
||||
} else if (args.dataInicio !== undefined) {
|
||||
return q.gte("timestamp", args.dataInicio);
|
||||
} else {
|
||||
return q.lte("timestamp", args.dataFim!);
|
||||
}
|
||||
});
|
||||
// Construir consulta respeitando tipos sem reatribuições
|
||||
let metricas;
|
||||
if (args.dataInicio !== undefined && args.dataFim !== undefined) {
|
||||
const inicio: number = args.dataInicio as number;
|
||||
const fim: number = args.dataFim as number;
|
||||
metricas = await ctx.db
|
||||
.query("systemMetrics")
|
||||
.withIndex("by_timestamp", (q) =>
|
||||
q.gte("timestamp", inicio).lte("timestamp", fim)
|
||||
)
|
||||
.order("desc")
|
||||
.collect();
|
||||
} else if (args.dataInicio !== undefined) {
|
||||
const inicio: number = args.dataInicio as number;
|
||||
metricas = await ctx.db
|
||||
.query("systemMetrics")
|
||||
.withIndex("by_timestamp", (q) => q.gte("timestamp", inicio))
|
||||
.order("desc")
|
||||
.collect();
|
||||
} else if (args.dataFim !== undefined) {
|
||||
const fim: number = args.dataFim as number;
|
||||
metricas = await ctx.db
|
||||
.query("systemMetrics")
|
||||
.withIndex("by_timestamp", (q) => q.lte("timestamp", fim))
|
||||
.order("desc")
|
||||
.collect();
|
||||
} else {
|
||||
metricas = await ctx.db.query("systemMetrics").order("desc").collect();
|
||||
}
|
||||
|
||||
let metricas = await query.order("desc").collect();
|
||||
|
||||
// Limitar resultados
|
||||
if (args.limit !== undefined && args.limit > 0) {
|
||||
metricas = metricas.slice(0, args.limit);
|
||||
@@ -298,10 +311,10 @@ export const verificarAlertasInternal = internalMutation({
|
||||
.collect();
|
||||
|
||||
for (const alerta of alertasAtivos) {
|
||||
// Obter valor da métrica correspondente
|
||||
const metricValue = (metrica as Record<string, number>)[alerta.metricName];
|
||||
|
||||
if (metricValue === undefined) continue;
|
||||
// Obter valor da métrica correspondente, validando tipo número
|
||||
const rawValue = (metrica as Record<string, unknown>)[alerta.metricName];
|
||||
if (typeof rawValue !== "number") continue;
|
||||
const metricValue = rawValue;
|
||||
|
||||
// Verificar se o alerta deve ser disparado
|
||||
let shouldTrigger = false;
|
||||
@@ -353,11 +366,16 @@ export const verificarAlertasInternal = internalMutation({
|
||||
|
||||
// Criar notificação no chat se configurado
|
||||
if (alerta.notifyByChat) {
|
||||
// Buscar usuários TI para notificar
|
||||
// Buscar roles administrativas (nível <= 1) e filtrar usuários por roleId
|
||||
const rolesAdminOuTi = await ctx.db
|
||||
.query("roles")
|
||||
.filter((q) => q.lte(q.field("nivel"), 1))
|
||||
.collect();
|
||||
|
||||
const rolesPermitidas = new Set(rolesAdminOuTi.map((r) => r._id));
|
||||
|
||||
const usuarios = await ctx.db.query("usuarios").collect();
|
||||
const usuariosTI = usuarios.filter(
|
||||
(u) => u.role?.nome === "ti" || u.role?.nivel === 0
|
||||
);
|
||||
const usuariosTI = usuarios.filter((u) => rolesPermitidas.has(u.roleId));
|
||||
|
||||
for (const usuario of usuariosTI) {
|
||||
await ctx.db.insert("notificacoes", {
|
||||
|
||||
Reference in New Issue
Block a user