-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
80 additions
and
59 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
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 |
---|---|---|
@@ -1,34 +1,46 @@ | ||
const db = require('../../config/mongoose') | ||
const Category = require('../category') | ||
const User = require('../user') | ||
|
||
db.once('open', async () => { | ||
db.once('open', () => { | ||
console.log('categorySeeder is connect!') | ||
const data = [ | ||
{ | ||
name: '家居物業', | ||
icon: 'fas fa-home' | ||
}, | ||
{ | ||
name: '交通出行', | ||
icon: 'fas fa-shuttle-van' | ||
}, | ||
{ | ||
name: '休閒娛樂', | ||
icon: 'fas fa-grin-beam' | ||
}, | ||
{ | ||
name: '餐飲食品', | ||
icon: 'fas fa-utensils' | ||
}, | ||
{ | ||
name: '其他', | ||
icon: 'fas fa-pen' | ||
}, | ||
{ | ||
name: '薪水', | ||
type: '收入' | ||
} | ||
] | ||
await Category.create(data) | ||
db.close() | ||
return User.find() | ||
.then(async user => { | ||
const userId = user[0]._id | ||
await Category.create( | ||
{ | ||
name: '家居物業', | ||
icon: 'fas fa-home', | ||
userId | ||
}, | ||
{ | ||
name: '交通出行', | ||
icon: 'fas fa-shuttle-van', | ||
userId | ||
}, | ||
{ | ||
name: '休閒娛樂', | ||
icon: 'fas fa-grin-beam', | ||
userId | ||
}, | ||
{ | ||
name: '餐飲食品', | ||
icon: 'fas fa-utensils', | ||
userId | ||
}, | ||
{ | ||
name: '其他', | ||
icon: 'fas fa-pen', | ||
userId | ||
}, | ||
{ | ||
name: '薪水', | ||
type: '收入', | ||
userId | ||
}) | ||
}) | ||
.then(() => { | ||
console.log('done') | ||
process.exit() | ||
}) | ||
}) |
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 |
---|---|---|
@@ -1,35 +1,43 @@ | ||
const db = require('../../config/mongoose') | ||
const Record = require('../record') | ||
const User = require('../user') | ||
const bcrypt = require('bcryptjs') | ||
|
||
|
||
db.once('open', async () => { | ||
console.log('recordSeeder is connect!') | ||
const data = [ | ||
{ | ||
name: '神戶牛排', | ||
category: '餐飲食品', | ||
date: Date.now(), | ||
amount: -2000 | ||
}, | ||
{ | ||
name: 'H1Z1', | ||
category: '休閒娛樂', | ||
date: Date.now(), | ||
amount: -799 | ||
}, | ||
{ | ||
name: '收入', | ||
category: '薪水', | ||
date: Date.now(), | ||
amount: 10000 | ||
}, | ||
{ | ||
name: '火鍋', | ||
category: '餐飲食品', | ||
date: Date.now(), | ||
amount: -500 | ||
} | ||
] | ||
await Record.create(data) | ||
db.close() | ||
const SEED_USER = { | ||
name: 'Alpha Camp', | ||
email: '[email protected]', | ||
password: '123' | ||
} | ||
bcrypt | ||
.genSalt(10) | ||
.then(salt => bcrypt.hash(SEED_USER.password, salt)) | ||
.then(hash => { | ||
User.create({ | ||
name: SEED_USER.name, | ||
email: SEED_USER.email, | ||
password: hash | ||
}) | ||
.then(async user => { | ||
await Record.create({ | ||
name: '神戶牛排', | ||
category: '餐飲食品', | ||
date: Date.now(), | ||
amount: -2000, | ||
userId: user._id | ||
}, { | ||
name: 'H1Z1', | ||
category: '休閒娛樂', | ||
date: Date.now(), | ||
amount: -799, | ||
userId: user._id | ||
}) | ||
}) | ||
.then(() => { | ||
console.log('recordSeeder done!') | ||
process.exit() | ||
}) | ||
}) | ||
}) |
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