|
@@ -94,6 +94,7 @@ export class PromotionService {
|
|
|
enabled: input.enabled,
|
|
enabled: input.enabled,
|
|
|
conditions: input.conditions.map(c => this.parseOperationArgs('condition', c)),
|
|
conditions: input.conditions.map(c => this.parseOperationArgs('condition', c)),
|
|
|
actions: input.actions.map(a => this.parseOperationArgs('action', a)),
|
|
actions: input.actions.map(a => this.parseOperationArgs('action', a)),
|
|
|
|
|
+ priorityScore: this.calculatePriorityScore(input),
|
|
|
});
|
|
});
|
|
|
this.channelService.assignToChannels(adjustmentSource, ctx);
|
|
this.channelService.assignToChannels(adjustmentSource, ctx);
|
|
|
const newAdjustmentSource = await this.connection.manager.save(adjustmentSource);
|
|
const newAdjustmentSource = await this.connection.manager.save(adjustmentSource);
|
|
@@ -118,7 +119,8 @@ export class PromotionService {
|
|
|
if (input.actions) {
|
|
if (input.actions) {
|
|
|
updatedAdjustmentSource.actions = input.actions.map(a => this.parseOperationArgs('action', a));
|
|
updatedAdjustmentSource.actions = input.actions.map(a => this.parseOperationArgs('action', a));
|
|
|
}
|
|
}
|
|
|
- await this.connection.manager.save(updatedAdjustmentSource);
|
|
|
|
|
|
|
+ (adjustmentSource.priorityScore = this.calculatePriorityScore(input)),
|
|
|
|
|
+ await this.connection.manager.save(updatedAdjustmentSource);
|
|
|
await this.updatePromotions();
|
|
await this.updatePromotions();
|
|
|
return assertFound(this.findOne(updatedAdjustmentSource.id));
|
|
return assertFound(this.findOne(updatedAdjustmentSource.id));
|
|
|
}
|
|
}
|
|
@@ -145,6 +147,16 @@ export class PromotionService {
|
|
|
return output;
|
|
return output;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private calculatePriorityScore(input: CreatePromotionInput | UpdatePromotionInput): number {
|
|
|
|
|
+ const conditions = input.conditions
|
|
|
|
|
+ ? input.conditions.map(c => this.getAdjustmentOperationByCode('condition', c.code))
|
|
|
|
|
+ : [];
|
|
|
|
|
+ const actions = input.actions
|
|
|
|
|
+ ? input.actions.map(c => this.getAdjustmentOperationByCode('action', c.code))
|
|
|
|
|
+ : [];
|
|
|
|
|
+ return [...conditions, ...actions].reduce((score, op) => score + op.priorityValue, 0);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private getAdjustmentOperationByCode(
|
|
private getAdjustmentOperationByCode(
|
|
|
type: 'condition' | 'action',
|
|
type: 'condition' | 'action',
|
|
|
code: string,
|
|
code: string,
|