feat: Add 'atas' (minutes/records) management feature, and implement various improvements across UI, backend logic, and authentication.

This commit is contained in:
2025-12-02 16:37:48 -03:00
parent 05e7f1181d
commit 4bd9e21748
265 changed files with 29156 additions and 26460 deletions

View File

@@ -0,0 +1,81 @@
import { v } from 'convex/values';
import { mutation, query } from './_generated/server';
import { getCurrentUserFunction } from './auth';
export const list = query({
args: {},
handler: async (ctx) => {
return await ctx.db.query('objetos').collect();
}
});
export const search = query({
args: { query: v.string() },
handler: async (ctx, args) => {
return await ctx.db
.query('objetos')
.withSearchIndex('search_nome', (q) => q.search('nome', args.query))
.take(10);
}
});
export const create = mutation({
args: {
nome: v.string(),
valorEstimado: v.string(),
tipo: v.union(v.literal('material'), v.literal('servico')),
codigoEfisco: v.string(),
codigoCatmat: v.optional(v.string()),
codigoCatserv: v.optional(v.string()),
unidade: v.string()
},
handler: async (ctx, args) => {
const user = await getCurrentUserFunction(ctx);
if (!user) throw new Error('Unauthorized');
return await ctx.db.insert('objetos', {
...args,
criadoPor: user._id,
criadoEm: Date.now()
});
}
});
export const update = mutation({
args: {
id: v.id('objetos'),
nome: v.string(),
valorEstimado: v.string(),
tipo: v.union(v.literal('material'), v.literal('servico')),
codigoEfisco: v.string(),
codigoCatmat: v.optional(v.string()),
codigoCatserv: v.optional(v.string()),
unidade: v.string()
},
handler: async (ctx, args) => {
const user = await getCurrentUserFunction(ctx);
if (!user) throw new Error('Unauthorized');
await ctx.db.patch(args.id, {
nome: args.nome,
valorEstimado: args.valorEstimado,
tipo: args.tipo,
codigoEfisco: args.codigoEfisco,
codigoCatmat: args.codigoCatmat,
codigoCatserv: args.codigoCatserv,
unidade: args.unidade
});
}
});
export const remove = mutation({
args: {
id: v.id('objetos')
},
handler: async (ctx, args) => {
const user = await getCurrentUserFunction(ctx);
if (!user) throw new Error('Unauthorized');
await ctx.db.delete(args.id);
}
});