feat: Endpoints para imprimir templates y operaciones con variables
All checks were successful
build-and-deploy / build-and-deploy (push) Successful in 36s
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:
@@ -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[]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user