Sharing giftlists

Currently, our giftlist functionality doesn't really work. We want users to be able to create giftlists which they can then share.

Fleshing out the giftlist model

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 ...

Get Mastering JavaScript Single Page Application Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.