actionGoodsFind.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. or: { name__icontains: text, description__icontains: text },
  32. },
  33. {
  34. limit: !!limit ? limit : 5,
  35. skip,
  36. orderBy,
  37. },
  38. ]),
  39. }
  40. )
  41. )
  42. );
  43. }