Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Commit

Permalink
Merge pull request #5 from jonyw4/ui
Browse files Browse the repository at this point in the history
Review Product
  • Loading branch information
jonyw4 authored Aug 13, 2020
2 parents 080af6e + de6d82b commit bdd5624
Show file tree
Hide file tree
Showing 55 changed files with 6,455 additions and 312 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@

## 🌟 Features
- Ability to customer create review of the Company using with [NPS](https://en.wikipedia.org/wiki/Net_Promoter)
- Ability to customer get, list, update and create review of an Product
- Manage the state of reviews approving every changes by the customer
- On every change of state its dispatch a new Event, so you can extend the features of this package to send email or something like that

## Todo
- Admin UI
- Products Review
- Order Review

## ⚙️ Install
Expand All @@ -27,17 +27,18 @@ npm install vendure-reviews-plugin --save

### 3. Add the plugin in Vendure configuration
```typescript
import { ReviewsStorePlugin } from 'vendure-reviews-plugin';
import { ReviewsStorePlugin, ReviewsProductPlugin } from 'vendure-reviews-plugin';
const config: VendureConfig = {
...
plugins: [
ReviewsStorePlugin
ReviewsStorePlugin,
ReviewsProductPlugin
]
}
```

## 📚 How to use?
If you want to use queries and mutation of this package [you can see the all on this file](https://github.com/jonyw4/vendure-reviews-plugin/blob/master/src/api/schema/shop.ts)
If you want to use queries and mutation of this package [you can see the all on this file](https://github.com/jonyw4/vendure-reviews-plugin/blob/master/src/api/schema/)

## ❗️ License
MIT
9 changes: 7 additions & 2 deletions dev-server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
DefaultSearchPlugin,
VendureConfig
} from '@vendure/core';
import { ReviewsStorePlugin } from '../src';
import { ReviewsStorePlugin, ReviewsProductPlugin } from '../src';

const PORT = Number(process.env.PORT) || 3000;

Expand Down Expand Up @@ -45,7 +45,12 @@ export const config: VendureConfig = {
paymentOptions: {
paymentMethodHandlers: [examplePaymentHandler]
},
plugins: [DefaultJobQueuePlugin, DefaultSearchPlugin, ReviewsStorePlugin]
plugins: [
DefaultJobQueuePlugin,
DefaultSearchPlugin,
ReviewsStorePlugin,
ReviewsProductPlugin
]
};

export default config;
4 changes: 2 additions & 2 deletions e2e/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { mergeConfig } from '@vendure/core';
import { testConfig as defaultTestConfig } from '@vendure/testing';
import path from 'path';
import { E2EInjectOrderPlugin } from './inject-order';
import { ReviewsStorePlugin } from '../../src';
import { ReviewsStorePlugin, ReviewsProductPlugin } from '../../src';

/**
* We use a relatively long timeout on the initial beforeAll() function of the
Expand All @@ -27,5 +27,5 @@ export const testConfig = mergeConfig(defaultTestConfig, {
importExportOptions: {
importAssetsDir: path.join(__dirname, '..', 'fixtures/assets')
},
plugins: [ReviewsStorePlugin, E2EInjectOrderPlugin]
plugins: [ReviewsStorePlugin, ReviewsProductPlugin, E2EInjectOrderPlugin]
});
25 changes: 20 additions & 5 deletions e2e/config/inject-order.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { Connection } from 'typeorm';
import { InjectConnection } from '@nestjs/typeorm';

import {
PluginCommonModule,
VendurePlugin,
OnVendureBootstrap,
Order,
CurrencyCode,
Customer
Customer,
ProductVariant,
OrderLine
} from '@vendure/core';

/**
Expand All @@ -20,7 +21,11 @@ export class E2EInjectOrderPlugin implements OnVendureBootstrap {
constructor(@InjectConnection() private connection: Connection) {}
async onVendureBootstrap(): Promise<void> {
const customers = await this.connection.getRepository(Customer).find();
await this.connection.getRepository(Order).save([
const productsVariant = await this.connection
.getRepository(ProductVariant)
.find({ relations: ['product'] });

await this.connection.getRepository(Order).save(
new Order({
code: 'T_1',
state: 'AddingItems',
Expand All @@ -37,7 +42,10 @@ export class E2EInjectOrderPlugin implements OnVendureBootstrap {
subTotal: 10,
shipping: 0,
shippingWithTax: 0
}),
})
);

const completeOrder = await this.connection.getRepository(Order).save(
new Order({
code: 'T_2',
state: 'Fulfilled',
Expand All @@ -55,6 +63,13 @@ export class E2EInjectOrderPlugin implements OnVendureBootstrap {
shipping: 0,
shippingWithTax: 0
})
]);
);

await this.connection.getRepository(OrderLine).save(
new OrderLine({
order: completeOrder,
productVariant: productsVariant[0]
})
);
}
}
52 changes: 52 additions & 0 deletions e2e/graphql/admin-api.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ export const ADMIN_REVIEW_STORE_FRAGMENT = gql`
state
nps
nextStates
customer {
id
firstName
}
}
`;

Expand Down Expand Up @@ -56,3 +60,51 @@ export const ADMIN_TRANSITION_REVIEW_STORE = gql`
}
${ADMIN_REVIEW_STORE_FRAGMENT}
`;

export const ADMIN_REVIEW_PRODUCT_FRAGMENT = gql`
fragment AdminReviewProduct on ReviewProduct {
id
title
description
state
stars
nextStates
customer {
id
firstName
}
product {
id
name
}
}
`;

export const ADMIN_REVIEW_PRODUCT = gql`
query ReviewProduct($id: ID!) {
reviewProduct(id: $id) {
...AdminReviewProduct
}
}
${ADMIN_REVIEW_PRODUCT_FRAGMENT}
`;

export const ADMIN_REVIEWS_PRODUCT = gql`
query ListReviewProduct {
reviewsProduct {
items {
...AdminReviewProduct
}
}
}
${ADMIN_REVIEW_PRODUCT_FRAGMENT}
`;

export const ADMIN_TRANSITION_REVIEW_PRODUCT = gql`
mutation transitionReviewProductToState($id: ID!, $state: String!) {
transitionReviewProductToState(id: $id, state: $state) {
...AdminReviewProduct
}
}
${ADMIN_REVIEW_PRODUCT_FRAGMENT}
`;
53 changes: 52 additions & 1 deletion e2e/graphql/admin-api.graphql.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as Types from '../../src/types/generated-admin-schema';
export type AdminReviewStoreFragment = { __typename?: 'ReviewStore' } & Pick<
Types.ReviewStore,
'id' | 'title' | 'description' | 'state' | 'nps' | 'nextStates'
>;
> & {
customer: { __typename?: 'Customer' } & Pick<
Types.Customer,
'id' | 'firstName'
>;
};

export type CustomerListQueryVariables = Types.Exact<{ [key: string]: never }>;

Expand Down Expand Up @@ -56,3 +61,49 @@ export type TransitionReviewStoreToStateMutation = {
{ __typename?: 'ReviewStore' } & AdminReviewStoreFragment
>;
};

export type AdminReviewProductFragment = {
__typename?: 'ReviewProduct';
} & Pick<
Types.ReviewProduct,
'id' | 'title' | 'description' | 'state' | 'stars' | 'nextStates'
> & {
customer: { __typename?: 'Customer' } & Pick<
Types.Customer,
'id' | 'firstName'
>;
product: { __typename?: 'Product' } & Pick<Types.Product, 'id' | 'name'>;
};

export type ReviewProductQueryVariables = Types.Exact<{
id: Types.Scalars['ID'];
}>;

export type ReviewProductQuery = { __typename?: 'Query' } & {
reviewProduct?: Types.Maybe<
{ __typename?: 'ReviewProduct' } & AdminReviewProductFragment
>;
};

export type ListReviewProductQueryVariables = Types.Exact<{
[key: string]: never;
}>;

export type ListReviewProductQuery = { __typename?: 'Query' } & {
reviewsProduct: { __typename?: 'ReviewProductList' } & {
items: Array<{ __typename?: 'ReviewProduct' } & AdminReviewProductFragment>;
};
};

export type TransitionReviewProductToStateMutationVariables = Types.Exact<{
id: Types.Scalars['ID'];
state: Types.Scalars['String'];
}>;

export type TransitionReviewProductToStateMutation = {
__typename?: 'Mutation';
} & {
transitionReviewProductToState?: Types.Maybe<
{ __typename?: 'ReviewProduct' } & AdminReviewProductFragment
>;
};
84 changes: 84 additions & 0 deletions e2e/graphql/shop-api.graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,17 @@ export const SHOP_UPDATE_REVIEW_STORE = gql`
${SHOP_REVIEW_STORE_FRAGMENT}
`;

export const SHOP_REVIEWS_STORE = gql`
query ListReviewStore {
reviewsStore {
items {
...ShopReviewStore
}
}
}
${SHOP_REVIEW_STORE_FRAGMENT}
`;

export const SHOP_MY_REVIEW_STORE = gql`
query MyReviewStore {
myReviewStore {
Expand All @@ -40,3 +51,76 @@ export const SHOP_AVG_REVIEW_STORE = gql`
avgReviewStore
}
`;

export const SHOP_REVIEW_PRODUCT_FRAGMENT = gql`
fragment ShopReviewProduct on ReviewProduct {
id
title
description
stars
}
`;

export const SHOP_AVAILABLE_PRODUCTS_REVIEW = gql`
query AvailableProductsReview {
availableProductsToReview {
items {
id
name
}
}
}
`;

export const SHOP_REVIEW_PRODUCT = gql`
query ReviewProduct($id: ID!) {
reviewProduct(id: $id) {
...ShopReviewProduct
}
}
${SHOP_REVIEW_PRODUCT_FRAGMENT}
`;

export const SHOP_REVIEWS_PRODUCT = gql`
query ListReviewProduct {
reviewsProduct {
items {
...ShopReviewProduct
}
}
}
${SHOP_REVIEW_PRODUCT_FRAGMENT}
`;
export const SHOP_CREATE_REVIEW_PRODUCT = gql`
mutation CreateReviewProduct($input: CreateReviewProductInput!) {
createReviewProduct(input: $input) {
...ShopReviewProduct
}
}
${SHOP_REVIEW_PRODUCT_FRAGMENT}
`;

export const SHOP_UPDATE_REVIEW_PRODUCT = gql`
mutation UpdateReviewProduct($input: UpdateReviewProductInput!) {
updateReviewProduct(input: $input) {
...ShopReviewProduct
}
}
${SHOP_REVIEW_PRODUCT_FRAGMENT}
`;

export const SHOP_PRODUCT_REVIEW = gql`
query ProductReview {
product(id: "T_1") {
id
reviewAvg
reviews {
items {
...ShopReviewProduct
}
}
canReview
}
}
${SHOP_REVIEW_PRODUCT_FRAGMENT}
`;
Loading

0 comments on commit bdd5624

Please sign in to comment.