aboutsummaryrefslogtreecommitdiff
path: root/routes/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'routes/index.js')
-rw-r--r--routes/index.js27
1 files changed, 14 insertions, 13 deletions
diff --git a/routes/index.js b/routes/index.js
index 9c2a157..533b7b1 100644
--- a/routes/index.js
+++ b/routes/index.js
@@ -33,7 +33,6 @@ exports.department = function(req, res){
if(err) throw err;
var dept_no = req.params.dept_no;
var employees = [];
- // TODO:
// TODO: Add dept_name to view
// TODO: Add manager as a link
client.query('SELECT employees.* FROM employees, dept_emp WHERE employees.emp_no=dept_emp.emp_no AND dept_emp.dept_no=$1 AND dept_emp.to_date > now() AND now() > dept_emp.from_date', [ dept_no ]).
@@ -41,16 +40,17 @@ exports.department = function(req, res){
employees.push(row);
}).
on('end', function() {
- if(req.accepts('application/vnd.collection+json')) {
- var object = collection_json.fromObject({});
- res.contentType('application/vnd.collection+json');
- res.send(object);
- }
- else
+ if(req.accepts('html')) {
res.render('department', {
title: 'Department ' + dept_no,
employees: employees
});
+ }
+ else {
+ var object = collection_json.fromObject({});
+ res.contentType('application/vnd.collection+json');
+ res.send(object);
+ }
});
});
};
@@ -65,17 +65,18 @@ exports.employee = function(req, res){
employee = row;
}).
on('end', function() {
- if(req.accepts('application/vnd.collection+json')) {
+ if(req.accepts('html')) {
+ res.render('employee', {
+ title: 'Employee ' + emp_no,
+ employee: employee
+ });
+ }
+ else {
var items = [ mapRow(employee) ];
var object = collection_json.fromObject({collection: {items: items}});
res.contentType('application/vnd.collection+json');
res.send(JSON.stringify(object), 200);
}
- else
- res.render('employee', {
- title: 'Employee ' + emp_no,
- employee: employee
- });
});
});
};