Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added route to get customer details in json

  • Loading branch information...
commit 654f276b4e8fbf1aa2faf78c5d649a2f84413823 1 parent e67db71
@davybrion authored
Showing with 12 additions and 3 deletions.
  1. +3 −0  TODO
  2. +8 −2 lib/routes/customer.js
  3. +1 −1  lib/views/customer/list.html
View
3  TODO
@@ -4,6 +4,8 @@ In Progress
- UI testing still needs to be done
- route testing ?
- View Customers
+ - UI testing still needs to be done
+ - route testing ?
Backlog
-------------------
@@ -29,6 +31,7 @@ Technical stuff
- authentication
- authorization
- use minimized versions of script files when in production environment
+- clean up error handling: try to remove these calls: if (err) { return next(err); };
General
View
10 lib/routes/customer.js
@@ -9,16 +9,22 @@ module.exports = function(app){
app.get('/customer/list', function(req, res, next) {
var customers = Customer.find({}, [ 'name' ], function(err, docs) {
if (err) { return next(err); }
-
+ console.log(docs);
res.render('customer/list', { customers: docs });
});
});
+ app.get('/customer/:id', function(req, res, next) {
+ var customer = Customer.findById(req.params.id, function(err, customer) {
+ if (err) { return next(err); };
+ res.send(customer);
+ });
+ });
+
app.post('/customer', function(req, res, next) {
var newCustomer = new Customer(req.body.customer);
newCustomer.save(function(err, result) {
if (err) { return next(err); }
-
req.flash('info', 'customer with id ' + result.id + ' created');
res.redirect('/');
});
View
2  lib/views/customer/list.html
@@ -2,6 +2,6 @@
<div id="customerList">
<% customers.forEach(function(customer) { %>
- <p><%= customer.name %> </p>
+ <p><%= customer.name %> <a href="<%= '/customer/' + customer.id %>">Details</a></p>
<% }); %>
</div>
Please sign in to comment.
Something went wrong with that request. Please try again.