12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- import {actionPromise} from "../reducers/PromiseReducer";
- import {gql} from "./PathDB";
- import {actionCategoryChange, actionCategoryCreate} from "../reducers/CategoryReducer";
- export const actionRootCats = () => {
- return actionPromise('rootCats', gql(`query rootCats{
- CategoryFind(query: "[{\\"parent\\": null}]"){
- _id
- name
- subCategories{
- _id,
- name,
- subCategories{
- _id,
- name
- }
- }
- }
- }`)
- )
- }
- export const actionFullRootCats = () =>
- async dispatch => {
- let value = await dispatch(actionRootCats())
- if (value){
- dispatch(actionCategoryCreate(value))
- }
- }
- const actionCatById = (_id) => {
- return actionPromise('catById', gql(`query catById($q: String){
- CategoryFindOne(query: $q){
- _id goods {
- _id createdAt name description price images {
- url
- }
- }
- }
- }`, {q: JSON.stringify([{_id}])}))
- }
- export const actionFullCatById = (_id) =>
- async dispatch => {
- let value = await dispatch(actionCatById(_id))
- if (value){
- dispatch(actionCategoryChange(value))
- }
- }
|