ok
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user