Skip to content

Commit dceee80

Browse files
dotansimhadarkbasic
authored andcommitted
Step 4.16: Move stubs data to the server side
1 parent 70c1007 commit dceee80

1 file changed

Lines changed: 67 additions & 1 deletion

File tree

‎api/server/main.ts‎

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,71 @@
11
import { Meteor } from 'meteor/meteor';
2+
import { Chats } from './collections/chats';
3+
import { Messages } from './collections/messages';
4+
import * as moment from 'moment';
5+
import { MessageType } from './models';
26

37
Meteor.startup(() => {
4-
// code to run on server at startup
8+
if (Chats.find({}).cursor.count() === 0) {
9+
let chatId;
10+
11+
chatId = Chats.collection.insert({
12+
title: 'Ethan Gonzalez',
13+
picture: 'https://randomuser.me/api/portraits/thumb/men/1.jpg'
14+
});
15+
16+
Messages.collection.insert({
17+
chatId: chatId,
18+
content: 'You on your way?',
19+
createdAt: moment().subtract(1, 'hours').toDate(),
20+
type: MessageType.TEXT
21+
});
22+
23+
chatId = Chats.collection.insert({
24+
title: 'Bryan Wallace',
25+
picture: 'https://randomuser.me/api/portraits/thumb/lego/1.jpg'
26+
});
27+
28+
Messages.collection.insert({
29+
chatId: chatId,
30+
content: 'Hey, it\'s me',
31+
createdAt: moment().subtract(2, 'hours').toDate(),
32+
type: MessageType.TEXT
33+
});
34+
35+
chatId = Chats.collection.insert({
36+
title: 'Avery Stewart',
37+
picture: 'https://randomuser.me/api/portraits/thumb/women/1.jpg'
38+
});
39+
40+
Messages.collection.insert({
41+
chatId: chatId,
42+
content: 'I should buy a boat',
43+
createdAt: moment().subtract(1, 'days').toDate(),
44+
type: MessageType.TEXT
45+
});
46+
47+
chatId = Chats.collection.insert({
48+
title: 'Katie Peterson',
49+
picture: 'https://randomuser.me/api/portraits/thumb/women/2.jpg'
50+
});
51+
52+
Messages.collection.insert({
53+
chatId: chatId,
54+
content: 'Look at my mukluks!',
55+
createdAt: moment().subtract(4, 'days').toDate(),
56+
type: MessageType.TEXT
57+
});
58+
59+
chatId = Chats.collection.insert({
60+
title: 'Ray Edwards',
61+
picture: 'https://randomuser.me/api/portraits/thumb/men/2.jpg'
62+
});
63+
64+
Messages.collection.insert({
65+
chatId: chatId,
66+
content: 'This is wicked good ice cream.',
67+
createdAt: moment().subtract(2, 'weeks').toDate(),
68+
type: MessageType.TEXT
69+
});
70+
}
571
});

0 commit comments

Comments
 (0)