ingredient.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const isSanitary = require("../validator.js").isSanitary;
  2. const mongoose = require("mongoose");
  3. const IngredientSchema = new mongoose.Schema({
  4. name: {
  5. type: String,
  6. minlength: [2, "INGREDIENT NAME MUST CONTAIN AT LEAST 2 CHARACTERS"],
  7. required: [true, "INGREDIENT NAME IS REQUIRED"],
  8. validate: {
  9. validator: isSanitary,
  10. message: "INGREDIENT NAME CONTAINS ILLEGAL CHARACTERS"
  11. }
  12. },
  13. category: {
  14. type: String,
  15. minlength: [2, "INGREDIENT CATEGORY MUST CONTAIN AT LEAST 2 CHARACTERS"],
  16. required: [true, "INGREDIENT CATEGORY IS REQUIRED"],
  17. validate: {
  18. validator: isSanitary,
  19. message: "INGREDIENT CATEGORY CONTAINS ILLEGAL CHARACTERS"
  20. }
  21. },
  22. unitType: {
  23. type: String,
  24. required: [true, "UNIT TYPE IS REQUIRED"]
  25. },
  26. unitSize: {
  27. type: Number,
  28. min: [0, "SIZE CANNOT BE A NEGATIVE NUMBER"],
  29. required: false
  30. },
  31. ingredients: [{
  32. ingredient: {
  33. type: mongoose.Schema.Types.ObjectId,
  34. ref: "Ingredient",
  35. required: true
  36. },
  37. quantity: {
  38. type: Number,
  39. required: true,
  40. min: 0
  41. }
  42. }],
  43. });
  44. module.exports = mongoose.model("Ingredient", IngredientSchema);