This commit is contained in:
zadit
2025-02-02 18:17:56 +07:00
parent b0813e1519
commit 02e101025e
13 changed files with 216 additions and 738 deletions

View File

@@ -6,7 +6,33 @@ import API_BASE_URL from '../config.js';
export function getAuthToken() {
return localStorage.getItem('auth');
}
// Function to create a coupon
export async function createCoupon(discountType, discountValue, discountPeriods) {
try {
const response = await fetch(`${API_BASE_URL}/coupon/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${getAuthToken()}`,
},
body: JSON.stringify({
discountType,
discountValue,
discountPeriods,
}),
});
if (response.ok) {
const data = await response.json();
return { success: true, couponCode: data.coupon.code };
} else {
return { success: false, message: 'Failed to create coupon.' };
}
} catch (error) {
console.error('Error creating coupon:', error);
return { success: false, message: 'Error creating coupon.' };
}
}
// Function to check the validity of the coupon code
export async function checkCoupon(couponCode) {
try {