This commit is contained in:
seb
2026-11-01 05:37:15 +01:00
parent e6c15dd053
commit 8f9c941699
32 changed files with 145 additions and 210 deletions

View File

@@ -8,7 +8,7 @@ import { pngToZpl } from '../../services/zplService.js';
import { notifyAgentJob } from '../agent/index.js';
import { emit } from '../sse.js';
import { applyZplCopies } from './zpljob.js';
import { interpolateString } from './article/shared.js';
import { interpolateString, interpolateObjects } from './article/shared.js';
// #region Helpers
@@ -590,16 +590,15 @@ export function register(app, basePath = '') {
// Resolve sample article for placeholder interpolation
let article = null;
if (req.body?.sku) {
try {
const result = await articleDb.getBySku(req.user.id, req.body.sku);
article = result?.article;
} catch {
// ignore
const skuStr = String(req.body.sku).trim();
const result = await articleDb.getBySku(req.user.id, skuStr);
if (!result?.article) {
return res.status(404).json({ error: 'Article not found' });
}
}
if (!article) {
article = result.article;
} else {
article = {
name: req.body?.name || template?.name || 'Musterartikel',
name: template?.name || 'Musterartikel',
sku: 'TEST-12345',
prices: [{ net: 19.99, taxRate: 19 }],
eans: ['4012345678901'],
@@ -625,16 +624,7 @@ export function register(app, basePath = '') {
objects = [];
}
const interpolatedObjects = objects.map((obj) => {
const cloned = { ...obj };
if (typeof cloned.text === 'string') {
cloned.text = interpolateString(cloned.text, article);
}
if (typeof cloned.code === 'string') {
cloned.code = interpolateString(cloned.code, article);
}
return cloned;
});
const interpolatedObjects = interpolateObjects(objects, article);
const printPayload = await renderLabel({
width: width || 448,