Skip to content

Commit

Permalink
fix: oops - Catalog.
Browse files Browse the repository at this point in the history
  • Loading branch information
machikoyasuda committed Feb 13, 2019
1 parent 099e7a0 commit b31f120
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import ReactionError from "@reactioncommerce/reaction-error";
*/
export default async function catalogItemsAggregate(context, { shopIds, tagId } = {}) {
const { collections } = context;
const { Catalogs, Tags } = collections;
const { Catalog, Tags } = collections;

if ((!shopIds || shopIds.length === 0) && (!tagId)) {
throw new ReactionError("invalid-param", "You must provide a tagId or shopIds or both");
Expand Down Expand Up @@ -63,7 +63,7 @@ export default async function catalogItemsAggregate(context, { shopIds, tagId }
};

return {
collection: Catalogs,
collection: Catalog,
pipeline: [addFields, projection, sort]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,34 @@ export default async function catalogItems(_, args, context) {
const shopIds = opaqueShopIds && opaqueShopIds.map(decodeShopOpaqueId);
const tagIds = opaqueTagIds && opaqueTagIds.map(decodeTagOpaqueId);

if (connectionArgs.sortyBy === "featured") {
const tagId = tagIds[0];
const query = await context.queries.catalogItemsAggregate(context, {
shopIds,
tagId
});
console.log(query)
return getPaginatedAggregateResponse(query, connectionArgs);
}

if (connectionArgs.sortBy === "minPrice") {
if (typeof connectionArgs.sortByPriceCurrencyCode !== "string") {
throw new Error("sortByPriceCurrencyCode is required when sorting by minPrice");
}
connectionArgs.sortBy = `product.pricing.${connectionArgs.sortByPriceCurrencyCode}.minPrice`;
}
// if (connectionArgs.sortyBy === "featured") {
// const tagId = tagIds[0];
// const query = await context.queries.catalogItemsAggregate(context, {
// shopIds,
// tagId
// });
// return getPaginatedAggregateResponse(query, connectionArgs);
// }

const query = await context.queries.catalogItems(context, {
shopIds,
tagIds
});
// if (connectionArgs.sortBy === "minPrice") {
// if (typeof connectionArgs.sortByPriceCurrencyCode !== "string") {
// throw new Error("sortByPriceCurrencyCode is required when sorting by minPrice");
// }
// connectionArgs.sortBy = `product.pricing.${connectionArgs.sortByPriceCurrencyCode}.minPrice`;
// }

return getPaginatedResponse(query, connectionArgs);
// const query = await context.queries.catalogItems(context, {
// shopIds,
// tagIds
// });

// return getPaginatedResponse(query, connectionArgs);
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,9 @@ type CatalogItemProduct implements CatalogItem & Node {
"The date and time at which this CatalogItem was last updated, which is when the related product was most recently published"
updatedAt: DateTime!

"Testing order"
order: Int

"Featured position"
featuredPosition: Int
}
Expand Down

0 comments on commit b31f120

Please sign in to comment.