refactor: improve type safety and error handling in vacation management components

- Updated the `AprovarFerias.svelte` component to use specific types for `solicitacao` and `gestorId`, enhancing type safety.
- Improved error handling by refining catch blocks to handle errors more accurately.
- Made minor adjustments to ensure consistent code formatting and readability across the component.
This commit is contained in:
2025-10-31 13:39:41 -03:00
parent 5dec7d7da7
commit 5cb63f9437
20 changed files with 155 additions and 112 deletions

View File

@@ -38,7 +38,7 @@ export const executar = internalMutation({
}
// 2. Agrupar funcionários por gestor
const gestoresMap = new Map<string, any[]>();
const gestoresMap = new Map<string, Doc<"funcionarios">[]>();
for (const funcionario of funcionariosComGestor) {
if (!funcionario.gestorId) continue;
@@ -53,7 +53,7 @@ export const executar = internalMutation({
// 3. Para cada gestor, criar um time
for (const [gestorId, subordinados] of gestoresMap.entries()) {
try {
const gestor = await ctx.db.get(gestorId as any);
const gestor = await ctx.db.get(gestorId);
if (!gestor) {
erros.push(`Gestor ${gestorId} não encontrado`);
@@ -63,7 +63,7 @@ export const executar = internalMutation({
// Verificar se já existe time para este gestor
const timeExistente = await ctx.db
.query("times")
.withIndex("by_gestor", (q) => q.eq("gestorId", gestorId as any))
.withIndex("by_gestor", (q) => q.eq("gestorId", gestorId))
.filter((q) => q.eq(q.field("ativo"), true))
.first();
@@ -76,7 +76,7 @@ export const executar = internalMutation({
timeId = await ctx.db.insert("times", {
nome: `Equipe ${gestor.nome}`,
descricao: `Time gerenciado por ${gestor.nome} (migração automática)`,
gestorId: gestorId as any,
gestorId: gestorId,
ativo: true,
cor: "#3B82F6",
});
@@ -102,7 +102,7 @@ export const executar = internalMutation({
});
funcionariosAtribuidos++;
}
} catch (e: any) {
} catch (e) {
erros.push(`Erro ao adicionar ${funcionario.nome} ao time: ${e.message}`);
}
}