Skip to content

Commit

Permalink
assign albums to user only
Browse files Browse the repository at this point in the history
  • Loading branch information
drillprop committed Feb 26, 2019
1 parent 94d3ffc commit 6264fa5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/graphql/resolvers/Mutation.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ const Mutation = {
throw new Error('Sign in to add a cd');
}
let { title, artist, image } = args;
const album = new Album({ title, artist, image });
await album.save();
console.log(user._id);
const album = new Album({
title,
artist,
image
});
await user.albums.push(album);
user.save();
return album;
},
signup: async (parent, args, ctx, info) => {
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const userSchema = new Schema({
password: { type: String, required: true },
date: { type: Date, default: Date.now },
avatar: String,
albums: [{ type: Schema.Types.ObjectId, ref: 'Album' }]
albums: []
});

const User = model('Users', userSchema);
Expand Down

0 comments on commit 6264fa5

Please sign in to comment.