fix: function convertTemplate
This commit is contained in:
parent
807c812b1a
commit
aef712b409
1 changed files with 21 additions and 2 deletions
|
|
@ -4,12 +4,31 @@ const templates = {
|
|||
return context?.join(', ') || '';
|
||||
},
|
||||
},
|
||||
'quotation-payment': {
|
||||
converter: (context?: {
|
||||
paymentType: 'full' | 'installments';
|
||||
installments: {
|
||||
date: string;
|
||||
amount: number;
|
||||
}[];
|
||||
}) => {
|
||||
return (
|
||||
context?.installments
|
||||
.map(
|
||||
(v) =>
|
||||
`asdasd
|
||||
`,
|
||||
)
|
||||
.join(', ') || ''
|
||||
);
|
||||
},
|
||||
},
|
||||
} as const;
|
||||
|
||||
type Template = typeof templates;
|
||||
type TemplateName = keyof Template;
|
||||
type TemplateContext = {
|
||||
[key in TemplateName]: Parameters<Template[TemplateName]['converter']>[0];
|
||||
[key in TemplateName]: Parameters<Template[key]['converter']>[0];
|
||||
};
|
||||
|
||||
export function convertTemplate(
|
||||
|
|
@ -25,7 +44,7 @@ export function convertTemplate(
|
|||
ret = text.replace(
|
||||
new RegExp('\\#\\[' + name.replaceAll('-', '\\-') + '\\]', 'g'),
|
||||
typeof template.converter === 'function'
|
||||
? template.converter(context?.[name as TemplateName])
|
||||
? template.converter(context?.[name as TemplateName] as any)
|
||||
: template.converter,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue