ActionCategory.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {actionPromise} from "../reducers/PromiseReducer";
  2. import {gql} from "./PathDB";
  3. import {actionCategoryChange, actionCategoryCreate} from "../reducers/CategoryReducer";
  4. export const actionRootCats = () => {
  5. return actionPromise('rootCats', gql(`query rootCats{
  6. CategoryFind(query: "[{\\"parent\\": null}]"){
  7. _id
  8. name
  9. subCategories{
  10. _id,
  11. name,
  12. subCategories{
  13. _id,
  14. name
  15. }
  16. }
  17. }
  18. }`)
  19. )
  20. }
  21. export const actionFullRootCats = () =>
  22. async dispatch => {
  23. let value = await dispatch(actionRootCats())
  24. if (value){
  25. dispatch(actionCategoryCreate(value))
  26. }
  27. }
  28. const actionCatById = (_id) => {
  29. return actionPromise('catById', gql(`query catById($q: String){
  30. CategoryFindOne(query: $q){
  31. _id goods {
  32. _id name description price images {
  33. url
  34. }
  35. }
  36. }
  37. }`, {q: JSON.stringify([{_id}])}))
  38. }
  39. export const actionFullCatById = (_id) =>
  40. async dispatch => {
  41. let value = await dispatch(actionCatById(_id))
  42. if (value){
  43. dispatch(actionCategoryChange(value))
  44. }
  45. }