ingredient.js 1016 B

123456789101112131415161718192021222324252627282930313233343536
  1. const helper = require("../controllers/helper.js");
  2. const mongoose = require("mongoose");
  3. let sanitary = (value)=>{
  4. return helper.isSanitary(value);
  5. }
  6. const IngredientSchema = new mongoose.Schema({
  7. name: {
  8. type: String,
  9. minlength: [2, "INGREDIENT NAME MUST CONTAIN AT LEAST 2 CHARACTERS"],
  10. required: [true, "INGREDIENT NAME IS REQUIRED"],
  11. validate: {
  12. validator: sanitary,
  13. message: "INGREDIENT NAME CONTAINS ILLEGAL CHARACTERS"
  14. }
  15. },
  16. category: {
  17. type: String,
  18. minlength: [2, "INGREDIENT CATEGORY MUST CONTAIN AT LEAST 2 CHARACTERS"],
  19. required: [true, "INGREDIENT CATEGORY IS REQUIRED"],
  20. validate: {
  21. validator: sanitary,
  22. message: "INGREDIENT CATEGORY CONTAINS ILLEGAL CHARACTERS"
  23. }
  24. },
  25. unitType: {
  26. type: String,
  27. required: true
  28. },
  29. specialUnit: String,
  30. unitSize: String
  31. });
  32. module.exports = mongoose.model("Ingredient", IngredientSchema);