transaction.js 865 B

1234567891011121314151617181920212223242526272829303132
  1. const mongoose = require("mongoose");
  2. const TransactionSchema = new mongoose.Schema({
  3. merchant: {
  4. type: mongoose.Schema.Types.ObjectId,
  5. ref: "Merchant",
  6. required: [true, "MERCHANT IS REQUIRED FOR A TRANSACTION"]
  7. },
  8. date: {
  9. type: Date,
  10. required: [true, "DATE MUST BE PROVIDED FOR A TRANSACTION"],
  11. validate: {
  12. validator: date => date < new Date,
  13. message: "TRANSACTION DATE CANNOT BE SET TO THE FUTURE"
  14. }
  15. },
  16. device: String,
  17. recipes: [{
  18. recipe: {
  19. type: mongoose.Schema.Types.ObjectId,
  20. ref: "Recipe"
  21. },
  22. quantity: {
  23. type: Number,
  24. min: [0, "RECIPE QUANTITIES MUST BE A POSITIVE NUMBER"]
  25. }
  26. }],
  27. posId: String
  28. });
  29. module.exports = mongoose.model("Transaction", TransactionSchema);