|
|
@@ -12,13 +12,14 @@ import {
|
|
|
import { PaginatedList } from '../../../../../shared/shared-types';
|
|
|
import { Promotion } from '../../../entity/promotion/promotion.entity';
|
|
|
import { PromotionService } from '../../../service/services/promotion.service';
|
|
|
+import { IdCodecService } from '../../common/id-codec.service';
|
|
|
import { RequestContext } from '../../common/request-context';
|
|
|
import { Allow } from '../../decorators/allow.decorator';
|
|
|
import { Ctx } from '../../decorators/request-context.decorator';
|
|
|
|
|
|
@Resolver('Promotion')
|
|
|
export class PromotionResolver {
|
|
|
- constructor(private promotionService: PromotionService) {}
|
|
|
+ constructor(private promotionService: PromotionService, private idCodecService: IdCodecService) {}
|
|
|
|
|
|
@Query()
|
|
|
@Allow(Permission.ReadSettings)
|
|
|
@@ -26,13 +27,16 @@ export class PromotionResolver {
|
|
|
@Ctx() ctx: RequestContext,
|
|
|
@Args() args: PromotionsQueryArgs,
|
|
|
): Promise<PaginatedList<Promotion>> {
|
|
|
- return this.promotionService.findAll(args.options || undefined);
|
|
|
+ return this.promotionService.findAll(args.options || undefined).then(res => {
|
|
|
+ res.items.forEach(this.encodeConditionsAndActions);
|
|
|
+ return res;
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
@Query()
|
|
|
@Allow(Permission.ReadSettings)
|
|
|
promotion(@Ctx() ctx: RequestContext, @Args() args: PromotionQueryArgs): Promise<Promotion | undefined> {
|
|
|
- return this.promotionService.findOne(args.id);
|
|
|
+ return this.promotionService.findOne(args.id).then(this.encodeConditionsAndActions);
|
|
|
}
|
|
|
|
|
|
@Query()
|
|
|
@@ -48,7 +52,9 @@ export class PromotionResolver {
|
|
|
@Ctx() ctx: RequestContext,
|
|
|
@Args() args: CreatePromotionMutationArgs,
|
|
|
): Promise<Promotion> {
|
|
|
- return this.promotionService.createPromotion(ctx, args.input);
|
|
|
+ this.idCodecService.decodeConfigurableOperation(args.input.actions);
|
|
|
+ this.idCodecService.decodeConfigurableOperation(args.input.conditions);
|
|
|
+ return this.promotionService.createPromotion(ctx, args.input).then(this.encodeConditionsAndActions);
|
|
|
}
|
|
|
|
|
|
@Mutation()
|
|
|
@@ -57,7 +63,9 @@ export class PromotionResolver {
|
|
|
@Ctx() ctx: RequestContext,
|
|
|
@Args() args: UpdatePromotionMutationArgs,
|
|
|
): Promise<Promotion> {
|
|
|
- return this.promotionService.updatePromotion(ctx, args.input);
|
|
|
+ this.idCodecService.decodeConfigurableOperation(args.input.actions || []);
|
|
|
+ this.idCodecService.decodeConfigurableOperation(args.input.conditions || []);
|
|
|
+ return this.promotionService.updatePromotion(ctx, args.input).then(this.encodeConditionsAndActions);
|
|
|
}
|
|
|
|
|
|
@Mutation()
|
|
|
@@ -65,4 +73,15 @@ export class PromotionResolver {
|
|
|
deletePromotion(@Args() args: DeletePromotionMutationArgs): Promise<DeletionResponse> {
|
|
|
return this.promotionService.softDeletePromotion(args.id);
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Encodes any entity IDs used in the filter arguments.
|
|
|
+ */
|
|
|
+ private encodeConditionsAndActions = <T extends Promotion | undefined>(collection: T): T => {
|
|
|
+ if (collection) {
|
|
|
+ this.idCodecService.encodeConfigurableOperation(collection.conditions);
|
|
|
+ this.idCodecService.encodeConfigurableOperation(collection.actions);
|
|
|
+ }
|
|
|
+ return collection;
|
|
|
+ };
|
|
|
}
|