feat: Endpoints para imprimir templates y operaciones con variables
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 36s

- POST /api/print/template: Imprime un template guardado por ID con variables
- POST /api/print/raw: Imprime operaciones arbitrarias con soporte de variables inline
- Agregada función resolveVariables() en server/utils/templates.ts
This commit is contained in:
2025-11-25 11:10:57 -06:00
parent 845c89be04
commit 1d5838de6c
3 changed files with 202 additions and 0 deletions

View File

@@ -55,6 +55,21 @@ export function extractVariables(operations: Operation[]): TemplateVariable[] {
return Array.from(variablesMap.values())
}
// Resolver variables en operaciones reemplazando {{nombre}} con valores
export function resolveVariables(
operations: Operation[],
values: Record<string, string> = {}
): Operation[] {
return JSON.parse(JSON.stringify(operations)).map((op: Operation) => {
for (const [key, val] of Object.entries(op)) {
if (typeof val === 'string') {
op[key] = val.replace(VARIABLE_REGEX, (_, name) => values[name] ?? '')
}
}
return op
})
}
export interface TemplatesStore {
templates: PrintTemplate[]
}