2017-03-27 10:52:56 +09:00
|
|
|
/*
|
|
|
|
|
|
|
|
Seed the database with some dummy content.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
import Movies from '../modules/movies/collection.js';
|
|
|
|
import Users from 'meteor/vulcan:users';
|
|
|
|
import { newMutation } from 'meteor/vulcan:core';
|
|
|
|
|
|
|
|
const seedData = [
|
|
|
|
{
|
|
|
|
name: 'Star Wars',
|
|
|
|
year: '1973',
|
|
|
|
review: `A classic.`,
|
|
|
|
privateComments: `Actually, I don't really like Star Wars…`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Die Hard',
|
|
|
|
year: '1987',
|
|
|
|
review: `A must-see if you like action movies.`,
|
|
|
|
privateComments: `I love Bruce Willis so much!`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Terminator',
|
|
|
|
year: '1983',
|
|
|
|
review: `Once again, Schwarzenegger shows why he's the boss.`,
|
|
|
|
privateComments: `Terminator is my favorite movie ever. `
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Jaws',
|
|
|
|
year: '1971',
|
|
|
|
review: 'The original blockbuster.',
|
|
|
|
privateComments: `I'm scared of sharks…`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Die Hard II',
|
|
|
|
year: '1991',
|
|
|
|
review: `Another classic.`
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Rush Hour',
|
|
|
|
year: '1993',
|
|
|
|
review: `Jackie Chan at his best.`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Citizen Kane',
|
|
|
|
year: '1943',
|
|
|
|
review: `A disappointing lack of action sequences.`,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: 'Commando',
|
|
|
|
year: '1983',
|
|
|
|
review: 'A good contender for highest kill count ever.',
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2017-04-29 12:33:05 +09:00
|
|
|
const createUser = function (username, email) {
|
|
|
|
const user = {
|
|
|
|
username,
|
|
|
|
email,
|
|
|
|
isDummy: true
|
|
|
|
};
|
|
|
|
newMutation({
|
|
|
|
collection: Users,
|
|
|
|
document: user,
|
|
|
|
validate: false
|
2017-04-09 15:43:26 +09:00
|
|
|
});
|
2017-04-29 12:33:05 +09:00
|
|
|
}
|
|
|
|
|
|
|
|
var createDummyUsers = function () {
|
|
|
|
console.log('// inserting dummy users…');
|
|
|
|
createUser('Bruce', 'dummyuser1@telescopeapp.org');
|
|
|
|
createUser('Arnold', 'dummyuser2@telescopeapp.org');
|
|
|
|
createUser('Julia', 'dummyuser3@telescopeapp.org');
|
2017-04-09 15:43:26 +09:00
|
|
|
};
|
|
|
|
|
2017-03-27 10:52:56 +09:00
|
|
|
Meteor.startup(function () {
|
|
|
|
if (Users.find().fetch().length === 0) {
|
2017-04-09 15:43:26 +09:00
|
|
|
createDummyUsers();
|
2017-03-27 10:52:56 +09:00
|
|
|
}
|
2017-04-09 15:43:26 +09:00
|
|
|
const currentUser = Users.findOne(); // just get the first user available
|
2017-03-27 10:52:56 +09:00
|
|
|
if (Movies.find().fetch().length === 0) {
|
2017-04-09 15:43:26 +09:00
|
|
|
console.log('// creating dummy movies');
|
2017-03-27 10:52:56 +09:00
|
|
|
seedData.forEach(document => {
|
|
|
|
newMutation({
|
|
|
|
action: 'movies.new',
|
|
|
|
collection: Movies,
|
|
|
|
document: document,
|
|
|
|
currentUser: currentUser,
|
|
|
|
validate: false
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|