Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added route to get customer details in json

  • Loading branch information...
commit 654f276b4e8fbf1aa2faf78c5d649a2f84413823 1 parent e67db71
Davy Brion authored
3  TODO
@@ -4,6 +4,8 @@ In Progress
4 4 - UI testing still needs to be done
5 5 - route testing ?
6 6 - View Customers
  7 + - UI testing still needs to be done
  8 + - route testing ?
7 9
8 10 Backlog
9 11 -------------------
@@ -29,6 +31,7 @@ Technical stuff
29 31 - authentication
30 32 - authorization
31 33 - use minimized versions of script files when in production environment
  34 +- clean up error handling: try to remove these calls: if (err) { return next(err); };
32 35
33 36
34 37 General
10 lib/routes/customer.js
@@ -9,16 +9,22 @@ module.exports = function(app){
9 9 app.get('/customer/list', function(req, res, next) {
10 10 var customers = Customer.find({}, [ 'name' ], function(err, docs) {
11 11 if (err) { return next(err); }
12   -
  12 + console.log(docs);
13 13 res.render('customer/list', { customers: docs });
14 14 });
15 15 });
16 16
  17 + app.get('/customer/:id', function(req, res, next) {
  18 + var customer = Customer.findById(req.params.id, function(err, customer) {
  19 + if (err) { return next(err); };
  20 + res.send(customer);
  21 + });
  22 + });
  23 +
17 24 app.post('/customer', function(req, res, next) {
18 25 var newCustomer = new Customer(req.body.customer);
19 26 newCustomer.save(function(err, result) {
20 27 if (err) { return next(err); }
21   -
22 28 req.flash('info', 'customer with id ' + result.id + ' created');
23 29 res.redirect('/');
24 30 });
2  lib/views/customer/list.html
@@ -2,6 +2,6 @@
2 2
3 3 <div id="customerList">
4 4 <% customers.forEach(function(customer) { %>
5   - <p><%= customer.name %> </p>
  5 + <p><%= customer.name %> <a href="<%= '/customer/' + customer.id %>">Details</a></p>
6 6 <% }); %>
7 7 </div>

0 comments on commit 654f276

Please sign in to comment.
Something went wrong with that request. Please try again.