feat: update ESLint and TypeScript configurations across frontend and backend; enhance component structure and improve data handling in various modules

This commit is contained in:
2025-12-02 16:36:02 -03:00
parent f48d28067c
commit d79e6959c3
215 changed files with 29474 additions and 28173 deletions

View File

@@ -1,152 +1,144 @@
import { query } from "./_generated/server";
import { v } from "convex/values";
import { query } from './_generated/server';
import { v } from 'convex/values';
// Obter estatísticas gerais do sistema
export const getStats = query({
args: {},
returns: v.object({
totalFuncionarios: v.number(),
totalSimbolos: v.number(),
funcionariosAtivos: v.number(),
funcionariosDesligados: v.number(),
cargoComissionado: v.number(),
funcaoGratificada: v.number(),
}),
handler: async (ctx) => {
// Contar funcionários
const funcionarios = await ctx.db.query("funcionarios").collect();
const totalFuncionarios = funcionarios.length;
// Funcionários ativos (sem data de desligamento)
const funcionariosAtivos = funcionarios.filter(
(f) => !f.desligamentoData
).length;
// Funcionários desligados
const funcionariosDesligados = funcionarios.filter(
(f) => f.desligamentoData
).length;
args: {},
returns: v.object({
totalFuncionarios: v.number(),
totalSimbolos: v.number(),
funcionariosAtivos: v.number(),
funcionariosDesligados: v.number(),
cargoComissionado: v.number(),
funcaoGratificada: v.number()
}),
handler: async (ctx) => {
// Contar funcionários
const funcionarios = await ctx.db.query('funcionarios').collect();
const totalFuncionarios = funcionarios.length;
// Contar por tipo de símbolo
const cargoComissionado = funcionarios.filter(
(f) => f.simboloTipo === "cargo_comissionado"
).length;
const funcaoGratificada = funcionarios.filter(
(f) => f.simboloTipo === "funcao_gratificada"
).length;
// Funcionários ativos (sem data de desligamento)
const funcionariosAtivos = funcionarios.filter((f) => !f.desligamentoData).length;
// Contar símbolos
const simbolos = await ctx.db.query("simbolos").collect();
const totalSimbolos = simbolos.length;
// Funcionários desligados
const funcionariosDesligados = funcionarios.filter((f) => f.desligamentoData).length;
return {
totalFuncionarios,
totalSimbolos,
funcionariosAtivos,
funcionariosDesligados,
cargoComissionado,
funcaoGratificada,
};
},
// Contar por tipo de símbolo
const cargoComissionado = funcionarios.filter(
(f) => f.simboloTipo === 'cargo_comissionado'
).length;
const funcaoGratificada = funcionarios.filter(
(f) => f.simboloTipo === 'funcao_gratificada'
).length;
// Contar símbolos
const simbolos = await ctx.db.query('simbolos').collect();
const totalSimbolos = simbolos.length;
return {
totalFuncionarios,
totalSimbolos,
funcionariosAtivos,
funcionariosDesligados,
cargoComissionado,
funcaoGratificada
};
}
});
// Obter atividades recentes (últimas 24 horas)
export const getRecentActivity = query({
args: {},
returns: v.object({
funcionariosCadastrados24h: v.number(),
simbolosCadastrados24h: v.number(),
}),
handler: async (ctx) => {
const now = Date.now();
const last24h = now - 24 * 60 * 60 * 1000;
args: {},
returns: v.object({
funcionariosCadastrados24h: v.number(),
simbolosCadastrados24h: v.number()
}),
handler: async (ctx) => {
const now = Date.now();
const last24h = now - 24 * 60 * 60 * 1000;
// Funcionários cadastrados nas últimas 24h
const funcionarios = await ctx.db.query("funcionarios").collect();
const funcionariosCadastrados24h = funcionarios.filter(
(f) => f._creationTime >= last24h
).length;
// Funcionários cadastrados nas últimas 24h
const funcionarios = await ctx.db.query('funcionarios').collect();
const funcionariosCadastrados24h = funcionarios.filter(
(f) => f._creationTime >= last24h
).length;
// Símbolos cadastrados nas últimas 24h
const simbolos = await ctx.db.query('simbolos').collect();
const simbolosCadastrados24h = simbolos.filter((s) => s._creationTime >= last24h).length;
// Símbolos cadastrados nas últimas 24h
const simbolos = await ctx.db.query("simbolos").collect();
const simbolosCadastrados24h = simbolos.filter(
(s) => s._creationTime >= last24h
).length;
return {
funcionariosCadastrados24h,
simbolosCadastrados24h,
};
},
return {
funcionariosCadastrados24h,
simbolosCadastrados24h
};
}
});
// Obter distribuição de funcionários por cidade
export const getFuncionariosPorCidade = query({
args: {},
returns: v.array(
v.object({
cidade: v.string(),
quantidade: v.number(),
})
),
handler: async (ctx) => {
const funcionarios = await ctx.db.query("funcionarios").collect();
const cidadesMap: Record<string, number> = {};
for (const func of funcionarios) {
if (!func.desligamentoData) {
cidadesMap[func.cidade] = (cidadesMap[func.cidade] || 0) + 1;
}
}
args: {},
returns: v.array(
v.object({
cidade: v.string(),
quantidade: v.number()
})
),
handler: async (ctx) => {
const funcionarios = await ctx.db.query('funcionarios').collect();
const result = Object.entries(cidadesMap)
.map(([cidade, quantidade]) => ({ cidade, quantidade }))
.sort((a, b) => b.quantidade - a.quantidade)
.slice(0, 5); // Top 5 cidades
const cidadesMap: Record<string, number> = {};
return result;
},
for (const func of funcionarios) {
if (!func.desligamentoData) {
cidadesMap[func.cidade] = (cidadesMap[func.cidade] || 0) + 1;
}
}
const result = Object.entries(cidadesMap)
.map(([cidade, quantidade]) => ({ cidade, quantidade }))
.sort((a, b) => b.quantidade - a.quantidade)
.slice(0, 5); // Top 5 cidades
return result;
}
});
// Obter evolução de cadastros por mês
export const getEvolucaoCadastros = query({
args: {},
returns: v.array(
v.object({
mes: v.string(),
funcionarios: v.number(),
})
),
handler: async (ctx) => {
const funcionarios = await ctx.db.query("funcionarios").collect();
args: {},
returns: v.array(
v.object({
mes: v.string(),
funcionarios: v.number()
})
),
handler: async (ctx) => {
const funcionarios = await ctx.db.query('funcionarios').collect();
const now = new Date();
const meses: Array<{ mes: string; funcionarios: number }> = [];
const now = new Date();
const meses: Array<{ mes: string; funcionarios: number }> = [];
// Últimos 6 meses
for (let i = 5; i >= 0; i--) {
const date = new Date(now.getFullYear(), now.getMonth() - i, 1);
const nextDate = new Date(now.getFullYear(), now.getMonth() - i + 1, 1);
const mesNome = date.toLocaleDateString("pt-BR", {
month: "short",
year: "2-digit",
});
// Últimos 6 meses
for (let i = 5; i >= 0; i--) {
const date = new Date(now.getFullYear(), now.getMonth() - i, 1);
const nextDate = new Date(now.getFullYear(), now.getMonth() - i + 1, 1);
const funcCount = funcionarios.filter(
(f) => f._creationTime >= date.getTime() && f._creationTime < nextDate.getTime()
).length;
const mesNome = date.toLocaleDateString('pt-BR', {
month: 'short',
year: '2-digit'
});
meses.push({
mes: mesNome,
funcionarios: funcCount,
});
}
const funcCount = funcionarios.filter(
(f) => f._creationTime >= date.getTime() && f._creationTime < nextDate.getTime()
).length;
return meses;
},
meses.push({
mes: mesNome,
funcionarios: funcCount
});
}
return meses;
}
});