d29ed8e35b
- Updated ProductVariant model to include 'profit' and 'special_discount_percent' fields. - Added corresponding fields in the admin interface for ProductVariant. - Created migration to add new fields to the database. feat: implement special discount code functionality in cart - Added composables for submitting and deleting special discount codes. - Updated CartSummary and CartItem components to handle special discount codes. - Enhanced API endpoints to support special discount operations. - Updated global types to include special discount code details in the cart.
38 lines
833 B
TypeScript
38 lines
833 B
TypeScript
// imports
|
|
|
|
import { useMutation } from "@tanstack/vue-query";
|
|
import { API_ENDPOINTS } from "~/constants";
|
|
|
|
// types
|
|
|
|
export type SubmitSpecialDiscountCodeRequest = {
|
|
code: string;
|
|
};
|
|
|
|
const useSubmitSpecialDiscountCode = () => {
|
|
// state
|
|
|
|
const { $axios: axios } = useNuxtApp();
|
|
|
|
// methods
|
|
|
|
const handleSubmitSpecialDiscountCode = async (
|
|
params: SubmitSpecialDiscountCodeRequest
|
|
) => {
|
|
const { data } = await axios.post(
|
|
API_ENDPOINTS.orders.cart.add_special_discount,
|
|
{
|
|
...params,
|
|
}
|
|
);
|
|
return data;
|
|
};
|
|
|
|
return useMutation({
|
|
mutationFn: (discountData: SubmitSpecialDiscountCodeRequest) =>
|
|
handleSubmitSpecialDiscountCode(discountData),
|
|
});
|
|
};
|
|
|
|
export default useSubmitSpecialDiscountCode;
|