ActionCategory.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. import {actionPromise} from "../reducers/PromiseReducer";
  2. import {gql} from "./PathDB";
  3. import {actionCategoryChange, actionCategoryCreate} from "../reducers/CategoryReducer";
  4. //CategoryFind -- parent: null
  5. export const actionRootCats = () => {
  6. return actionPromise('rootCats', gql(`query rootCats{
  7. CategoryFind(query: "[{\\"parent\\": null}]"){
  8. _id
  9. name
  10. subCategories{
  11. _id,
  12. name,
  13. subCategories{
  14. _id,
  15. name
  16. }
  17. }
  18. }
  19. }`)
  20. )
  21. }
  22. export const actionFullRootCats = () =>
  23. async dispatch => {
  24. let value = await dispatch(actionRootCats())
  25. if (value){
  26. dispatch(actionCategoryCreate(value))
  27. }
  28. }
  29. //CategoryFindOne
  30. const actionCatById = (_id) => {
  31. return actionPromise('catById', gql(`query catById($q: String){
  32. CategoryFindOne(query: $q){
  33. _id goods {
  34. _id createdAt name description price images {
  35. url
  36. }
  37. }
  38. }
  39. }`, {q: JSON.stringify([{_id}])}))
  40. }
  41. export const actionFullCatById = (_id) =>
  42. async dispatch => {
  43. let value = await dispatch(actionCatById(_id))
  44. if (value){
  45. dispatch(actionCategoryChange(value))
  46. }
  47. }
  48. //CategoryCount
  49. export const actionCategoryCount = () => {
  50. return actionPromise('categoryCount', gql(`query categoryCount{
  51. CategoryCount(query: "[{}]")
  52. }`
  53. )
  54. )
  55. }
  56. //CategoryUpsert
  57. export const actionCategoryUpsert = category =>
  58. async dispatch => {
  59. let value = await dispatch(actionPromise('categoryUpsert', gql(`
  60. mutation categoryUpsert($category: CategoryInput){
  61. CategoryUpsert(category: $category) {
  62. _id
  63. }
  64. }`, {"category": {...category}}
  65. )
  66. ))
  67. if (value) {
  68. await dispatch(actionFullRootCats())
  69. }
  70. }
  71. //CategoryFind
  72. export const actionAllCategory = () => {
  73. return actionPromise('allCategory', gql(`query allCategory{
  74. CategoryFind(query: "[{}]"){
  75. _id
  76. name
  77. subCategories{
  78. _id,
  79. name,
  80. subCategories{
  81. _id,
  82. name
  83. }
  84. }
  85. }
  86. }`)
  87. )
  88. }
  89. export const actionFullAllCategory = () =>
  90. async dispatch => {
  91. let value = await dispatch(actionAllCategory())
  92. if (value){
  93. dispatch(actionCategoryCreate(value))
  94. }
  95. }