41 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-12-09 18:22:44 +00:00
/* Copyright (C) 2024 Manuel Bustillo*/
import { Serializable } from "../api/abstract-api";
import { Entity } from "./definitions";
export const pricingTypes = ['fixed', 'per_person'] as const;
export type PricingType = typeof pricingTypes[number];
export class Expense implements Entity {
id?: string;
2024-12-09 20:12:18 +01:00
name?: string;
amount?: number;
pricingType?: PricingType;
constructor(id?: string, name?: string, amount?: number, pricingType?: PricingType) {
this.id = id;
this.name = name || '';
this.amount = amount || 0;
this.pricingType = pricingType || 'fixed';
}
}
export class ExpenseSerializer implements Serializable<Expense>{
fromJson(data: any): Expense {
return new Expense(data.id, data.name, data.amount, data.pricing_type);
}
toJson(expense: Expense): string {
return JSON.stringify({
expense: {
name: expense.name,
amount: expense.amount,
pricing_type: expense.pricingType
}
});
}
apiPath(): string {
return 'expenses';
}
}