Transaction.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. class TransactionRecipe{
  2. constructor(recipe, quantity){
  3. if(quantity < 0){
  4. banner.createError("QUANTITY CANNOT BE A NEGATIVE NUMBER");
  5. return false;
  6. }
  7. if(quantity % 1 !== 0){
  8. banner.createError("RECIPES WITHIN A TRANSACTION MUST BE WHOLE NUMBERS");
  9. return false;
  10. }
  11. this._recipe = recipe;
  12. this._quantity = quantity;
  13. }
  14. get recipe(){
  15. return this._recipe;
  16. }
  17. get quantity(){
  18. return this._quantity;
  19. }
  20. }
  21. class Transaction{
  22. constructor(id, date, recipes, parent){
  23. date = new Date(date);
  24. if(date > new Date()){
  25. banner.createError("DATE CANNOT BE SET TO THE FUTURE");
  26. return false;
  27. }
  28. this._id = id;
  29. this._parent = parent;
  30. this._date = date;
  31. this._recipes = [];
  32. for(let i = 0; i < recipes.length; i++){
  33. const transactionRecipe = new TransactionRecipe(
  34. recipes[i].recipe,
  35. recipes[i].quantity
  36. )
  37. this._recipes.push(transactionRecipe);
  38. }
  39. }
  40. get id(){
  41. return this._id;
  42. }
  43. get parent(){
  44. return this._parent;
  45. }
  46. get date(){
  47. return this._date;
  48. }
  49. get recipes(){
  50. return this._recipes;
  51. }
  52. }
  53. module.exports = Transaction;