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 parentTemplate = documentTemplate.parent;
|
||||
|
||||
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
|
||||
if (
|
||||
documentTemplate.parent.content == null ||
|
||||
typeof documentTemplate.parent.content !== 'string'
|
||||
parentTemplate.content == null ||
|
||||
typeof parentTemplate.content !== 'string'
|
||||
) {
|
||||
logger.error(
|
||||
'Parent template content is required and must be a string.',
|
||||
documentTemplate.parent.content
|
||||
parentTemplate.content
|
||||
);
|
||||
return {
|
||||
error:
|
||||
'Parent template content is required and must be a string.' +
|
||||
documentTemplate.parent.content
|
||||
parentTemplate.content
|
||||
};
|
||||
}
|
||||
templateWithParentContent = await ejs.render(
|
||||
documentTemplate.parent.content,
|
||||
parentTemplate.content,
|
||||
{ content: templateContent, fc: this.fc },
|
||||
defaultOptions
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user