adiciona funcionarios pagina
This commit is contained in:
4
packages/backend/convex/_generated/api.d.ts
vendored
4
packages/backend/convex/_generated/api.d.ts
vendored
@@ -13,8 +13,10 @@ import type * as betterAuth__generated_api from "../betterAuth/_generated/api.js
|
||||
import type * as betterAuth__generated_server from "../betterAuth/_generated/server.js";
|
||||
import type * as betterAuth_adapter from "../betterAuth/adapter.js";
|
||||
import type * as betterAuth_auth from "../betterAuth/auth.js";
|
||||
import type * as funcionarios from "../funcionarios.js";
|
||||
import type * as healthCheck from "../healthCheck.js";
|
||||
import type * as http from "../http.js";
|
||||
import type * as simbolos from "../simbolos.js";
|
||||
import type * as todos from "../todos.js";
|
||||
|
||||
import type {
|
||||
@@ -37,8 +39,10 @@ declare const fullApi: ApiFromModules<{
|
||||
"betterAuth/_generated/server": typeof betterAuth__generated_server;
|
||||
"betterAuth/adapter": typeof betterAuth_adapter;
|
||||
"betterAuth/auth": typeof betterAuth_auth;
|
||||
funcionarios: typeof funcionarios;
|
||||
healthCheck: typeof healthCheck;
|
||||
http: typeof http;
|
||||
simbolos: typeof simbolos;
|
||||
todos: typeof todos;
|
||||
}>;
|
||||
declare const fullApiWithMounts: typeof fullApi;
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
import { v } from "convex/values";
|
||||
import { query, mutation } from "./_generated/server";
|
||||
|
||||
export const getAll = query({
|
||||
handler: async (ctx) => {
|
||||
return await ctx.db.query("funcionarios").collect();
|
||||
},
|
||||
});
|
||||
|
||||
export const create = mutation({
|
||||
args: {
|
||||
nome: v.string(),
|
||||
matricula: v.string(),
|
||||
simboloId: v.id("simbolos"),
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const novoFuncionarioId = await ctx.db.insert("funcionarios", {
|
||||
nome: args.nome,
|
||||
matricula: args.matricula,
|
||||
simboloId: args.simboloId,
|
||||
});
|
||||
return await ctx.db.get(novoFuncionarioId);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
import { defineSchema, defineTable } from "convex/server";
|
||||
import { v } from "convex/values";
|
||||
import { Infer, v } from "convex/values";
|
||||
import { tables } from "./betterAuth/schema";
|
||||
|
||||
export const simboloTipo = v.union(
|
||||
v.literal("cargo_comissionado"),
|
||||
v.literal("funcao_gratificada")
|
||||
);
|
||||
export type SimboloTipo = Infer<typeof simboloTipo>;
|
||||
|
||||
export default defineSchema({
|
||||
...tables,
|
||||
todos: defineTable({
|
||||
@@ -20,13 +26,21 @@ export default defineSchema({
|
||||
telefone: v.optional(v.string()),
|
||||
email: v.optional(v.string()),
|
||||
matricula: v.string(),
|
||||
simbolo: v.optional(v.string()),
|
||||
vencimento: v.optional(v.string()),
|
||||
admissao: v.optional(v.string()),
|
||||
desligamento: v.optional(v.string()),
|
||||
ferias: v.optional(v.string()),
|
||||
atestado: v.optional(v.string()),
|
||||
simboloId: v.id("simbolos"),
|
||||
})
|
||||
.index("by_matricula", ["matricula"])
|
||||
.index("by_nome", ["nome"]),
|
||||
|
||||
simbolos: defineTable({
|
||||
nome: v.string(),
|
||||
tipo: simboloTipo,
|
||||
descricao: v.string(),
|
||||
vencValor: v.string(),
|
||||
repValor: v.string(),
|
||||
valor: v.string(),
|
||||
}),
|
||||
});
|
||||
|
||||
50
packages/backend/convex/simbolos.ts
Normal file
50
packages/backend/convex/simbolos.ts
Normal 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);
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user