b59d4484ec
CI / verify (pull_request) Has been cancelled
Add partner/customer SMS confirm, address auto-receive or on-site pickup, proxy placer fields, PARTNER_PROXY user source, and C-end badge. Co-authored-by: Cursor <cursoragent@cursor.com>
82 lines
2.3 KiB
TypeScript
82 lines
2.3 KiB
TypeScript
import type { CommonEvent } from '@prisma/client';
|
|
|
|
type OrderLike = {
|
|
productName?: string;
|
|
productSpec?: string;
|
|
quantity?: number;
|
|
listUnitPrice?: unknown;
|
|
payAmount?: unknown;
|
|
payStatus?: string;
|
|
payExternalNo?: string | null;
|
|
paidAt?: Date | string | null;
|
|
imageResource?: { url?: string } | null;
|
|
};
|
|
|
|
export function mapOrderItemCompat(order: OrderLike) {
|
|
return {
|
|
productName: order.productName ?? '',
|
|
productSpec: order.productSpec ?? '',
|
|
productImage: order.imageResource?.url ?? '',
|
|
unitPrice: Number(order.listUnitPrice ?? 0),
|
|
quantity: order.quantity ?? 1,
|
|
};
|
|
}
|
|
|
|
export function mapOrderCompat<T extends OrderLike & {
|
|
orderType?: string | null;
|
|
proxyPartnerName?: string | null;
|
|
proxyPartnerPhone?: string | null;
|
|
proxyPartnerAccountId?: bigint | number | string | null;
|
|
}>(order: T) {
|
|
const payStatus = order.payStatus ?? 'UNPAID';
|
|
const isProxyOrder = order.orderType === 'PROXY';
|
|
return {
|
|
...order,
|
|
isProxyOrder,
|
|
proxyPartnerName: order.proxyPartnerName ?? null,
|
|
proxyPartnerPhone: order.proxyPartnerPhone ?? null,
|
|
items: [mapOrderItemCompat(order)],
|
|
payment: {
|
|
status: payStatus === 'PAID' ? 'SUCCESS' : payStatus,
|
|
externalNo: order.payExternalNo ?? null,
|
|
paidAt: order.paidAt ?? null,
|
|
},
|
|
};
|
|
}
|
|
|
|
export function mapStoreCompat<T extends { coverResource?: { url?: string } | null }>(store: T) {
|
|
return {
|
|
...store,
|
|
coverUrl: store.coverResource?.url ?? null,
|
|
};
|
|
}
|
|
|
|
export function mapStatusLogCompat(events: CommonEvent[]) {
|
|
return events.map((e) => ({
|
|
fromStatus: e.param1,
|
|
toStatus: e.param2 ?? '',
|
|
operator: e.param3,
|
|
remark: e.remark,
|
|
createdAt: e.createdAt,
|
|
}));
|
|
}
|
|
|
|
export function mapBenefitLedgerCompat(
|
|
event: CommonEvent,
|
|
user?: { userNo?: string | null } | null,
|
|
coupon?: { couponNo?: string } | null,
|
|
) {
|
|
return {
|
|
id: event.id,
|
|
type: event.param1,
|
|
amount: event.amount1 != null ? Number(event.amount1) : 0,
|
|
balanceAfter: event.amount2 != null ? Number(event.amount2) : 0,
|
|
remark: event.remark,
|
|
createdAt: event.createdAt,
|
|
userId: event.actorId,
|
|
couponId: event.param2 ? BigInt(event.param2) : null,
|
|
user: user ? { userNo: user.userNo } : undefined,
|
|
coupon: coupon ? { couponNo: coupon.couponNo } : undefined,
|
|
};
|
|
}
|