refactor(api): extract calculation rule support

This commit is contained in:
2026-03-31 14:00:22 +02:00
parent 46aa038229
commit 6aa0625c8c
3 changed files with 126 additions and 26 deletions
@@ -0,0 +1,43 @@
import type { Prisma } from "@capakraken/db";
import {
CreateCalculationRuleSchema,
UpdateCalculationRuleSchema,
} from "@capakraken/shared";
import { z } from "zod";
type CreateCalculationRuleInput = z.infer<typeof CreateCalculationRuleSchema>;
type UpdateCalculationRuleInput = Omit<z.infer<typeof UpdateCalculationRuleSchema>, "id">;
export function buildCalculationRuleCreateData(
input: CreateCalculationRuleInput,
): Prisma.CalculationRuleUncheckedCreateInput {
return {
name: input.name,
triggerType: input.triggerType,
costEffect: input.costEffect,
chargeabilityEffect: input.chargeabilityEffect,
...(input.description !== undefined ? { description: input.description } : {}),
...(input.projectId !== undefined ? { projectId: input.projectId } : {}),
...(input.orderType !== undefined ? { orderType: input.orderType as never } : {}),
...(input.costReductionPercent !== undefined ? { costReductionPercent: input.costReductionPercent } : {}),
priority: input.priority,
isActive: input.isActive,
};
}
export function buildCalculationRuleUpdateData(
input: UpdateCalculationRuleInput,
): Prisma.CalculationRuleUncheckedUpdateInput {
return {
...(input.name !== undefined ? { name: input.name } : {}),
...(input.description !== undefined ? { description: input.description } : {}),
...(input.triggerType !== undefined ? { triggerType: input.triggerType } : {}),
...(input.projectId !== undefined ? { projectId: input.projectId } : {}),
...(input.orderType !== undefined ? { orderType: input.orderType as never } : {}),
...(input.costEffect !== undefined ? { costEffect: input.costEffect } : {}),
...(input.costReductionPercent !== undefined ? { costReductionPercent: input.costReductionPercent } : {}),
...(input.chargeabilityEffect !== undefined ? { chargeabilityEffect: input.chargeabilityEffect } : {}),
...(input.priority !== undefined ? { priority: input.priority } : {}),
...(input.isActive !== undefined ? { isActive: input.isActive } : {}),
};
}