feat(IncidentEpisodeService): enhance incident count update with dynamic title and description templates

This commit is contained in:
Nawaz Dhandala
2026-02-09 21:15:56 +00:00
parent cd450bc3b6
commit dbb1fa6c18

View File

@@ -712,15 +712,68 @@ export class Service extends DatabaseService<Model> {
},
});
await this.updateOneById({
const incidentCount: number = count.toNumber();
// Get the episode to check for templates
const episode: Model | null = await this.findOneById({
id: episodeId,
data: {
incidentCount: count.toNumber(),
select: {
titleTemplate: true,
descriptionTemplate: true,
title: true,
description: true,
},
props: {
isRoot: true,
},
});
const updateData: {
incidentCount: number;
title?: string;
description?: string;
} = {
incidentCount: incidentCount,
};
// Update title with dynamic variables if template exists
if (episode?.titleTemplate) {
updateData.title = this.renderTemplateWithDynamicValues(
episode.titleTemplate,
incidentCount,
);
}
// Update description with dynamic variables if template exists
if (episode?.descriptionTemplate) {
updateData.description = this.renderTemplateWithDynamicValues(
episode.descriptionTemplate,
incidentCount,
);
}
await this.updateOneById({
id: episodeId,
data: updateData,
props: {
isRoot: true,
},
});
}
private renderTemplateWithDynamicValues(
template: string,
incidentCount: number,
): string {
let result: string = template;
// Replace dynamic variables
result = result.replace(
/\{\{incidentCount\}\}/g,
incidentCount.toString(),
);
return result;
}
@CaptureSpan()