mirror of
https://github.com/Tria-plc/edr-platform.git
synced 2026-08-29 18:48:11 +00:00
make a contrat template
This commit is contained in:
@@ -3,6 +3,11 @@ import * as fs from 'fs';
|
||||
import * as path from 'path';
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import {
|
||||
interpolateTemplateText,
|
||||
parseArticleBody,
|
||||
RenderedArticle,
|
||||
} from './contract-article.util';
|
||||
import { ContractViewModel } from './contract-view-model.builder';
|
||||
|
||||
@Injectable()
|
||||
@@ -31,9 +36,40 @@ export class ContractRendererService implements OnModuleInit {
|
||||
return template({
|
||||
...view,
|
||||
paymentArticle: view.pricing.currency === 'ETB' ? 'ETB' : 'USD',
|
||||
...this.buildDynamicSections(view),
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Turn the DB-backed dynamic template (when present) into render-ready data:
|
||||
* interpolate placeholders against the view model, then parse each article
|
||||
* body into numbered clauses with nested bullets.
|
||||
*/
|
||||
private buildDynamicSections(view: ContractViewModel): {
|
||||
dynamicDocumentTitle?: string;
|
||||
dynamicWhereas?: string[];
|
||||
dynamicArticles?: RenderedArticle[];
|
||||
} {
|
||||
const dyn = view.dynamicTemplate;
|
||||
if (!dyn || dyn.articles.length === 0) return {};
|
||||
|
||||
const articles = [...dyn.articles]
|
||||
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
|
||||
.map((article, index) => ({
|
||||
number: index + 1,
|
||||
title: interpolateTemplateText(article.title, view),
|
||||
...parseArticleBody(interpolateTemplateText(article.body, view)),
|
||||
}));
|
||||
|
||||
return {
|
||||
dynamicDocumentTitle: interpolateTemplateText(dyn.documentTitle, view),
|
||||
dynamicWhereas: dyn.whereasClauses.map((clause) =>
|
||||
interpolateTemplateText(clause, view),
|
||||
),
|
||||
dynamicArticles: articles,
|
||||
};
|
||||
}
|
||||
|
||||
private getCompiled(fileName: string): Handlebars.TemplateDelegate {
|
||||
const cached = this.compiled.get(fileName);
|
||||
if (cached) return cached;
|
||||
|
||||
Reference in New Issue
Block a user