Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(fsbazaarvoice): Expand review data source #1061

Merged
merged 2 commits into from
Feb 11, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/fsbazaarvoice/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
},
"dependencies": {
"@brandingbrand/fscommerce": "^8.2.0",
"@brandingbrand/fsnetwork": "^8.2.0"
"@brandingbrand/fsnetwork": "^8.2.0",
"qs": "^6.9.1"
},
"publishConfig": {
"registry": "https://registry.npmjs.org/"
Expand Down
15 changes: 12 additions & 3 deletions packages/fsbazaarvoice/src/BazaarvoiceDataSource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
import * as BazaarvoiceNormalizer from './BazaarvoiceNormalizer';
import * as BazaarvoiceDenormalizer from './BazaarvoiceDenormalizer';
import { BazaarvoiceReviewRequest } from './BazaarvoiceReviewRequest';
import qs from 'qs';

export interface BazaarvoiceConfig {
endpoint: string;
Expand All @@ -31,18 +32,26 @@ export class BazaarvoiceDataSource extends AbstractReviewDataSource implements R

async fetchReviewDetails(query: ReviewTypes.ReviewQuery): Promise<ReviewTypes.ReviewDetails[]> {
const id = Array.isArray(query.ids) ? query.ids[0] : query.ids;
const filter = query.filter || `ProductId:${id}`;

const params: BazaarvoiceReviewRequest = {
Filter: `ProductId:${id}`,
Filter: filter,
Include: 'Products',
Stats: 'Reviews',
Limit: query.limit || 10
Limit: query.limit || 10,
...(query.sort ? {Sort: query.sort} : {})

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just make it Sort: query.sort? Is it shoving in "Sort=undefined" that way?

Copy link
Author

@varzaman varzaman Feb 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't think to check to see if qs omits undefined parameters.

I just checked and qs indeed omits them, so I can change this.

};

if (query.page) {
params.Offset = params.Limit * (query.page - 1);
}

const { data } = await this.client.get('/data/reviews.json', { params });
const { data } = await this.client.get('/data/reviews.json', {
params,
paramsSerializer: (params: BazaarvoiceReviewRequest) => {
return qs.stringify(params, { indices: false });
}
});

return [{
id,
Expand Down
3 changes: 2 additions & 1 deletion packages/fsbazaarvoice/src/BazaarvoiceReviewRequest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export interface BazaarvoiceReviewRequest {
Filter: string;
Filter: string | string[];
Sort?: string;
Include: 'Products';
Stats: 'Reviews';
Limit: number;
Expand Down
15 changes: 15 additions & 0 deletions packages/fscommerce/src/Review/types/ReviewQuery.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/**
* Query to select a group of reviews
* https://developer.bazaarvoice.com/conversations-api/reference/v5.4/reviews/review-display
*/
export interface ReviewQuery {
/**
Expand All @@ -20,4 +21,18 @@ export interface ReviewQuery {
* @example 10
*/
limit?: number;

/**
* The Filter parameter for the Bazaarvoice query
*
* @example ['ProductId:50', 'Rating:eq:2']
*/
filter?: string | string[];

/**
* The Sort parameter for the Bazaarvoice query
*
* @example 'Rating:asc,SubmissionTime:desc'
*/
sort?: string;
}