actionCategoryGoods.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { call } from "redux-saga/effects";
  2. import { gql } from "../helpers";
  3. import { actionPromise } from "../reducers";
  4. import { promiseWorker } from "../reducers/promiseReducer";
  5. export const actionCategoryGoods = ({ limit = 20, skip = 0, promiseName = "categoryGoods", orderBy = "_id", category } = {}) => ({
  6. type: "CATEGORY_GOODS",
  7. payload: { limit, skip, promiseName, orderBy, category },
  8. });
  9. export function* categoryGoodsWorker(action) {
  10. const { limit = 20, skip = 0, promiseName = "categoryGoods", orderBy = "_id", category } = action.payload || {};
  11. if (!category) {
  12. return;
  13. }
  14. yield call(
  15. promiseWorker,
  16. actionPromise(
  17. promiseName,
  18. gql(
  19. `query CategoryGoods($query:String){
  20. GoodFind(query: $query){
  21. _id name price images{
  22. _id url
  23. }
  24. categories{
  25. _id name
  26. }
  27. amount
  28. }
  29. }`,
  30. {
  31. query: JSON.stringify([
  32. {
  33. categories__in: [category._id],
  34. },
  35. {
  36. limit: !!limit ? limit : 100,
  37. skip: skip,
  38. orderBy,
  39. },
  40. ]),
  41. }
  42. )
  43. )
  44. );
  45. }