adiciona funcionarios pagina

This commit is contained in:
2025-10-24 08:53:15 -03:00
parent 9d17ad1271
commit aafee4b654
14 changed files with 564 additions and 9 deletions

View File

@@ -0,0 +1,50 @@
import { v } from "convex/values";
import { query, mutation } from "./_generated/server";
import { simboloTipo } from "./schema";
export const getAll = query({
handler: async (ctx) => {
return await ctx.db.query("simbolos").collect();
},
});
export const create = mutation({
args: {
nome: v.string(),
tipo: simboloTipo,
refValor: v.string(),
vencValor: v.string(),
descricao: v.string(),
valor: v.optional(v.string()),
},
handler: async (ctx, args) => {
let refValor = args.refValor;
let vencValor = args.vencValor;
let valor = args.valor ?? "";
if (args.tipo === "cargo_comissionado") {
if (!refValor || !vencValor) {
throw new Error(
"Valor de referência e valor de vencimento são obrigatórios para cargo comissionado"
);
}
valor = (Number(refValor) + Number(vencValor)).toFixed(2);
} else {
if (!args.valor) {
throw new Error("Valor é obrigatório para função gratificada");
}
refValor = "";
vencValor = "";
valor = args.valor;
}
const novoSimboloId = await ctx.db.insert("simbolos", {
nome: args.nome,
descricao: args.descricao,
repValor: refValor,
vencValor: vencValor,
tipo: args.tipo,
valor,
});
return await ctx.db.get(novoSimboloId);
},
});