feat: add superadmin member review and coupon ops
This commit is contained in:
@@ -40,5 +40,55 @@ export const CouponService = {
|
||||
total: data?.total ?? 0,
|
||||
items: normalizeItems(data?.items)
|
||||
};
|
||||
},
|
||||
async createCoupon(tenantID, form = {}) {
|
||||
if (!tenantID) throw new Error('tenantID is required');
|
||||
return requestJson(`/super/v1/tenants/${tenantID}/coupons`, {
|
||||
method: 'POST',
|
||||
body: normalizeCouponForm(form)
|
||||
});
|
||||
},
|
||||
async getCoupon(tenantID, couponID) {
|
||||
if (!tenantID) throw new Error('tenantID is required');
|
||||
if (!couponID) throw new Error('couponID is required');
|
||||
return requestJson(`/super/v1/tenants/${tenantID}/coupons/${couponID}`);
|
||||
},
|
||||
async updateCoupon(tenantID, couponID, form = {}) {
|
||||
if (!tenantID) throw new Error('tenantID is required');
|
||||
if (!couponID) throw new Error('couponID is required');
|
||||
return requestJson(`/super/v1/tenants/${tenantID}/coupons/${couponID}`, {
|
||||
method: 'PUT',
|
||||
body: normalizeCouponForm(form)
|
||||
});
|
||||
},
|
||||
async grantCoupon(tenantID, couponID, userIDs = []) {
|
||||
if (!tenantID) throw new Error('tenantID is required');
|
||||
if (!couponID) throw new Error('couponID is required');
|
||||
if (!Array.isArray(userIDs) || userIDs.length === 0) throw new Error('userIDs is required');
|
||||
return requestJson(`/super/v1/tenants/${tenantID}/coupons/${couponID}/grant`, {
|
||||
method: 'POST',
|
||||
body: { user_ids: userIDs }
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function normalizeCouponForm(form) {
|
||||
const iso = (d) => {
|
||||
if (!d) return undefined;
|
||||
const date = d instanceof Date ? d : new Date(d);
|
||||
if (Number.isNaN(date.getTime())) return undefined;
|
||||
return date.toISOString();
|
||||
};
|
||||
|
||||
return {
|
||||
title: form.title,
|
||||
description: form.description,
|
||||
type: form.type,
|
||||
value: form.value,
|
||||
min_order_amount: form.min_order_amount,
|
||||
max_discount: form.max_discount,
|
||||
total_quantity: form.total_quantity,
|
||||
start_at: iso(form.start_at),
|
||||
end_at: iso(form.end_at)
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user