apply order cancaltion

This commit is contained in:
2025-11-24 00:05:25 +03:00
parent b9c5ab69e6
commit 6e8305f9c2
4 changed files with 63 additions and 12 deletions

View File

@@ -5,13 +5,15 @@ import {
ORDER_DETAILS_URL,
ORDERS_URL,
PRODUCTS_AND_CATEGORIES_URL,
RATE_ORDER_URL,
RESTAURANT_DETAILS_URL,
TABLES_URL,
USER_DETAILS_URL,
} from "utils/constants";
import { OrderDetails } from "pages/checkout/hooks/types";
import menuParser from "pages/menu/helper";
import { DiscountResultType, RestaurantDetails } from "utils/types/appTypes";
import { DiscountResultType, RestaurantDetails, UserType } from "utils/types/appTypes";
import { baseApi } from "./apiSlice";
export const branchApi = baseApi.injectEndpoints({
@@ -55,10 +57,12 @@ export const branchApi = baseApi.injectEndpoints({
invalidatesTags: ["Orders", "Restaurant"],
}),
cancelOrder: builder.mutation({
query: (body: any) => ({
query: ({ orderID }: { orderID: string }) => ({
url: CANCEL_ORDER_URL,
method: "POST",
body,
body: {
order_id: orderID,
},
}),
invalidatesTags: ["Orders", "Restaurant"],
}),
@@ -103,7 +107,7 @@ export const branchApi = baseApi.injectEndpoints({
},
}),
getDiscount: builder.mutation<
DiscountResultType,
DiscountResultType,
{ discountCode: string; restaurantID: string }
>({
query: ({
@@ -113,13 +117,48 @@ export const branchApi = baseApi.injectEndpoints({
discountCode: string;
restaurantID: string;
}) => ({
url: `${DISCOUNT_URL}/${discountCode}/${restaurantID}`,
url: `${DISCOUNT_URL}/${discountCode}/${restaurantID}`,
method: "GET",
}),
transformResponse: (response: any) => {
return response.result;
},
}),
getUserDetails: builder.query<
UserType,
void
>({
query: () => ({
url: `${USER_DETAILS_URL}`,
method: "GET",
}),
transformResponse: (response: any) => {
return response.result;
},
}),
rateOrder: builder.mutation({
query: ({
orderID,
rating,
comment,
userID,
}: {
orderID: string;
rating: number;
comment: string;
userID: string;
}) => ({
url: RATE_ORDER_URL,
method: "POST",
body: {
order_id: orderID,
rating,
comment,
user_id: userID,
},
}),
invalidatesTags: ["Orders", "Restaurant"],
}),
}),
});
export const {
@@ -130,5 +169,7 @@ export const {
useGetTablesQuery,
useGetOrderDetailsQuery,
useCancelOrderMutation,
useGetDiscountMutation
useGetDiscountMutation,
useRateOrderMutation,
useGetUserDetailsQuery,
} = branchApi;