This commit is contained in:
seb
2026-11-01 05:38:45 +01:00
parent 8f9c941699
commit bf081f875d
2 changed files with 18 additions and 8 deletions

View File

@@ -14,7 +14,6 @@ import {
parseFullHash,
articleErrorStatus,
interpolateString,
interpolateObjects,
} from './shared.js';
/**
@@ -403,7 +402,7 @@ export function register(app, basePath = '') {
if (!template || template.company_id !== companyId) {
return res.status(404).json({ error: 'Label template not found' });
}
let article;
try {
const result = await db.getBySku(req.user.id, sku);
@@ -434,7 +433,16 @@ export function register(app, basePath = '') {
? content
: [];
const interpolatedObjects = interpolateObjects(objects, article);
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 printPayload = await renderLabel({
width: template.width,
@@ -460,7 +468,7 @@ export function register(app, basePath = '') {
console.error('Print article label failed:', error);
res.status(500).json({ error: error.message });
// #endregion
// #endregion
}
});
}

View File

@@ -96,10 +96,12 @@ export function register(app, basePath = '') {
try {
const templates = await db.list(req.user.id);
res.status(200).json({ labeltemplates: templates.map((t) => {
const { content, ...rest } = serializeTemplate(t);
return rest;
}) });
res.status(200).json({
labeltemplates: templates.map((t) => {
const { content, ...rest } = serializeTemplate(t);
return rest;
})
});
} catch (error) {
const status = labeltemplateErrorStatus(error);
if (status === 500) console.error('List label templates failed:', error);