-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Step 3.10: Mock initial data in chats and messages collections
- Loading branch information
Showing
1 changed file
with
66 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import Moment from 'moment'; | ||
import { Meteor } from 'meteor/meteor'; | ||
import { Chats, Messages } from './collections'; | ||
|
||
Meteor.startup(function() { | ||
if (Chats.find().count() !== 0) return; | ||
|
||
Messages.remove({}); | ||
|
||
const messages = [ | ||
{ | ||
text: 'You on your way?', | ||
timestamp: Moment().subtract(1, 'hours').toDate() | ||
}, | ||
{ | ||
text: 'Hey, it\'s me', | ||
timestamp: Moment().subtract(2, 'hours').toDate() | ||
}, | ||
{ | ||
text: 'I should buy a boat', | ||
timestamp: Moment().subtract(1, 'days').toDate() | ||
}, | ||
{ | ||
text: 'Look at my mukluks!', | ||
timestamp: Moment().subtract(4, 'days').toDate() | ||
}, | ||
{ | ||
text: 'This is wicked good ice cream.', | ||
timestamp: Moment().subtract(2, 'weeks').toDate() | ||
} | ||
]; | ||
|
||
messages.forEach((m) => { | ||
Messages.insert(m); | ||
}); | ||
|
||
const chats = [ | ||
{ | ||
name: 'Ethan Gonzalez', | ||
picture: 'https://randomuser.me/api/portraits/thumb/men/1.jpg' | ||
}, | ||
{ | ||
name: 'Bryan Wallace', | ||
picture: 'https://randomuser.me/api/portraits/thumb/lego/1.jpg' | ||
}, | ||
{ | ||
name: 'Avery Stewart', | ||
picture: 'https://randomuser.me/api/portraits/thumb/women/1.jpg' | ||
}, | ||
{ | ||
name: 'Katie Peterson', | ||
picture: 'https://randomuser.me/api/portraits/thumb/women/2.jpg' | ||
}, | ||
{ | ||
name: 'Ray Edwards', | ||
picture: 'https://randomuser.me/api/portraits/thumb/men/2.jpg' | ||
} | ||
]; | ||
|
||
chats.forEach((chat) => { | ||
const message = Messages.findOne({ chatId: { $exists: false } }); | ||
chat.lastMessage = message; | ||
const chatId = Chats.insert(chat); | ||
Messages.update(message._id, { $set: { chatId } }); | ||
}); | ||
}); |