feat: Implement initial pedido (order) management, product catalog, and TI configuration features.
This commit is contained in:
38
packages/backend/convex/config.ts
Normal file
38
packages/backend/convex/config.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import { mutation, query } from './_generated/server';
|
||||
import { v } from 'convex/values';
|
||||
import { getCurrentUserFunction } from './auth';
|
||||
|
||||
export const getComprasSetor = query({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
return await ctx.db.query('config').first();
|
||||
}
|
||||
});
|
||||
|
||||
export const updateComprasSetor = mutation({
|
||||
args: {
|
||||
setorId: v.id('setores')
|
||||
},
|
||||
handler: async (ctx, args) => {
|
||||
const user = await getCurrentUserFunction(ctx);
|
||||
if (!user) throw new Error('Unauthorized');
|
||||
|
||||
// Check if user has permission (e.g., admin or TI) - For now, assuming any auth user can set it,
|
||||
// but in production should be restricted.
|
||||
|
||||
const existingConfig = await ctx.db.query('config').first();
|
||||
|
||||
if (existingConfig) {
|
||||
await ctx.db.patch(existingConfig._id, {
|
||||
comprasSetorId: args.setorId,
|
||||
atualizadoEm: Date.now()
|
||||
});
|
||||
} else {
|
||||
await ctx.db.insert('config', {
|
||||
comprasSetorId: args.setorId,
|
||||
criadoPor: user._id,
|
||||
atualizadoEm: Date.now()
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user