39 lines
881 B
TypeScript
39 lines
881 B
TypeScript
import {CreateResourceReq} from '@/actions/resource'
|
|
|
|
export type PurchaseKind = 'short' | 'long'
|
|
export type PurchaseMode = '1' | '2'
|
|
|
|
export type PurchaseSelection = {
|
|
kind: PurchaseKind
|
|
mode: PurchaseMode
|
|
live: string
|
|
quota: number
|
|
expire: string
|
|
dailyLimit: number
|
|
}
|
|
|
|
function getPurchasePayload(selection: PurchaseSelection) {
|
|
return {
|
|
mode: Number(selection.mode),
|
|
live: Number(selection.live),
|
|
expire: selection.mode === '1' ? Number(selection.expire) : undefined,
|
|
quota: selection.mode === '1' ? Number(selection.dailyLimit) : Number(selection.quota),
|
|
}
|
|
}
|
|
|
|
export function buildPurchaseResource(selection: PurchaseSelection): CreateResourceReq {
|
|
const payload = getPurchasePayload(selection)
|
|
|
|
if (selection.kind === 'short') {
|
|
return {
|
|
type: 1,
|
|
short: payload,
|
|
}
|
|
}
|
|
|
|
return {
|
|
type: 2,
|
|
long: payload,
|
|
}
|
|
}
|