1
0
mwe-comments/server/db/seed.js
data 23144bc180 fix toggling and thread view
- pass all comments to ThreadList
- filter comments based on threadLevel === parentId
- pass comment id to toggleCollapse()
2019-07-13 21:09:23 +02:00

42 lines
957 B
JavaScript
Executable File

const db = require('../db')
const { Comment } = require('./models')
const tc1 = { text: 'c1' }
const tc2 = { text: 'c2' }
const tc3 = { text: 'c3' }
const tc4 = { text: 'c4' }
const tc5 = { text: 'c5' }
const tc6 = { text: 'c6' }
async function runSeed() {
await db.sync({ force: true })
console.log('db synced!')
console.log('seeding...')
try {
const c1 = await Comment.create(tc1)
const c2 = await Comment.create(tc2)
const c3 = await Comment.create(tc3)
const c4 = await Comment.create(tc4)
const c5 = await Comment.create(tc5)
const c6 = await Comment.create(tc6)
await c1.addReply(2)
await c2.addReplies([c3, c4])
await c5.setParent(c4)
await c6.setParent(c1)
console.log('seeded successfully')
} catch (err) {
console.error(err)
process.exitCode = 1
} finally {
console.log('closing db connection')
await db.close()
console.log('db connection closed')
}
}
runSeed()