Skip to content

Commit

Permalink
Merge pull request #3 from uxpolishop/feature/reviews
Browse files Browse the repository at this point in the history
feature/reviews
  • Loading branch information
Breno Calazans authored Feb 12, 2020
2 parents 4a3f0d9 + 8040d07 commit a849505
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 51 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Changed
- Renamed `review` query to `rating`.
- Renamed `reviews` query to `ratings`.

### Added
- New query `reviews`.
27 changes: 0 additions & 27 deletions README.md

This file was deleted.

48 changes: 43 additions & 5 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
@@ -1,19 +1,57 @@

type Element {
type RatingElement {
ProductId: Int,
TotalRatings: Int,
Rating: Float,
}

type Review {
type Rating {
HasErrors: Boolean,
Element: [Element],
Element: [RatingElement],
ErrorList: [String],
Total: Int,
CurrentPage: Int
}

type Fields {
Name: String,
Values: [String]
}

type User {
Name: String,
Email: String,
CPF: String,
City: String,
State: String,
UserId: String,
ExhibitionName: String,
}

type ReviewElement {
ReviewId: Int,
Rating: Int,
Review: String,
Date: String,
Likes: Int,
Dislikes: Int,
CustomFields: [Fields],
User: User,
ReferenceOrder: String,
ReviewTitle: String,
BoughtProduct: Boolean
}

type Reviews {
HasErrors: Boolean,
Element: [ReviewElement],
ErrorList: [String],
Total: Int,
CurrentPage: Int
}

type Query {
review(productId: String): Review @withSecretKeys
reviews(productIds: [String!]): Review @withSecretKeys
rating(productId: String): Rating @withSecretKeys
ratings(productIds: [String!]): Rating @withSecretKeys
reviews(productId: String): Reviews @withSecretKeys
}
22 changes: 14 additions & 8 deletions node/clients/yourviews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,29 @@ export default class YourViewsClient extends ExternalClient {
this.token = secretKeys.yourviewsToken
}

public async getReview (productId: string): Promise<string> {
return this.get(this.routes.review(productId), {
metric: 'yourviews-get-review',
public async getRating (productId: string): Promise<string> {
return this.get(this.routes.rating(productId), {
metric: 'yourviews-get-rating',
})
}

public async getReviews (productIds: string[]): Promise<string> {
return this.get(this.routes.reviews(productIds), {
public async getRatings (productIds: string[]): Promise<string> {
return this.get(this.routes.ratings(productIds), {
metric: 'yourviews-get-ratings',
})
}

public async getReviews (productId: string): Promise<string> {
return this.get(this.routes.reviews(productId), {
metric: 'yourviews-get-reviews',
})
}

private get routes () {
return {
// Review endpoints
review: (productId: string) => `/api/${this.appId}/review/reviewshelf?productIds=${productId}`,
reviews: (productIds: string[]) => `/api/${this.appId}/review/reviewshelf?productIds=${productIds.join(',')}`,
rating: (productId: string) => `/api/${this.appId}/review/reviewshelf?productIds=${productId}`,
ratings: (productIds: string[]) => `/api/${this.appId}/review/reviewshelf?productIds=${productIds.join(',')}`,
reviews: (productId: string) => `/api/${this.appId}/review?productId=${productId}`,
}
}

Expand Down
4 changes: 2 additions & 2 deletions node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
"@vtex/api": "^3.8.1",
"tslint": "^5.12.0",
"tslint-config-vtex": "^2.1.0",
"typescript": "^3.4.2"
"typescript": "3.7.3"
},
"scripts": {
"lint": "tsc --noEmit && tslint --fix -c tslint.json './**/*.ts'"
},
"version": "0.0.4"
"version": "1.0.0"
}
6 changes: 4 additions & 2 deletions node/resolvers/review/index.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import {
review,
rating,
ratings,
reviews,
} from './yourviewsResolver'

export const queries = {
review,
rating,
ratings,
reviews,
}
18 changes: 11 additions & 7 deletions node/resolvers/review/yourviewsResolver.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
interface ReviewArgs {
interface SingleProductArgs {
productId: string
}

export const review = async (_: any, args: ReviewArgs, ctx: Context) => {
const data = await ctx.clients.yourviews.getReview(args.productId)
console.log('data', data)
export const rating = async (_: any, args: SingleProductArgs, ctx: Context) => {
const data = await ctx.clients.yourviews.getRating(args.productId)
return data
}

interface ReviewsArgs {
interface MultipleProductsArg {
productIds: string[]
}

export const reviews = async (_: any, args: ReviewsArgs, ctx: Context) => {
const data = await ctx.clients.yourviews.getReviews(args.productIds)
export const ratings = async (_: any, args: MultipleProductsArg, ctx: Context) => {
const data = await ctx.clients.yourviews.getRatings(args.productIds)
return data
}

export const reviews = async (_: any, args: SingleProductArgs, ctx: Context) => {
const data = await ctx.clients.yourviews.getReviews(args.productId)
return data
}

0 comments on commit a849505

Please sign in to comment.