ActionGoodFind.js 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. }, categories {
  21. _id, name
  22. }
  23. }
  24. }`, {query: JSON.stringify([
  25. {
  26. $or: [{name: `/${text}/`}, {description: `/${text}/`}]
  27. },
  28. {
  29. sort: [{title: 1}]
  30. }
  31. ])}
  32. )
  33. )
  34. export const actionFullGoodFind = (text) =>
  35. async dispatch => {
  36. let value = await dispatch(actionGoodFind(text))
  37. if (value){
  38. dispatch(actionSearchResult(value))
  39. }
  40. }
  41. export const actionAllGoodFind = () => {
  42. return actionPromise('goodAllFind', gql(`
  43. query goodAllFind($query: String){
  44. GoodFind(query: $query){
  45. _id name
  46. }
  47. }`, {query: JSON.stringify([{name: {$ne: null}}])}
  48. )
  49. )
  50. }
  51. //GoodCount
  52. export const actionGoodCount = () => {
  53. return actionPromise('goodCount', gql(`query goodCount{
  54. GoodCount(query: "[{}]")
  55. }`
  56. )
  57. )
  58. }