33 lines
788 B
TypeScript
33 lines
788 B
TypeScript
import type { Giftcard } from '@/model/giftCard'
|
|
|
|
export function resolveGiftCardCustomer(giftCard?: Giftcard | null) {
|
|
if (!giftCard) return null
|
|
|
|
const name = giftCard.customer?.name ?? giftCard.name
|
|
const mobile = giftCard.customer?.mobile ?? giftCard.mobile
|
|
|
|
if (name || mobile) {
|
|
return {
|
|
name: name || '-',
|
|
mobile: mobile || '-',
|
|
}
|
|
}
|
|
|
|
if (giftCard.customer_id) {
|
|
return {
|
|
name: `مشتری #${giftCard.customer_id}`,
|
|
mobile: '-',
|
|
}
|
|
}
|
|
|
|
return null
|
|
}
|
|
|
|
export function giftCardCustomerLabel(giftCard?: Giftcard | null) {
|
|
return resolveGiftCardCustomer(giftCard)?.name ?? '— (کد عمومی)'
|
|
}
|
|
|
|
export function giftCardCustomerMobile(giftCard?: Giftcard | null) {
|
|
return resolveGiftCardCustomer(giftCard)?.mobile ?? '-'
|
|
}
|