Skip to content

Commit

Permalink
Add schemas for series, movies and user
Browse files Browse the repository at this point in the history
  • Loading branch information
Araan Branco committed Mar 10, 2017
1 parent 93b6cce commit 6c63c60
Show file tree
Hide file tree
Showing 8 changed files with 214 additions and 4 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import Hapi from 'hapi';
import dotenv from 'dotenv';
import Debug from 'debug';
import Models from './models';
import Routes from './plugins/routes';

dotenv.config();
Expand All @@ -18,6 +19,7 @@ server.connection({
});

let initializer = [
Models,
Routes
];

Expand Down
28 changes: 28 additions & 0 deletions models/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

import * as db from '../helpers/db';
import Debug from 'debug';

const debug = Debug('sofanerd.models');

const register = (server, options, next) => {
const dbConenction = db.connect('sofanerd').connection;

debug('Models initialize');
require('./movie').model(dbConenction);
require('./serie').model(dbConenction);
require('./user').model(dbConenction);

debug('Models registered');

next();
};

register.attributes = {
name: 'models',
multi: false,
once: true
};

export default {
register
};
9 changes: 9 additions & 0 deletions models/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

import Debug from 'debug';
import schema from './schemas/movie';

const debug = Debug('sofanerd.models.movie');

export const model = (connection) => {
return connection.model('Movie', schema);
};
72 changes: 72 additions & 0 deletions models/schemas/movie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@

import mongoose from 'mongoose';

const Schema = mongoose.Schema;

const schema = new Schema({
id_imdb: {
type: Number
},
name: {
type: String,
required: true
},
slug: {
type: String
},
description: {
type: String
},
year: {
type: Number
},
genre: {
type: String
},
country: {
type: String
},
director: {
type: String
},
writer: {
type: String
},
trailer: {
type: String
},
published: {
type: Array
},
featured: {
type: Array
},
checkins: [{
user_id: {
type: Schema.Types.ObjectId,
ref: 'User'
},
created_at:{
type: Date,
default: Date.now
}
}],
reactions: [{
user_id: {
type: Schema.Types.ObjectId,
ref: 'User'
},
note: {
type: Number
},
created_at:{
type: Date,
default: Date.now
}
}],
favorites: [],
collections: [],
comments: []
});

export default schema;
66 changes: 65 additions & 1 deletion models/schemas/serie.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,70 @@ import mongoose from 'mongoose';

const Schema = mongoose.Schema;

const schema = new Schema();
const schema = new Schema({
id_imdb: {
type: Number
},
id_moviedb: {
type: String
},
name: {
type: String,
required: true
},
slug: {
type: String,
required: true
},
description: {
type: String
},
runtime: {
type: String
},
networks: {
type: String
},
genre: {
type: String
},
country: {
type: String
},
status_show: {
type: String
},
trailer: {
type: String
},
checkins: [{
user_id: {
type: Schema.Types.ObjectId,
ref: 'User'
},
created_at:{
type: Date,
default: Date.now
}
}],
reactions: [{
user_id: {
type: Schema.Types.ObjectId,
ref: 'User'
},
note: {
type: Number
},
created_at:{
type: Date,
default: Date.now
}
}],
favorites: [],
collections: [],
seasons: [],
comments: []
});


export default schema;
27 changes: 26 additions & 1 deletion models/schemas/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,31 @@ import mongoose from 'mongoose';

const Schema = mongoose.Schema;

const schema = new Schema();
const schema = new Schema({
username: { type: String },
name: { type: String },
email: { type: String },
password: { type: String },
roles: { type: Array, default: ['user', 'authenticated'] },
favorites: [],
collections: [],
reactions: [{
serie_id: {
type: Schema.Types.ObjectId,
ref: 'Serie',
},
movie_id: {
type: Schema.Types.ObjectId,
ref: 'Movie',
},
created_at:{
type: Date,
default: Date.now
},
note: {
type: Number
}
}]
});

export default schema;
7 changes: 6 additions & 1 deletion models/serie.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

import Debug from 'debug';
import schema from './schemas/serie';

const debug = Debug('sofanerd.models.serie');
const debug = Debug('sofanerd.models.serie');

export const model = (connection) => {
return connection.model('Serie', schema);
};
7 changes: 6 additions & 1 deletion models/user.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@

import Debug from 'debug';
import schema from './schemas/user';

const debug = Debug('sofanerd.models.user');
const debug = Debug('sofanerd.models.user');

export const model = (connection) => {
return connection.model('User', schema);
};

0 comments on commit 6c63c60

Please sign in to comment.