Skip to content

Commit 8105bcf

Browse files
committed
Adding seeding of DB
1 parent 53aa6e3 commit 8105bcf

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

chapter-18/starships/controllers/ships.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const ShipsModel = require('../models/ships')
2+
const insertRandomNames = require('../models/setup')
23

34
const TORPEDO_DAMAGE = 75
45

@@ -10,6 +11,10 @@ const calculateDamage = (ship1, ship2, weapon) => {
1011
return damage
1112
}
1213

14+
exports.seedDatabase = async () => {
15+
return await insertRandomNames()
16+
}
17+
1318
exports.createShip = async (data) => {
1419
return await ShipsModel.createShip(data)
1520
}

chapter-18/starships/routes/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ var express = require('express');
22
var router = express.Router();
33
const ShipsController = require('../controllers/ships');
44

5+
ShipsController.seedDatabase();
6+
57
/* GET home page. */
68
router.get('/', async (req, res, next) => {
79
res.render('index', { ships: await ShipsController.getFleet() });

0 commit comments

Comments
 (0)