Skip to content

Commit

Permalink
Merge pull request #4187 from novuhq/variants-condition
Browse files Browse the repository at this point in the history
Stacked PR - new variants & condition support
  • Loading branch information
LetItRock authored Nov 27, 2023
2 parents 8553343 + 03041c5 commit 4e2c8a2
Show file tree
Hide file tree
Showing 210 changed files with 8,101 additions and 4,555 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
MessageTemplateRepository,
NotificationStepEntity,
NotificationGroupRepository,
StepVariantEntity,
} from '@novu/dal';
import { ChangeEntityTypeEnum } from '@novu/shared';
import {
Expand Down Expand Up @@ -42,7 +43,10 @@ export class PromoteNotificationTemplateChange {
const messages = await this.messageTemplateRepository.find({
_environmentId: command.environmentId,
_parentId: {
$in: newItem.steps ? newItem.steps.map((step) => step._templateId) : [],
$in: (newItem.steps || []).flatMap((step) => [
step._templateId,
...(step.variants || []).flatMap((variant) => variant._templateId),
]),
},
});

Expand All @@ -53,6 +57,30 @@ export class PromoteNotificationTemplateChange {
return message._parentId === step._templateId;
});

if (step.variants && step.variants.length > 0) {
step.variants = step.variants
?.map(mapNewVariantItem)
.filter((variant): variant is StepVariantEntity => variant !== undefined);
}

if (!oldMessage) {
missingMessages.push(step._templateId);

return undefined;
}

if (step?._templateId && oldMessage._id) {
step._templateId = oldMessage._id;
}

return step;
};

const mapNewVariantItem = (step: StepVariantEntity) => {
const oldMessage = messages.find((message) => {
return message._parentId === step._templateId;
});

if (!oldMessage) {
missingMessages.push(step._templateId);

Expand Down
Loading

1 comment on commit 4e2c8a2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.