transaction.js 936 B

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