dev #21
@ -1,4 +1,5 @@
|
|||||||
import { authFetch } from '../../../utils/authFetch'
|
import { authFetch } from '../../../utils/authFetch'
|
||||||
|
import { getOrderPackError } from '../../lib/orderRules'
|
||||||
|
|
||||||
export type SubscribeAboItem = { coffeeId: string | number; quantity?: number }
|
export type SubscribeAboItem = { coffeeId: string | number; quantity?: number }
|
||||||
export type SubscribeAboInput = {
|
export type SubscribeAboInput = {
|
||||||
@ -123,11 +124,11 @@ export async function subscribeAbo(input: SubscribeAboInput) {
|
|||||||
coffeeId: i.coffeeId,
|
coffeeId: i.coffeeId,
|
||||||
quantity: i.quantity != null ? i.quantity : 1,
|
quantity: i.quantity != null ? i.quantity : 1,
|
||||||
}))
|
}))
|
||||||
// NEW: enforce supported package sizes
|
|
||||||
const sumPacks = body.items.reduce((s: number, it: any) => s + Number(it.quantity || 0), 0)
|
const sumPacks = body.items.reduce((s: number, it: any) => s + Number(it.quantity || 0), 0)
|
||||||
if (sumPacks !== 6 && sumPacks !== 12) {
|
const orderPackError = getOrderPackError(sumPacks)
|
||||||
console.warn('[subscribeAbo] Invalid pack total:', sumPacks, 'expected 6 or 12')
|
if (orderPackError) {
|
||||||
throw new Error('Order must contain exactly 6 packs (60 capsules) or 12 packs (120 capsules).')
|
console.warn('[subscribeAbo] Invalid pack total:', sumPacks, orderPackError)
|
||||||
|
throw new Error(orderPackError)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
body.coffeeId = input.coffeeId
|
body.coffeeId = input.coffeeId
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user