You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

product.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. const mongoose = require('mongoose');
  2. const ProductSchema = new mongoose.Schema({
  3. category: {
  4. type: String,
  5. required: [true, 'Please provide a category.'],
  6. maxlength: 100,
  7. trim: true,
  8. },
  9. name: {
  10. type: String,
  11. required: [true, 'Please provide a name.'],
  12. maxlength: 100,
  13. trim: true,
  14. },
  15. image: {
  16. type: String,
  17. required: [true, 'Please provide an image.'],
  18. },
  19. description: {
  20. type: String,
  21. required: [true, 'Please provide a description.'],
  22. trim: true,
  23. },
  24. place: {
  25. type: String,
  26. trim: true,
  27. },
  28. people: {
  29. type: String,
  30. trim: true,
  31. },
  32. process: {
  33. type: String,
  34. trim: true,
  35. },
  36. pairing: {
  37. type: String,
  38. trim: true,
  39. },
  40. available: {
  41. type: Boolean,
  42. default: true,
  43. },
  44. isFeatured: {
  45. type: Boolean,
  46. default: false,
  47. },
  48. price: {
  49. type: Number,
  50. required: [true, 'Please provide a price.'],
  51. validate(value) {
  52. if (value < 0) {
  53. throw new Error('Price must be a postive number');
  54. }
  55. },
  56. },
  57. customID: {
  58. type: String,
  59. required: [true, 'Please provide a custom id.'],
  60. unique: [true, 'Custom id must be unique'],
  61. },
  62. stripeID: {
  63. type: String,
  64. required: [true, 'Please provide a stripe id.'],
  65. unique: [true, 'Stripe id must be unique'],
  66. },
  67. });
  68. const Product =
  69. mongoose.models.Product || mongoose.model('Product', ProductSchema);
  70. module.exports = Product;