Allowance.js 890 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. export default class Allowance{
  2. constructor(id, name, amount, isPercent){
  3. this._id = id;
  4. this._name = name;
  5. this._amount = amount;
  6. this._isPercent = isPercent;
  7. }
  8. get id(){
  9. return this._id;
  10. }
  11. get name(){
  12. return this._name;
  13. }
  14. get type(){
  15. return "Allowance";
  16. }
  17. static create(name, amount, isPercent){
  18. return new Allowance(
  19. crypto.randomUUID(),
  20. name,
  21. amount,
  22. isPercent
  23. );
  24. }
  25. static fromObject(data){
  26. return new Allowance(
  27. data.id,
  28. data.name,
  29. data.amount,
  30. data.isPercent
  31. );
  32. }
  33. serialize(){
  34. return {
  35. id: this._id,
  36. name: this._name,
  37. amount: this._amount,
  38. isPercent: this._isPercent
  39. };
  40. }
  41. }