Skip to content

Commit 6a5ba4e

Browse files
committed
Added user details page
1 parent 37714b8 commit 6a5ba4e

4 files changed

Lines changed: 25 additions & 2 deletions

File tree

routes/index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
var ObjectID = require('mongodb').ObjectID;
2+
13
module.exports = function (app, db) {
24
app.get('/', function (req, res) {
35
db.collection('nodelabs-users', function (err, collection) {
@@ -6,4 +8,13 @@ module.exports = function (app, db) {
68
});
79
});
810
});
11+
12+
app.get('/user/:id', function (req, res) {
13+
var id = req.params.id;
14+
db.collection('nodelabs-users', function (err, collection) {
15+
collection.findOne({ _id: ObjectID(id) }, function (err, user) {
16+
res.render('user.jade', { user: user });
17+
});
18+
});
19+
});
920
};

views/index.jade

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ block content
1010
tr
1111
td= user.firstName + " " + user.lastName
1212
td= user.emailAddress
13-
td edit - remove
13+
td
14+
a(href="/user/" + user._id) edit
15+
| - remove
1416

views/layout.jade

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ html(lang="en")
55
link(href="/css/app.css" rel="stylesheet")
66
body
77
h1 Users
8-
block content
8+
block content

views/user.jade

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extends layout
2+
3+
block content
4+
ul.details
5+
li= user.firstName + " " + user.lastName
6+
li= user.emailAddress
7+
8+
div.photo
9+
a(href="http://thecatapi.com")
10+
img(src="http://thecatapi.com/api/images/get?format=src&type=gif&size=small&cb=" + new Date().getTime())

0 commit comments

Comments
 (0)