ActionGoodFind.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import {actionSearchResult} from "../reducers/SearchReducer";
  2. const {actionPromise} = require("../reducers/PromiseReducer");
  3. const {gql} = require("./PathDB");
  4. export const actionGoodFindOne = (_id) =>
  5. actionPromise('goodFindOne', gql(`query goodFindOne($q :String){
  6. GoodFindOne(query: $q){
  7. _id name price createdAt description images{
  8. _id url originalFileName
  9. }, categories {
  10. _id name
  11. }
  12. }
  13. }`, { q: JSON.stringify([{ _id }]) }))
  14. export const actionGoodFind = (text) =>
  15. actionPromise('goodFind', gql(`
  16. query goodFind($query: String){
  17. GoodFind(query: $query){
  18. _id, name, description, price, images{
  19. _id, url
  20. }
  21. }
  22. }`, {query: JSON.stringify([
  23. {
  24. $or: [{name: `/${text}/`}, {description: `/${text}/`}]
  25. },
  26. {
  27. sort: [{title: 1}]
  28. }
  29. ])}
  30. )
  31. )
  32. export const actionFullGoodFind = (text) =>
  33. async dispatch => {
  34. let value = await dispatch(actionGoodFind(text))
  35. if (value){
  36. dispatch(actionSearchResult(value))
  37. }
  38. }