feat: Add planning cloning functionality to list and detail pages with backend support.
This commit is contained in:
@@ -177,7 +177,8 @@ export const create = mutation({
|
||||
descricao: v.string(),
|
||||
data: v.string(),
|
||||
responsavelId: v.id('funcionarios'),
|
||||
acaoId: v.optional(v.id('acoes'))
|
||||
acaoId: v.optional(v.id('acoes')),
|
||||
sourcePlanningId: v.optional(v.id('planejamentosPedidos'))
|
||||
},
|
||||
returns: v.id('planejamentosPedidos'),
|
||||
handler: async (ctx, args) => {
|
||||
@@ -192,7 +193,7 @@ export const create = mutation({
|
||||
if (!descricao) throw new Error('Informe uma descrição.');
|
||||
if (!data) throw new Error('Informe uma data.');
|
||||
|
||||
return await ctx.db.insert('planejamentosPedidos', {
|
||||
const newItemId = await ctx.db.insert('planejamentosPedidos', {
|
||||
titulo,
|
||||
descricao,
|
||||
data,
|
||||
@@ -203,6 +204,30 @@ export const create = mutation({
|
||||
criadoEm: now,
|
||||
atualizadoEm: now
|
||||
});
|
||||
|
||||
const sourcePlanningId = args.sourcePlanningId;
|
||||
|
||||
if (sourcePlanningId) {
|
||||
const sourceItems = await ctx.db
|
||||
.query('planejamentoItens')
|
||||
.withIndex('by_planejamentoId', (q) => q.eq('planejamentoId', sourcePlanningId))
|
||||
.collect();
|
||||
|
||||
for (const item of sourceItems) {
|
||||
await ctx.db.insert('planejamentoItens', {
|
||||
planejamentoId: newItemId,
|
||||
objetoId: item.objetoId,
|
||||
quantidade: item.quantidade,
|
||||
valorEstimado: item.valorEstimado,
|
||||
numeroDfd: item.numeroDfd,
|
||||
// Não copiamos o pedidoId pois é um novo planejamento
|
||||
criadoEm: now,
|
||||
atualizadoEm: now
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return newItemId;
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user