Skip to content

Commit

Permalink
switch to embeded data model
Browse files Browse the repository at this point in the history
  • Loading branch information
drillprop committed Feb 27, 2019
1 parent 6264fa5 commit 2e2561f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
9 changes: 5 additions & 4 deletions src/graphql/resolvers/Mutation.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import fetch from 'node-fetch';
import bcrypt from 'bcryptjs';
import 'dotenv/config';
import jwt from 'jsonwebtoken';
import Album from '../../models/Album';
import User from '../../models/User';
import jwt from 'jsonwebtoken';
import 'dotenv/config';

const Mutation = {
createCd: async (parent, args, ctx, info) => {
Expand All @@ -18,8 +17,10 @@ const Mutation = {
artist,
image
});
await album.save();
await user.albums.push(album);
user.save();
await user.save();

return album;
},
signup: async (parent, args, ctx, info) => {
Expand Down
4 changes: 2 additions & 2 deletions src/models/Album.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Schema, model } from 'mongoose';
import { model, Schema } from 'mongoose';

const albumSchema = new Schema({
export const albumSchema = new Schema({
artist: String,
title: String,
image: String
Expand Down
5 changes: 3 additions & 2 deletions src/models/User.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { Schema, model } from 'mongoose';
import { model, Schema } from 'mongoose';
import { albumSchema } from './Album';

const userSchema = new Schema({
name: { type: String, unique: true, required: true },
email: { type: String, unique: true, required: true },
password: { type: String, required: true },
date: { type: Date, default: Date.now },
avatar: String,
albums: []
albums: [albumSchema]
});

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

0 comments on commit 2e2561f

Please sign in to comment.