Skip to content

Commit

Permalink
feat(core): Make Promotion entity translatable, add description
Browse files Browse the repository at this point in the history
Relates to #1990

BREAKING CHANGE: The Promotion entity is now translatable, which means existing promotions will need
to be migrated to the new DB schema and care taken to preserve the name data. Also the GraphQL
API for creating and updating Promotions, as well as the corresponding PromotionService methods
have changed to take a `translations` array for setting the `name` and `description` in a given
language.
  • Loading branch information
michaelbromley committed Feb 24, 2023
1 parent 06efc50 commit dada243
Show file tree
Hide file tree
Showing 25 changed files with 340 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,9 @@ export type CreatePromotionInput = {
customFields?: InputMaybe<Scalars['JSON']>;
enabled: Scalars['Boolean'];
endsAt?: InputMaybe<Scalars['DateTime']>;
name: Scalars['String'];
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4202,18 +4202,21 @@ export type Promotion = Node & {
couponCode?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
customFields?: Maybe<Scalars['JSON']>;
description: Scalars['String'];
enabled: Scalars['Boolean'];
endsAt?: Maybe<Scalars['DateTime']>;
id: Scalars['ID'];
name: Scalars['String'];
perCustomerUsageLimit?: Maybe<Scalars['Int']>;
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
};

export type PromotionFilterParameter = {
couponCode?: InputMaybe<StringOperators>;
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
endsAt?: InputMaybe<DateOperators>;
id?: InputMaybe<IdOperators>;
Expand Down Expand Up @@ -4244,6 +4247,7 @@ export type PromotionListOptions = {
export type PromotionSortParameter = {
couponCode?: InputMaybe<SortOrder>;
createdAt?: InputMaybe<SortOrder>;
description?: InputMaybe<SortOrder>;
endsAt?: InputMaybe<SortOrder>;
id?: InputMaybe<SortOrder>;
name?: InputMaybe<SortOrder>;
Expand All @@ -4252,6 +4256,23 @@ export type PromotionSortParameter = {
updatedAt?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
createdAt: Scalars['DateTime'];
description: Scalars['String'];
id: Scalars['ID'];
languageCode: LanguageCode;
name: Scalars['String'];
updatedAt: Scalars['DateTime'];
};

export type PromotionTranslationInput = {
customFields?: InputMaybe<Scalars['JSON']>;
description?: InputMaybe<Scalars['String']>;
id?: InputMaybe<Scalars['ID']>;
languageCode: LanguageCode;
name?: InputMaybe<Scalars['String']>;
};

/** Returned if the specified quantity of an OrderLine is greater than the number of items in that line */
export type QuantityTooGreatError = ErrorResult & {
errorCode: ErrorCode;
Expand Down Expand Up @@ -5510,9 +5531,9 @@ export type UpdatePromotionInput = {
enabled?: InputMaybe<Scalars['Boolean']>;
endsAt?: InputMaybe<Scalars['DateTime']>;
id: Scalars['ID'];
name?: InputMaybe<Scalars['String']>;
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down
12 changes: 12 additions & 0 deletions packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2696,12 +2696,14 @@ export type Promotion = Node & {
couponCode?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
customFields?: Maybe<Scalars['JSON']>;
description: Scalars['String'];
enabled: Scalars['Boolean'];
endsAt?: Maybe<Scalars['DateTime']>;
id: Scalars['ID'];
name: Scalars['String'];
perCustomerUsageLimit?: Maybe<Scalars['Int']>;
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
};

Expand All @@ -2711,6 +2713,16 @@ export type PromotionList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type PromotionTranslation = {
__typename?: 'PromotionTranslation';
createdAt: Scalars['DateTime'];
description: Scalars['String'];
id: Scalars['ID'];
languageCode: LanguageCode;
name: Scalars['String'];
updatedAt: Scalars['DateTime'];
};

export type Query = {
__typename?: 'Query';
/** The active Channel */
Expand Down
26 changes: 24 additions & 2 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,9 +804,9 @@ export type CreatePromotionInput = {
customFields?: InputMaybe<Scalars['JSON']>;
enabled: Scalars['Boolean'];
endsAt?: InputMaybe<Scalars['DateTime']>;
name: Scalars['String'];
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4423,18 +4423,21 @@ export type Promotion = Node & {
couponCode?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
customFields?: Maybe<Scalars['JSON']>;
description: Scalars['String'];
enabled: Scalars['Boolean'];
endsAt?: Maybe<Scalars['DateTime']>;
id: Scalars['ID'];
name: Scalars['String'];
perCustomerUsageLimit?: Maybe<Scalars['Int']>;
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
};

export type PromotionFilterParameter = {
couponCode?: InputMaybe<StringOperators>;
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
endsAt?: InputMaybe<DateOperators>;
id?: InputMaybe<IdOperators>;
Expand Down Expand Up @@ -4466,6 +4469,7 @@ export type PromotionListOptions = {
export type PromotionSortParameter = {
couponCode?: InputMaybe<SortOrder>;
createdAt?: InputMaybe<SortOrder>;
description?: InputMaybe<SortOrder>;
endsAt?: InputMaybe<SortOrder>;
id?: InputMaybe<SortOrder>;
name?: InputMaybe<SortOrder>;
Expand All @@ -4474,6 +4478,24 @@ export type PromotionSortParameter = {
updatedAt?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
__typename?: 'PromotionTranslation';
createdAt: Scalars['DateTime'];
description: Scalars['String'];
id: Scalars['ID'];
languageCode: LanguageCode;
name: Scalars['String'];
updatedAt: Scalars['DateTime'];
};

export type PromotionTranslationInput = {
customFields?: InputMaybe<Scalars['JSON']>;
description?: InputMaybe<Scalars['String']>;
id?: InputMaybe<Scalars['ID']>;
languageCode: LanguageCode;
name?: InputMaybe<Scalars['String']>;
};

/** Returned if the specified quantity of an OrderLine is greater than the number of items in that line */
export type QuantityTooGreatError = ErrorResult & {
__typename?: 'QuantityTooGreatError';
Expand Down Expand Up @@ -5802,9 +5824,9 @@ export type UpdatePromotionInput = {
enabled?: InputMaybe<Scalars['Boolean']>;
endsAt?: InputMaybe<Scalars['DateTime']>;
id: Scalars['ID'];
name?: InputMaybe<Scalars['String']>;
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down
3 changes: 2 additions & 1 deletion packages/core/e2e/active-order-strategy.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LanguageCode } from '@vendure/common/lib/generated-types';
import { mergeConfig, orderPercentageDiscount } from '@vendure/core';
import { createTestEnvironment } from '@vendure/testing';
import gql from 'graphql-tag';
Expand Down Expand Up @@ -148,7 +149,6 @@ describe('custom ActiveOrderStrategy', () => {
{
input: {
enabled: true,
name: 'Free with test coupon',
couponCode: TEST_COUPON_CODE,
conditions: [],
actions: [
Expand All @@ -157,6 +157,7 @@ describe('custom ActiveOrderStrategy', () => {
arguments: [{ name: 'discount', value: '100' }],
},
],
translations: [{ languageCode: LanguageCode.en, name: 'Free with test coupon' }],
},
},
);
Expand Down
3 changes: 2 additions & 1 deletion packages/core/e2e/draft-order.e2e-spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* tslint:disable:no-non-null-assertion */
import { LanguageCode } from '@vendure/common/lib/generated-types';
import { DefaultLogger, mergeConfig, orderPercentageDiscount } from '@vendure/core';
import { createErrorResultGuard, createTestEnvironment, ErrorResultGuard } from '@vendure/testing';
import gql from 'graphql-tag';
Expand Down Expand Up @@ -72,7 +73,6 @@ describe('Draft Orders resolver', () => {
Codegen.CreatePromotionMutationVariables
>(CREATE_PROMOTION, {
input: {
name: 'Free Order',
enabled: true,
conditions: [],
couponCode: freeOrderCouponCode,
Expand All @@ -82,6 +82,7 @@ describe('Draft Orders resolver', () => {
arguments: [{ name: 'discount', value: '100' }],
},
],
translations: [{ languageCode: LanguageCode.en, name: 'Free Order' }],
},
});
}, TEST_SETUP_TIMEOUT_MS);
Expand Down
25 changes: 23 additions & 2 deletions packages/core/e2e/graphql/generated-e2e-admin-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -790,9 +790,9 @@ export type CreatePromotionInput = {
customFields?: InputMaybe<Scalars['JSON']>;
enabled: Scalars['Boolean'];
endsAt?: InputMaybe<Scalars['DateTime']>;
name: Scalars['String'];
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations: Array<PromotionTranslationInput>;
};

export type CreatePromotionResult = MissingConditionsError | Promotion;
Expand Down Expand Up @@ -4202,18 +4202,21 @@ export type Promotion = Node & {
couponCode?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
customFields?: Maybe<Scalars['JSON']>;
description: Scalars['String'];
enabled: Scalars['Boolean'];
endsAt?: Maybe<Scalars['DateTime']>;
id: Scalars['ID'];
name: Scalars['String'];
perCustomerUsageLimit?: Maybe<Scalars['Int']>;
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
};

export type PromotionFilterParameter = {
couponCode?: InputMaybe<StringOperators>;
createdAt?: InputMaybe<DateOperators>;
description?: InputMaybe<StringOperators>;
enabled?: InputMaybe<BooleanOperators>;
endsAt?: InputMaybe<DateOperators>;
id?: InputMaybe<IdOperators>;
Expand Down Expand Up @@ -4244,6 +4247,7 @@ export type PromotionListOptions = {
export type PromotionSortParameter = {
couponCode?: InputMaybe<SortOrder>;
createdAt?: InputMaybe<SortOrder>;
description?: InputMaybe<SortOrder>;
endsAt?: InputMaybe<SortOrder>;
id?: InputMaybe<SortOrder>;
name?: InputMaybe<SortOrder>;
Expand All @@ -4252,6 +4256,23 @@ export type PromotionSortParameter = {
updatedAt?: InputMaybe<SortOrder>;
};

export type PromotionTranslation = {
createdAt: Scalars['DateTime'];
description: Scalars['String'];
id: Scalars['ID'];
languageCode: LanguageCode;
name: Scalars['String'];
updatedAt: Scalars['DateTime'];
};

export type PromotionTranslationInput = {
customFields?: InputMaybe<Scalars['JSON']>;
description?: InputMaybe<Scalars['String']>;
id?: InputMaybe<Scalars['ID']>;
languageCode: LanguageCode;
name?: InputMaybe<Scalars['String']>;
};

/** Returned if the specified quantity of an OrderLine is greater than the number of items in that line */
export type QuantityTooGreatError = ErrorResult & {
errorCode: ErrorCode;
Expand Down Expand Up @@ -5510,9 +5531,9 @@ export type UpdatePromotionInput = {
enabled?: InputMaybe<Scalars['Boolean']>;
endsAt?: InputMaybe<Scalars['DateTime']>;
id: Scalars['ID'];
name?: InputMaybe<Scalars['String']>;
perCustomerUsageLimit?: InputMaybe<Scalars['Int']>;
startsAt?: InputMaybe<Scalars['DateTime']>;
translations?: InputMaybe<Array<PromotionTranslationInput>>;
};

export type UpdatePromotionResult = MissingConditionsError | Promotion;
Expand Down
11 changes: 11 additions & 0 deletions packages/core/e2e/graphql/generated-e2e-shop-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2604,12 +2604,14 @@ export type Promotion = Node & {
couponCode?: Maybe<Scalars['String']>;
createdAt: Scalars['DateTime'];
customFields?: Maybe<Scalars['JSON']>;
description: Scalars['String'];
enabled: Scalars['Boolean'];
endsAt?: Maybe<Scalars['DateTime']>;
id: Scalars['ID'];
name: Scalars['String'];
perCustomerUsageLimit?: Maybe<Scalars['Int']>;
startsAt?: Maybe<Scalars['DateTime']>;
translations: Array<PromotionTranslation>;
updatedAt: Scalars['DateTime'];
};

Expand All @@ -2618,6 +2620,15 @@ export type PromotionList = PaginatedList & {
totalItems: Scalars['Int'];
};

export type PromotionTranslation = {
createdAt: Scalars['DateTime'];
description: Scalars['String'];
id: Scalars['ID'];
languageCode: LanguageCode;
name: Scalars['String'];
updatedAt: Scalars['DateTime'];
};

export type Query = {
/** The active Channel */
activeChannel: Channel;
Expand Down
Loading

0 comments on commit dada243

Please sign in to comment.