I hope this is the right place to ask about modeling the data. I put together a simple data and am trying to figure out what I need to do for model.
In my MERN app which is a reward program, I just want to display the list of customers, and once you click on the customer, it takes you to the customer’s recorded purchases per month. I will be using React to calculate how many reward points the customer earn for each purchase in a month, and the total reward points per month, and the total of 3 months’ reward points.
So basically, the database would be just the customers and its purchases and I will be using React to calculate the reward points.
So to put together the model for this, do I need one model like Customer.js or two models: Customer.js and Purchases.js?
Here’s what I put together so far for Customer.js:
const mongoose = require('mongoose');
const CustomerSchema = new mongoose.Schema({
name: {
type: String
},
account: {
type: String
},
purchase: {
type: Number
},
purchase_date: {
type: Date
}
});
module.exports = Customer = mongoose.model('customer', CustomerSchema);
Here’s a sample of my data:
[
{
"account": "ABC123",
"name": "John Doe",
"purchase-history": [
{
"month1": "January",
"transitions": [
{
"date": "01/01/20",
"purchase": 120
},
{
"date": "01/03/20",
"purchase": 195
},
{
"date": "01/15/20",
"purchase": 49
},
{
"date": "01/23/20",
"purchase": 63
}
]
},
{
"month2": "February",
"transitions": [
{
"date": "02/01/20",
"purchase": 120
},
{
"date": "02/03/20",
"purchase": 85
},
{
"date": "02/15/20",
"purchase": 300
},
{
"date": "02/23/20",
"purchase": 51
}
]
},
{
"month3": "March",
"transitions": [
{
"date": "03/01/20",
"purchase": 120
},
{
"date": "03/03/20",
"purchase": 225
},
{
"date": "03/15/20",
"purchase": 9
},
{
"date": "03/23/20",
"purchase": 72
}
]
},
{
"month4": "April",
"transitions": [
{
"date": "04/03/20",
"purchase": 195
},
{
"date": "04/23/20",
"purchase": 63
}
]
},
{
"month5": "May",
"transitions": [
{
"date": "05/01/20",
"purchase": 161
},
{
"date": "05/03/20",
"purchase": 155
},
{
"date": "05/15/20",
"purchase": 52
},
{
"date": "05/23/20",
"purchase": 84
}
]
}
]
},
{
"account": "ACD134",
"name": "Nancy Drew",
"purchase-history": [
{
"month1": "January",
"transitions": [
{
"date": "01/01/20",
"purchase": 130
},
{
"date": "01/03/20",
"purchase": 185
},
{
"date": "01/15/20",
"purchase": 59
},
{
"date": "01/23/20",
"purchase": 33
}
]
},
{
"month2": "February",
"transitions": [
{
"date": "02/01/20",
"purchase": 110
},
{
"date": "02/03/20",
"purchase": 25
},
{
"date": "02/15/20",
"purchase": 340
},
{
"date": "02/23/20",
"purchase": 71
}
]
},
{
"month3": "March",
"transitions": [
{
"date": "03/01/20",
"purchase": 150
},
{
"date": "03/03/20",
"purchase": 215
},
{
"date": "03/15/20",
"purchase": 49
},
{
"date": "03/23/20",
"purchase": 82
}
]
},
{
"month4": "April",
"transitions": [
{
"date": "04/03/20",
"purchase": 125
},
{
"date": "04/23/20",
"purchase": 83
}
]
},
{
"month5": "May",
"transitions": [
{
"date": "05/01/20",
"purchase": 181
},
{
"date": "05/03/20",
"purchase": 115
},
{
"date": "05/15/20",
"purchase": 62
},
{
"date": "05/23/20",
"purchase": 14
}
]
}
]
}