Vibed it... :(
This commit is contained in:
55
backend/models/UserSelection.js
Normal file
55
backend/models/UserSelection.js
Normal file
@@ -0,0 +1,55 @@
|
||||
const mongoose = require('mongoose');
|
||||
|
||||
const userSelectionSchema = new mongoose.Schema({
|
||||
userId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'User',
|
||||
required: true
|
||||
},
|
||||
selectedRecipes: [{
|
||||
recipeId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Recipe',
|
||||
required: true
|
||||
},
|
||||
quantity: {
|
||||
type: Number,
|
||||
default: 1,
|
||||
min: 1
|
||||
},
|
||||
addedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
}],
|
||||
aggregatedIngredients: [{
|
||||
name: String,
|
||||
totalAmount: Number,
|
||||
unit: String,
|
||||
recipes: [{
|
||||
recipeId: {
|
||||
type: mongoose.Schema.Types.ObjectId,
|
||||
ref: 'Recipe'
|
||||
},
|
||||
recipeTitle: String,
|
||||
amount: Number,
|
||||
quantity: Number // recipe quantity multiplier
|
||||
}]
|
||||
}],
|
||||
createdAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
},
|
||||
updatedAt: {
|
||||
type: Date,
|
||||
default: Date.now
|
||||
}
|
||||
});
|
||||
|
||||
// Update the updatedAt field before saving
|
||||
userSelectionSchema.pre('save', function(next) {
|
||||
this.updatedAt = Date.now();
|
||||
next();
|
||||
});
|
||||
|
||||
module.exports = mongoose.model('UserSelection', userSelectionSchema);
|
||||
Reference in New Issue
Block a user