Skip to content

Commit b9f0a91

Browse files
committed
Add ideas, meetings, minions router js files
1 parent 6593267 commit b9f0a91

File tree

6 files changed

+96
-2
lines changed

6 files changed

+96
-2
lines changed

ClientApp/server.js

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const express = require('express');
22
const app = express();
3+
const morgan = require('morgan');
34
var bodyParser = require('body-parser');
45
var cors = require('cors')
56

@@ -12,13 +13,19 @@ const PORT = process.env.PORT || 4001;
1213

1314
// Add middleware for handling CORS requests from index.html
1415
app.use(cors());
15-
16+
1617
// Add middware for parsing request bodies here:
17-
app.use(bodyParser());
18+
app.use(bodyParser.json());
19+
20+
if (!process.env.IS_TEST_ENV) {
21+
app.use(morgan('short'));
22+
}
1823

1924
// Mount your existing apiRouter below at the '/api' path.
2025
const apiRouter = require('./server/api');
2126

27+
app.use('/api', apiRouter)
28+
2229

2330
// This conditional is here for testing purposes:
2431
if (!module.parent) {

ClientApp/server/api.js

+23
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,29 @@
11
const express = require('express');
22
const apiRouter = express.Router();
3+
const db = require('./db.js');
4+
const minionRouter = require('./apiMinion')
5+
const ideasRouter = require('./apiIdeas')
6+
const meetingsRouter = require('./apiMeetings')
37

8+
// MINIONS ROUTER
9+
apiRouter.use('/minions', minionRouter)
10+
// IDEAS ROUTER
11+
apiRouter.use('/ideas', ideasRouter)
12+
//MEETINGS ROUTER
13+
apiRouter.use('/meetings', meetingsRouter)
414

15+
// GET /api/minions to get an array of all minions.
16+
17+
18+
// Middleware (USE) /api/minions/:minionId 1.validate existence of the minion, 2. if exists, find the index of the minion in the database, 3. then to attach the index location to the request object
19+
//apiRouter.param('minionId', )
20+
21+
//apiRouter.param('minionId', (req, res, next, minionId) => {
22+
23+
//});
24+
25+
// GET /api/minions/:minionId to get a single minion by id.
26+
// PUT /api/minions/:minionId to update a single minion by id.
27+
// DELETE /api/minions/:minionId to delete a single minion by id.
528

629
module.exports = apiRouter;

ClientApp/server/apiIdeas.js

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
const express = require('express')
2+
const ideasRouter = express.Router();
3+
const db = require('./db.js');
4+
5+
ideasRouter.get('/', (req, res, next) => {
6+
res.send(db.getAllFromDatabase('ideas'));
7+
});
8+
9+
10+
module.exports = ideasRouter

ClientApp/server/apiMeetings.js

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
const express = require('express')
2+
const meetingsRouter = express.Router();
3+
const db = require('./db.js');
4+
5+
meetingsRouter.get('/', (req, res, next) => {
6+
res.send(db.getAllFromDatabase('meetings'));
7+
});
8+
9+
module.exports = meetingsRouter

ClientApp/server/apiMinion.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
const express = require('express')
2+
const minionRouter = express.Router();
3+
const db = require('./db.js');
4+
5+
minionRouter.get('/', (req, res, next) => {
6+
res.send(db.getAllFromDatabase('minions'));
7+
});
8+
9+
// POST /api/minions to create a new minion and save it to the database.
10+
minionRouter.post('/', (req, res, next) => {
11+
const newMinion = {
12+
name: req.body.name.toString(),
13+
title: req.body.title.toString(),
14+
weaknesses: req.body.weaknesses.toString(),
15+
salary: Number(req.body.salary),
16+
};
17+
res.send(db.addToDatabase('minions', newMinion));
18+
})
19+
20+
module.exports = minionRouter

boss-machine.sln

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.30011.22
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "boss-machine", "boss-machine.csproj", "{EBEA19C7-F003-4907-9BED-764497196C8D}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{EBEA19C7-F003-4907-9BED-764497196C8D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{EBEA19C7-F003-4907-9BED-764497196C8D}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{EBEA19C7-F003-4907-9BED-764497196C8D}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{EBEA19C7-F003-4907-9BED-764497196C8D}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {0CF7835E-92C6-42B0-85C5-142D3F02C529}
24+
EndGlobalSection
25+
EndGlobal

0 commit comments

Comments
 (0)