u
This commit is contained in:
@@ -14,7 +14,6 @@ import {
|
|||||||
parseFullHash,
|
parseFullHash,
|
||||||
articleErrorStatus,
|
articleErrorStatus,
|
||||||
interpolateString,
|
interpolateString,
|
||||||
interpolateObjects,
|
|
||||||
} from './shared.js';
|
} from './shared.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -403,7 +402,7 @@ export function register(app, basePath = '') {
|
|||||||
if (!template || template.company_id !== companyId) {
|
if (!template || template.company_id !== companyId) {
|
||||||
return res.status(404).json({ error: 'Label template not found' });
|
return res.status(404).json({ error: 'Label template not found' });
|
||||||
}
|
}
|
||||||
|
|
||||||
let article;
|
let article;
|
||||||
try {
|
try {
|
||||||
const result = await db.getBySku(req.user.id, sku);
|
const result = await db.getBySku(req.user.id, sku);
|
||||||
@@ -434,7 +433,16 @@ export function register(app, basePath = '') {
|
|||||||
? content
|
? 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({
|
const printPayload = await renderLabel({
|
||||||
width: template.width,
|
width: template.width,
|
||||||
@@ -460,7 +468,7 @@ export function register(app, basePath = '') {
|
|||||||
console.error('Print article label failed:', error);
|
console.error('Print article label failed:', error);
|
||||||
res.status(500).json({ error: error.message });
|
res.status(500).json({ error: error.message });
|
||||||
|
|
||||||
// #endregion
|
// #endregion
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,10 +96,12 @@ export function register(app, basePath = '') {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
const templates = await db.list(req.user.id);
|
const templates = await db.list(req.user.id);
|
||||||
res.status(200).json({ labeltemplates: templates.map((t) => {
|
res.status(200).json({
|
||||||
const { content, ...rest } = serializeTemplate(t);
|
labeltemplates: templates.map((t) => {
|
||||||
return rest;
|
const { content, ...rest } = serializeTemplate(t);
|
||||||
}) });
|
return rest;
|
||||||
|
})
|
||||||
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const status = labeltemplateErrorStatus(error);
|
const status = labeltemplateErrorStatus(error);
|
||||||
if (status === 500) console.error('List label templates failed:', error);
|
if (status === 500) console.error('List label templates failed:', error);
|
||||||
|
|||||||
Reference in New Issue
Block a user