|
|
@@ -33,17 +33,39 @@ import { TypedBaseDetailComponent, LanguageCode, SharedModule } from '@vendure/a
|
|
|
// This is the TypedDocumentNode & type generated by GraphQL Code Generator
|
|
|
import { graphql } from '../../gql';
|
|
|
|
|
|
+export const reviewDetailFragment = graphql(`
|
|
|
+ fragment ReviewDetail on ProductReview {
|
|
|
+ id
|
|
|
+ createdAt
|
|
|
+ updatedAt
|
|
|
+ title
|
|
|
+ rating
|
|
|
+ text
|
|
|
+ authorName
|
|
|
+ productId
|
|
|
+ }
|
|
|
+`);
|
|
|
+
|
|
|
export const getReviewDetailDocument = graphql(`
|
|
|
query GetReviewDetail($id: ID!) {
|
|
|
review(id: $id) {
|
|
|
- id
|
|
|
- createdAt
|
|
|
- updatedAt
|
|
|
- title
|
|
|
- rating
|
|
|
- text
|
|
|
- authorName
|
|
|
- productId
|
|
|
+ ...ReviewDetail
|
|
|
+ }
|
|
|
+ }
|
|
|
+`);
|
|
|
+
|
|
|
+export const createReviewDocument = graphql(`
|
|
|
+ mutation CreateReview($input: CreateProductReviewInput!) {
|
|
|
+ createProductReview(input: $input) {
|
|
|
+ ...ReviewDetail
|
|
|
+ }
|
|
|
+ }
|
|
|
+`);
|
|
|
+
|
|
|
+export const updateReviewDocument = graphql(`
|
|
|
+ mutation UpdateReview($input: UpdateProductReviewInput!) {
|
|
|
+ updateProductReview(input: $input) {
|
|
|
+ ...ReviewDetail
|
|
|
}
|
|
|
}
|
|
|
`);
|
|
|
@@ -63,7 +85,7 @@ export class ReviewDetailComponent extends TypedBaseDetailComponent<typeof getRe
|
|
|
authorName: [''],
|
|
|
});
|
|
|
|
|
|
- constructor(private formBuilder: FormBuilder) {
|
|
|
+ constructor(private formBuilder: FormBuilder, private notificationService: NotificationService) {
|
|
|
super();
|
|
|
}
|
|
|
|
|
|
@@ -76,11 +98,31 @@ export class ReviewDetailComponent extends TypedBaseDetailComponent<typeof getRe
|
|
|
}
|
|
|
|
|
|
create() {
|
|
|
- // Logic to save a Review
|
|
|
+ const { title, rating, authorName } = this.detailForm.value;
|
|
|
+ if (!title || rating == null || !authorName) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ this.dataService
|
|
|
+ .mutate(createReviewDocument, {
|
|
|
+ input: { title, rating, authorName },
|
|
|
+ })
|
|
|
+ .subscribe(({ createProductReview }) => {
|
|
|
+ if (createProductReview.id) {
|
|
|
+ this.notificationService.success('Review created');
|
|
|
+ this.router.navigate(['extensions', 'reviews', createProductReview.id]);
|
|
|
+ }
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
update() {
|
|
|
- // Logic to update a Review
|
|
|
+ const { title, rating, authorName } = this.detailForm.value;
|
|
|
+ this.dataService
|
|
|
+ .mutate(updateOrganizationDocument, {
|
|
|
+ input: { id: this.id, title, rating, authorName },
|
|
|
+ })
|
|
|
+ .subscribe(() => {
|
|
|
+ this.notificationService.success('Review updated');
|
|
|
+ });
|
|
|
}
|
|
|
|
|
|
protected setFormValues(entity: NonNullable<ResultOf<typeof getReviewDetailDocument>['review']>, languageCode: LanguageCode): void {
|