/
db-seed.js
69 lines (59 loc) · 1.8 KB
/
db-seed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
const config = require('./nuxt.config.js')
const firebase = require('firebase')
if (!firebase.apps.length) {
firebase.initializeApp(
{
apiKey: config.env.APIKEY,
authDomain: config.env.AUTHDOMAIN,
databaseURL: config.env.DATABASEURL,
projectId: config.env.PROJECTID,
storageBucket: config.env.STORAGEBUCKET,
messagingSenderId: config.env.MESSAGINGSENDERID
}
)
}
const firestore = firebase.firestore();
const dbSeed = async () => {
// 板登録
firestore.collection('boards').add({
name: 'ニュース速報'
})
firestore.collection('boards').add({
name: 'ニュース速報+'
})
const board = await firestore.collection('boards').add({
name: 'ニュー速VIP'
})
const boardId = board.id
const threads = firestore.collection('boards').doc(boardId).collection('threads')
// スレ作成
const thread = await threads.add({
title: 'おもしろスレ'
})
threads.add({
title: '質問ある?'
})
const threadId = thread.id
// スレ書き込み
const FieldValue = require('firebase').firestore.FieldValue;
threads.doc(threadId).collection('responses').add({
author: "NO NAME",
email: "noname@example.com",
body: "1",
createAt: FieldValue.serverTimestamp()
})
threads.doc(threadId).collection('responses').add({
author: "ななしさん",
email: "noname@example.com",
body: "2get",
createAt: FieldValue.serverTimestamp()
})
threads.doc(threadId).collection('responses').add({
author: "xssマン",
email: "noname@example.com",
body: "<script>alert('hoge')</script>",
createAt: FieldValue.serverTimestamp()
})
console.log('firestore のコンソールを確認してVIPのおもしろスレにレスが3つついてたらctrl+Cで終了してください')
}
dbSeed()