| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- class OrderIngredient{
- constructor(ingredient, quantity){
- if(quantity < 0){
- banner.createError = "QUANTITY CANNOT BE A NEGATIVE NUBMER";
- return false;
- }
- this._ingredient = ingredient;
- this.quantity = this.convertToBase(quantity);
- }
- get ingredient(){
- return this._ingredient;
- }
- get quantity(){
- switch(unit){
- case "g":return this._quantity;
- case "kg": return this._quantity * 1000;
- case "oz": return this._quantity * 28.3495;
- case "lb": return this._quantity * 453.5924;
- case "ml": return this._quantity / 1000;
- case "l": return this._quantity;
- case "tsp": return this._quantity / 202.8842;
- case "tbsp": return this._quantity / 67.6278;
- case "ozfl": return this._quantity / 33.8141;
- case "cup": return this._quantity / 4.1667;
- case "pt": return this._quantity / 2.1134;
- case "qt": return this._quantity / 1.0567;
- case "gal": return this._quantity * 3.7854;
- case "mm": return this._quantity / 1000;
- case "cm": return this._quantity / 100;
- case "m": return this._quantity;
- case "in": return this._quantity / 39.3701;
- case "ft": return this._quantity / 3.2808;
- default: return this._quantity;
- }
- }
- convertToBase(quantity){
- switch(this._ingredient.unit){
- case "g": return quantity;
- case "kg": return quantity / 1000;
- case "oz": return quantity / 28.3495;
- case "lb": return quantity / 453.5924;
- case "ml": return quantity *= 1000;
- case "l": return quantity;
- case "tsp": return quantity * 202.8842;
- case "tbsp": return quantity * 67.6278;
- case "ozfl": return quantity * 33.8141;
- case "cup": return quantity * 4.1667;
- case "pt": return quantity * 2.1134;
- case "qt": return quantity * 1.0567;
- case "gal": return quantity / 3.7854;
- case "mm": return quantity * 1000;
- case "cm": return quantity * 100;
- case "m": return quantity;
- case "in": return quantity * 39.3701;
- case "ft": return quantity * 3.2808;
- default: return quantity;
- }
- }
- }
- class Order{
- constructor(id, name, date, taxes, fees, ingredients, parent){
- if(!this.isSanitaryString(name)){
- banner.createError("NAME CONTAINS ILLEGAL CHARACTERS");
- return false;
- }
- if(taxes < 0){
- banner.createError("TAXES CANNOT BE A NEGATIVE NUMBER");
- }
- this._id = id;
- this._name = name;
- this._date = new Date(date);
- this._taxes = taxes;
- this._fees = fees;
- this._ingredients = [];
- this._parent = parent;
- if(date > new Date()){
- banner.createError("CANNOT SET A DATE IN THE FUTURE");
- return false;
- }
- for(let i = 0; i < ingredients.length; i++){
- const orderIngredient = new OrderIngredient(
- ingredients[i].ingredient,
- ingredients[i].quantity
- )
- this._ingredients.push(orderIngredient);
- }
- this._parent.modules.ingredients.isPopulated = false;
- }
- get id(){
- return this._id;
- }
- get name(){
- return this._name;
- }
- get date(){
- return this._date;
- }
- get taxes(){
- return this._taxes;
- }
- get fees(){
- return this._fees;
- }
- get parent(){
- return this._parent;
- }
- get ingredients(){
- return this._ingredients;
- }
- isSanitaryString(str){
- let disallowed = ["\\", "<", ">", "$", "{", "}", "(", ")"];
- for(let i = 0; i < disallowed.length; i++){
- if(str.includes(disallowed[i])){
- return false;
- }
- }
- return true;
- }
- }
- module.exports = Order;
|