Menu.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import mongoose, {
  2. Document,
  3. Schema
  4. } from "mongoose";
  5. export interface IMenu extends Document {
  6. userID: mongoose.Types.ObjectId;
  7. title: string;
  8. description?: string;
  9. isActive?: boolean;
  10. products: Array<{
  11. categoryIDs: mongoose.Types.ObjectId[];
  12. productID: mongoose.Types.ObjectId;
  13. isViewPrice: boolean;
  14. }>;
  15. isViewPrice: boolean;
  16. createdAt: Date;
  17. updatedAt: Date;
  18. }
  19. const menuSchema = new Schema<IMenu>(
  20. {
  21. userID: {
  22. type: Schema.Types.ObjectId,
  23. ref: "User", // TODO aggregate fonk kullanılacak ref değil
  24. },
  25. title: {
  26. type: String,
  27. },
  28. description: {
  29. type: String,
  30. },
  31. isActive: {
  32. type: Boolean,
  33. default: true
  34. },
  35. products: [
  36. {
  37. categoryIDs: {
  38. type: [Schema.Types.ObjectId],
  39. default: []
  40. },
  41. productID: {
  42. type: Schema.Types.ObjectId,
  43. ref: "Product", // TODO ilerde product servis buna göre düzenlenecek aggregate fonskiyonu kullanılacak ref değil
  44. },
  45. isViewPrice: {
  46. type: Boolean,
  47. }
  48. }
  49. ],
  50. isViewPrice: {
  51. type: Boolean,
  52. }
  53. },
  54. {
  55. timestamps: true
  56. }
  57. );
  58. export const Menu = mongoose.model<IMenu>("Menu", menuSchema);