I am trying to make a single Post request to this endpoint:
.route('/users/:userId/recipes')
The request should create the recipe and an array of flavors. So a recipe should contain 1 to many flavors. The api is going to be used by a website and an Android application. Is it possible to achieve this with a single request? if so, how can I achieve this?
I want the result to look something like this.
{
_id: "j3232343424",
name: "Strawbery bla bla",
amount: 30,
pg: 70,
vg: 30,
flavors: [
{
name: "Strawberry",
percentage: 90
},
{
name: "Cream",
percentage: 10
}
]
}
I have two schemas, one for the recipe, and the other for the flavorings. The recipe Schema has an array of flavors.
var flavorSchema = mongoose.Schema({
name: {
type: String,
required: true
},
percentage: {
type: Number,
required: true
}
});
var recipeSchema = mongoose.Schema({
name: {
type: String,
required: true
},
amount: {
type: Number,
required: true
},
pg: {
type: Number,
min: 0,
max: 100,
required: true
},
vg: {
type: Number,
min: 0,
max: 100,
required: true
},
flavors: [flavorSchema],