actionGoodsFind.js 1.5 KB

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