|
@@ -21,7 +21,7 @@ export const api = createApi({
|
|
|
url: API_URL,
|
|
|
prepareHeaders
|
|
|
}),
|
|
|
- tagTypes: ['Category', 'Order'],
|
|
|
+ tagTypes: ['Category', 'Order', 'Good'],
|
|
|
endpoints: (builder) => ({
|
|
|
getCategories: builder.query({
|
|
|
query: () => ({
|
|
@@ -113,7 +113,7 @@ export const api = createApi({
|
|
|
providesTags: (result, error, id) => ([{ type: 'User', id }])
|
|
|
}),
|
|
|
getOwnerOrder: builder.query({
|
|
|
- query: () => ({
|
|
|
+ query: ({ limit, skip }) => ({
|
|
|
document: gql`
|
|
|
query orders($q: String) {
|
|
|
OrderFind(query: $q) {
|
|
@@ -129,10 +129,19 @@ export const api = createApi({
|
|
|
}
|
|
|
}
|
|
|
`,
|
|
|
- variables: { q: JSON.stringify([{}]) }
|
|
|
+ variables: { q: JSON.stringify([{}, { limit: [limit], skip: [skip] }]) }
|
|
|
}),
|
|
|
providesTags: ['Order'],
|
|
|
}),
|
|
|
+ getOrderCount: builder.query({
|
|
|
+ query: () => ({
|
|
|
+ document: gql`
|
|
|
+ query getOrderCount($q: String) {
|
|
|
+ OrderCount(query: $q)
|
|
|
+ }`,
|
|
|
+ variables: { q: JSON.stringify([{}]) }
|
|
|
+ })
|
|
|
+ }),
|
|
|
getOrderGood: builder.query({
|
|
|
query: () => ({
|
|
|
document: gql`
|
|
@@ -161,22 +170,32 @@ export const api = createApi({
|
|
|
query GetGoods($q: String) {
|
|
|
GoodFind(query: $q) {
|
|
|
_id, name, description, price, categories {
|
|
|
- _id
|
|
|
+ _id, name
|
|
|
}
|
|
|
}
|
|
|
}`,
|
|
|
variables: { q: JSON.stringify([{}]) }
|
|
|
+ }),
|
|
|
+ providesTags: ['Good'],
|
|
|
+ }),
|
|
|
+ getUserCount: builder.query({
|
|
|
+ query: () => ({
|
|
|
+ document: gql`
|
|
|
+ query GetUserCount($q: String) {
|
|
|
+ UserCount(query: $q)
|
|
|
+ }`,
|
|
|
+ variables: { q: JSON.stringify([{}]) }
|
|
|
})
|
|
|
}),
|
|
|
getUsers: builder.query({
|
|
|
- query: () => ({
|
|
|
+ query: ({ skip, limit }) => ({
|
|
|
document: gql`
|
|
|
query GetUsers($q: String) {
|
|
|
UserFind(query: $q) {
|
|
|
_id, login, createdAt
|
|
|
}
|
|
|
}`,
|
|
|
- variables: { q: JSON.stringify([{}]) }
|
|
|
+ variables: { q: JSON.stringify([{}, { skip: [skip], limit: [limit] }]) }
|
|
|
})
|
|
|
}),
|
|
|
login: builder.mutation({
|
|
@@ -242,20 +261,50 @@ export const api = createApi({
|
|
|
}),
|
|
|
invalidatesTags: ['Category'],
|
|
|
}),
|
|
|
+ createGood: builder.mutation({
|
|
|
+ query: (good) => ({
|
|
|
+ document: gql`
|
|
|
+ mutation createGood($good: GoodInput) {
|
|
|
+ GoodUpsert(good: $good) {
|
|
|
+ _id
|
|
|
+ }
|
|
|
+ }`,
|
|
|
+ variables: { good }
|
|
|
+ }),
|
|
|
+ invalidatesTags: ['Good']
|
|
|
+ }),
|
|
|
+ deleteGood: builder.mutation({
|
|
|
+ query: (good) => ({
|
|
|
+ document: gql`
|
|
|
+ mutation deleteGood($good: GoodInput) {
|
|
|
+ GoodDelete(good: $good) {
|
|
|
+ _id, name, images {
|
|
|
+ url, _id
|
|
|
+ }, price, description
|
|
|
+ }
|
|
|
+ }`,
|
|
|
+ variables: { good }
|
|
|
+ }),
|
|
|
+ invalidatesTags: ['Good']
|
|
|
+ }),
|
|
|
}),
|
|
|
});
|
|
|
|
|
|
+export const createGood = good =>
|
|
|
+ async dispatch => {
|
|
|
+ await dispatch(api.endpoints.createGood.initiate(good));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
export const createCategory = category =>
|
|
|
async dispatch => {
|
|
|
- console.log(category);
|
|
|
- const payload = await dispatch(api.endpoints.createCategory.initiate(category));
|
|
|
- console.log('category created', payload);
|
|
|
+ await dispatch(api.endpoints.createCategory.initiate(category));
|
|
|
}
|
|
|
|
|
|
export const deleteCategory = category =>
|
|
|
async dispatch => {
|
|
|
- const payload = await dispatch(api.endpoints.deleteCategory.initiate(category));
|
|
|
- console.log('deleted', payload);
|
|
|
+ await dispatch(api.endpoints.deleteCategory.initiate(category));
|
|
|
}
|
|
|
|
|
|
export const actionOrder = orderGoods =>
|
|
@@ -371,4 +420,5 @@ export const cartSlice = createSlice({
|
|
|
});
|
|
|
export const { addGood, deleteGood, decreaseGoodCount, setGoodCount, clearCart } = cartSlice.actions;
|
|
|
export const { useGetCategoriesQuery, useGetCategoryByIdQuery, useGetGoodByIdQuery, useLoginMutation, useGetOwnerOrderQuery,
|
|
|
- useRegisterMutation, useGetUserByIdQuery, useCreateCategoryMutation, useGetGoodsQuery, useGetUsersQuery, useGetOrderGoodQuery } = api;
|
|
|
+ useRegisterMutation, useGetUserByIdQuery, useCreateCategoryMutation, useGetGoodsQuery, useGetUsersQuery, useGetOrderGoodQuery,
|
|
|
+ useGetUserCountQuery, useGetOrderCountQuery } = api;
|