97 lines
2.1 KiB
TypeScript
97 lines
2.1 KiB
TypeScript
import { Entity, Column, PrimaryColumn } from "typeorm";
|
|
|
|
|
|
export enum BillingUnitCategory{
|
|
TRANSACTIONS,
|
|
USERS
|
|
}
|
|
|
|
export enum Currency{
|
|
EUR,
|
|
USD,
|
|
GBP,
|
|
JPY,
|
|
CNY,
|
|
INR,
|
|
AUD,
|
|
CAD,
|
|
CHF,
|
|
MXN
|
|
}
|
|
|
|
@Entity()
|
|
export class PaymentPlanTemplate{
|
|
|
|
@PrimaryColumn()
|
|
name!:string
|
|
|
|
@Column()
|
|
BillingType!:BillingUnitCategory
|
|
|
|
@Column({type:"float"})
|
|
PricePerUnitOverMin!:number
|
|
|
|
@Column()
|
|
MinUnits!:number
|
|
|
|
@Column({type:"float"})
|
|
MinPrice!:number
|
|
|
|
@Column({default:0})
|
|
MaxUnits!:number
|
|
|
|
@Column({default:Currency.EUR})
|
|
Currency!:Currency
|
|
|
|
builderCurrency(currency: Currency){
|
|
this.Currency = currency
|
|
return this
|
|
}
|
|
builderBillingType(BillingType: BillingUnitCategory){
|
|
this.BillingType = BillingType
|
|
return this
|
|
}
|
|
builderMinUnits(minUnits: number){
|
|
this.MinUnits = minUnits
|
|
return this;
|
|
}
|
|
builderMinPrice(minPrice: number){
|
|
this.MinPrice = minPrice
|
|
return this
|
|
}
|
|
builderPricePerUnitOverMin(pricePerUnitOverMin: number){
|
|
this.PricePerUnitOverMin = pricePerUnitOverMin;
|
|
return this
|
|
}
|
|
builderName(name: string){
|
|
this.name = name;
|
|
return this;
|
|
}
|
|
builderMaxUnits(maxUnits: number){
|
|
this.MaxUnits = maxUnits
|
|
return this
|
|
}
|
|
|
|
|
|
}
|
|
|
|
export function isPaymentPlantTemplate(instance: any): instance is PaymentPlanTemplate{
|
|
return typeof instance.name == "string"
|
|
&& typeof instance.Currency == "number"
|
|
&& instance.Currency in Currency
|
|
&& typeof instance.MinUnits == "number"
|
|
&& typeof instance.MaxUnits == "number"
|
|
&& typeof instance.PricePerUnitOverMin == "number"
|
|
&& typeof instance.MinPrice == "number"
|
|
&& typeof instance.BillingType == "number"
|
|
&& instance.BillingType in BillingUnitCategory
|
|
}
|
|
|
|
export const defaultPaymentPlanTemplate = new PaymentPlanTemplate()
|
|
.builderName("dev")
|
|
.builderMinUnits(0)
|
|
.builderMinPrice(0)
|
|
.builderBillingType(BillingUnitCategory.USERS)
|
|
.builderMaxUnits(10)
|
|
.builderPricePerUnitOverMin(0)
|
|
.builderCurrency(Currency.EUR) |