Refactor parent template handling in TemplateManager
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
All checks were successful
farmcontrol/farmcontrol-ws/pipeline/head This commit looks good
- Updated the logic to retrieve and validate the parent template content, ensuring it is correctly fetched and checked for string type. - Improved error logging to provide clearer messages when parent template content is missing or invalid.
This commit is contained in:
parent
8c445a7392
commit
53b5924767
@ -427,24 +427,37 @@ export class TemplateManager {
|
|||||||
|
|
||||||
var templateWithParentContent;
|
var templateWithParentContent;
|
||||||
|
|
||||||
|
var parentTemplate = documentTemplate.parent;
|
||||||
|
|
||||||
if (documentTemplate.parent != undefined) {
|
if (documentTemplate.parent != undefined) {
|
||||||
|
if (typeof parentTemplate === 'string') {
|
||||||
|
parentTemplate = await getObject({
|
||||||
|
model: documentTemplateModel,
|
||||||
|
id: parentTemplate,
|
||||||
|
populate: [
|
||||||
|
{ path: 'documentSize' },
|
||||||
|
{ path: 'parent', strictPopulate: false }
|
||||||
|
],
|
||||||
|
cached: true
|
||||||
|
});
|
||||||
|
}
|
||||||
// Validate parent content
|
// Validate parent content
|
||||||
if (
|
if (
|
||||||
documentTemplate.parent.content == null ||
|
parentTemplate.content == null ||
|
||||||
typeof documentTemplate.parent.content !== 'string'
|
typeof parentTemplate.content !== 'string'
|
||||||
) {
|
) {
|
||||||
logger.error(
|
logger.error(
|
||||||
'Parent template content is required and must be a string.',
|
'Parent template content is required and must be a string.',
|
||||||
documentTemplate.parent.content
|
parentTemplate.content
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
error:
|
error:
|
||||||
'Parent template content is required and must be a string.' +
|
'Parent template content is required and must be a string.' +
|
||||||
documentTemplate.parent.content
|
parentTemplate.content
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
templateWithParentContent = await ejs.render(
|
templateWithParentContent = await ejs.render(
|
||||||
documentTemplate.parent.content,
|
parentTemplate.content,
|
||||||
{ content: templateContent, fc: this.fc },
|
{ content: templateContent, fc: this.fc },
|
||||||
defaultOptions
|
defaultOptions
|
||||||
);
|
);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user