Currently, our giftlist functionality doesn't really work. We want users to be able to create giftlists which they can then share.
Since we're using Mongoose to model data for our users, let's also put it to use to model our giftlists
. Inside your models
folder, create a new file called giftlist.js
:
var mongoose = require('mongoose'); var giftlistSchema = mongoose.Schema({ id: String, user_id: String, name: String, gifts: [{name: String}] sharedWith [{user_id: String}] }); module.exports = mongoose.model('Giftlist',giftlistSchema);
This model is pretty straightforward. A giftlist has an ID, a name, a list of gift
objects, and a user_id
field. We will populate the user_id
with the ID of the user who owns the giftlist. In a relational database, this would be a foreign key, defining a one-to-many relationship between users and giftlists.
The gifts field is an...