Skip to content

Commit

Permalink
feat(core): Add isPrivate flag to Collection
Browse files Browse the repository at this point in the history
Relates to #71
  • Loading branch information
michaelbromley committed Apr 25, 2019
1 parent b5a07d1 commit 848c8b4
Show file tree
Hide file tree
Showing 14 changed files with 309 additions and 195 deletions.
2 changes: 1 addition & 1 deletion packages/common/src/generated-shop-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable
// Generated in 2019-04-25T09:11:09+02:00
// Generated in 2019-04-25T13:30:55+02:00
export type Maybe<T> = T | null;

export interface OrderListOptions {
Expand Down
88 changes: 50 additions & 38 deletions packages/common/src/generated-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// tslint:disable
// Generated in 2019-04-25T09:11:10+02:00
// Generated in 2019-04-25T13:30:57+02:00
export type Maybe<T> = T | null;


Expand Down Expand Up @@ -169,6 +169,13 @@ export interface CollectionFilterParameter {
position?: Maybe<NumberOperators>;

description?: Maybe<StringOperators>;

isPrivate?: Maybe<BooleanOperators>;
}

export interface BooleanOperators {

eq?: Maybe<boolean>;
}

export interface ProductVariantListOptions {
Expand Down Expand Up @@ -224,11 +231,6 @@ export interface ProductVariantFilterParameter {
enabled?: Maybe<BooleanOperators>;
}

export interface BooleanOperators {

eq?: Maybe<boolean>;
}

export interface CountryListOptions {

skip?: Maybe<number>;
Expand Down Expand Up @@ -714,6 +716,8 @@ export interface UpdateChannelInput {

export interface CreateCollectionInput {

isPrivate?: Maybe<boolean>;

featuredAssetId?: Maybe<string>;

assetIds?: Maybe<string[]>;
Expand Down Expand Up @@ -760,6 +764,8 @@ export interface UpdateCollectionInput {

id: string;

isPrivate?: Maybe<boolean>;

featuredAssetId?: Maybe<string>;

parentId?: Maybe<string>;
Expand Down Expand Up @@ -1169,18 +1175,6 @@ export interface UpdateRoleInput {
permissions?: Maybe<Permission[]>;
}

export interface CreateTaxCategoryInput {

name: string;
}

export interface UpdateTaxCategoryInput {

id: string;

name?: Maybe<string>;
}

export interface CreateShippingMethodInput {

code: string;
Expand All @@ -1205,6 +1199,18 @@ export interface UpdateShippingMethodInput {
calculator?: Maybe<ConfigurableOperationInput>;
}

export interface CreateTaxCategoryInput {

name: string;
}

export interface UpdateTaxCategoryInput {

id: string;

name?: Maybe<string>;
}

export interface CreateTaxRateInput {

name: string;
Expand Down Expand Up @@ -2074,6 +2080,8 @@ export namespace GetCollectionList {

description: string;

isPrivate: Maybe<boolean>;

featuredAsset: Maybe<FeaturedAsset>;

parent: Maybe<Parent>;
Expand Down Expand Up @@ -3618,6 +3626,8 @@ export namespace Collection {

description: string;

isPrivate: Maybe<boolean>;

languageCode: Maybe<LanguageCode>;

featuredAsset: Maybe<FeaturedAsset>;
Expand Down Expand Up @@ -4601,10 +4611,6 @@ export interface Query {

role?: Maybe<Role>;

taxCategories: TaxCategory[];

taxCategory?: Maybe<TaxCategory>;

shippingMethods: ShippingMethodList;

shippingMethod?: Maybe<ShippingMethod>;
Expand All @@ -4613,6 +4619,10 @@ export interface Query {

shippingCalculators: ConfigurableOperation[];

taxCategories: TaxCategory[];

taxCategory?: Maybe<TaxCategory>;

taxRates: TaxRateList;

taxRate?: Maybe<TaxRate>;
Expand Down Expand Up @@ -4839,6 +4849,8 @@ export interface Collection extends Node {

productVariants: ProductVariantList;

isPrivate?: Maybe<boolean>;

customFields?: Maybe<Json>;
}

Expand Down Expand Up @@ -5754,14 +5766,14 @@ export interface Mutation {
createRole: Role;
/** Update an existing Role */
updateRole: Role;
/** Create a new TaxCategory */
createTaxCategory: TaxCategory;
/** Update an existing TaxCategory */
updateTaxCategory: TaxCategory;
/** Create a new ShippingMethod */
createShippingMethod: ShippingMethod;
/** Update an existing ShippingMethod */
updateShippingMethod: ShippingMethod;
/** Create a new TaxCategory */
createTaxCategory: TaxCategory;
/** Update an existing TaxCategory */
updateTaxCategory: TaxCategory;
/** Create a new TaxRate */
createTaxRate: TaxRate;
/** Update an existing TaxRate */
Expand Down Expand Up @@ -5962,10 +5974,6 @@ export interface RoleQueryArgs {

id: string;
}
export interface TaxCategoryQueryArgs {

id: string;
}
export interface ShippingMethodsQueryArgs {

options?: Maybe<ShippingMethodListOptions>;
Expand All @@ -5974,6 +5982,10 @@ export interface ShippingMethodQueryArgs {

id: string;
}
export interface TaxCategoryQueryArgs {

id: string;
}
export interface TaxRatesQueryArgs {

options?: Maybe<TaxRateListOptions>;
Expand Down Expand Up @@ -6206,14 +6218,6 @@ export interface UpdateRoleMutationArgs {

input: UpdateRoleInput;
}
export interface CreateTaxCategoryMutationArgs {

input: CreateTaxCategoryInput;
}
export interface UpdateTaxCategoryMutationArgs {

input: UpdateTaxCategoryInput;
}
export interface CreateShippingMethodMutationArgs {

input: CreateShippingMethodInput;
Expand All @@ -6222,6 +6226,14 @@ export interface UpdateShippingMethodMutationArgs {

input: UpdateShippingMethodInput;
}
export interface CreateTaxCategoryMutationArgs {

input: CreateTaxCategoryInput;
}
export interface UpdateTaxCategoryMutationArgs {

input: UpdateTaxCategoryInput;
}
export interface CreateTaxRateMutationArgs {

input: CreateTaxRateInput;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/e2e/__snapshots__/collection.e2e-spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ Object {
},
],
"id": "T_3",
"isPrivate": false,
"languageCode": "en",
"name": "Electronics",
"parent": Object {
Expand Down Expand Up @@ -102,6 +103,7 @@ Object {
},
],
"id": "T_5",
"isPrivate": false,
"languageCode": "en",
"name": "Pear",
"parent": Object {
Expand Down
13 changes: 13 additions & 0 deletions packages/core/e2e/default-search-plugin.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,18 @@ describe('Default search plugin', () => {
});
expect(result.search.items.map(i => i.productVariantId)).toEqual(['T_1', 'T_2', 'T_4']);
});

it('encodes collectionIds', async () => {
const result = await shopClient.query(SEARCH_PRODUCTS_SHOP, {
input: {
groupByProduct: false,
term: 'cactus',
take: 1,
},
});

expect(result.search.items[0].collectionIds).toEqual(['T_2']);
});
});

describe('admin api', () => {
Expand Down Expand Up @@ -472,6 +484,7 @@ export const SEARCH_PRODUCTS_SHOP = gql`
productVariantName
productVariantPreview
sku
collectionIds
}
}
}
Expand Down
55 changes: 53 additions & 2 deletions packages/core/e2e/shop-catalog.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import gql from 'graphql-tag';
import path from 'path';

import { CREATE_COLLECTION } from '../../../admin-ui/src/app/data/definitions/collection-definitions';
import { CREATE_COLLECTION, UPDATE_COLLECTION } from '../../../admin-ui/src/app/data/definitions/collection-definitions';
import { GET_PRODUCT_WITH_VARIANTS, UPDATE_PRODUCT_VARIANTS } from '../../../admin-ui/src/app/data/definitions/product-definitions';
import { ConfigArgType, CreateCollection, LanguageCode } from '../../common/lib/generated-types';
import { ConfigArgType, CreateCollection, LanguageCode, UpdateCollection } from '../../common/lib/generated-types';
import { GetProductWithVariants, UpdateProductVariants } from '../../common/src/generated-types';
import { facetValueCollectionFilter } from '../src/config/collection/default-collection-filters';

Expand Down Expand Up @@ -175,6 +175,48 @@ describe('Shop catalog', () => {
{ id: 'T_27', name: 'Football' },
]);
});

it('collection list', async () => {
const result = await shopClient.query(GET_COLLECTION_LIST);

expect(result.collections.items).toEqual([
{ id: 'T_2', name: 'Plants' },
{ id: 'T_3', name: 'My Collection' },
]);
});

it('omits private collections', async () => {
await adminClient.query<UpdateCollection.Mutation, UpdateCollection.Variables>(UPDATE_COLLECTION, {
input: {
id: collection.id,
isPrivate: true,
},
});
const result = await shopClient.query(GET_COLLECTION_LIST);

expect(result.collections.items).toEqual([
{ id: 'T_2', name: 'Plants' },
]);
});

it('returns null for private collection', async () => {
const result = await shopClient.query(GET_COLLECTION_VARIANTS, { id: collection.id });

expect(result.collection).toBeNull();
});

it('product.collections list omits private collections', async () => {
const result = await shopClient.query(gql`{
product(id: "T_12") {
collections {
id
name
}
}
}`);

expect(result.product.collections).toEqual([]);
});
});
});

Expand All @@ -201,3 +243,12 @@ const GET_COLLECTION_VARIANTS = gql`
}
}
`;

const GET_COLLECTION_LIST = gql`{
collections {
items {
id
name
}
}
}`;
2 changes: 1 addition & 1 deletion packages/core/src/api/common/id-codec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ID } from '@vendure/common/lib/shared-types';
import { EntityIdStrategy } from '../../config/entity-id-strategy/entity-id-strategy';
import { VendureEntity } from '../../entity/base/base.entity';

const ID_KEYS = ['id', 'productId', 'productVariantId'];
const ID_KEYS = ['id', 'productId', 'productVariantId', 'collectionIds'];

/**
* This service is responsible for encoding/decoding entity IDs according to the configured EntityIdStrategy.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ export class ProductEntityResolver {
async collections(
@Ctx() ctx: RequestContext,
@Parent() product: Product,
@Api() apiType: ApiType,
): Promise<Array<Translated<Collection>>> {
return this.collectionService.getCollectionsByProductId(ctx, product.id);
return this.collectionService.getCollectionsByProductId(ctx, product.id, apiType === 'shop');
}
}
Loading

0 comments on commit 848c8b4

Please sign in to comment.