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.ts 1.4KB

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