ActionGoodFind.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {actionSearchResult} from "../reducers/SearchReducer";
  2. const {actionPromise} = require("../reducers/PromiseReducer");
  3. const {gql} = require("./PathDB");
  4. //GoodFindOne
  5. export const actionGoodFindOne = (_id) =>
  6. actionPromise('goodFindOne', gql(`query goodFindOne($q :String){
  7. GoodFindOne(query: $q){
  8. _id name price createdAt description images{
  9. _id url originalFileName
  10. }, categories {
  11. _id name
  12. }
  13. }
  14. }`, { q: JSON.stringify([{ _id }]) }))
  15. //GoodFind
  16. export const actionGoodFind = (text) => {
  17. return actionPromise('goodFind', gql(`
  18. query goodFind($query: String){
  19. GoodFind(query: $query){
  20. _id, name, description, price, images{
  21. _id, url
  22. }, categories {
  23. _id, name
  24. }
  25. }
  26. }`, {
  27. query: JSON.stringify([
  28. {
  29. $or: [{name: `/${text}/`}, {description: `/${text}/`}]
  30. },
  31. {
  32. sort: [{title: 1}]
  33. }
  34. ])
  35. }
  36. )
  37. )
  38. }
  39. export const actionFullGoodFind = (text) =>
  40. async dispatch => {
  41. let value = await dispatch(actionGoodFind(text))
  42. if (value){
  43. dispatch(actionSearchResult(value))
  44. }
  45. }
  46. //GoodFind - name: {$ne: null}
  47. export const actionAllGoodFind = () => {
  48. return actionPromise('goodAllFind', gql(`
  49. query goodAllFind($query: String){
  50. GoodFind(query: $query){
  51. _id name
  52. }
  53. }`, {query: JSON.stringify([{name: {$ne: null}}])}
  54. )
  55. )
  56. }
  57. //GoodCount
  58. export const actionGoodCount = () => {
  59. return actionPromise('goodCount', gql(`query goodCount{
  60. GoodCount(query: "[{}]")
  61. }`
  62. )
  63. )
  64. }