aboutsummaryrefslogtreecommitdiff
path: root/routes
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2012-06-29 23:41:58 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2012-06-29 23:41:58 +0200
commit7c4e5ec5a650c4bf5730b323eee2c51f1cb94fc9 (patch)
tree79d7e2b185c898b288f765dbde1012bd4269d4cd /routes
parent1de4ff6433bbfc1996d8b93d0fed369683d785a9 (diff)
downloadexample-collection-json-db-7c4e5ec5a650c4bf5730b323eee2c51f1cb94fc9.tar.gz
example-collection-json-db-7c4e5ec5a650c4bf5730b323eee2c51f1cb94fc9.tar.bz2
example-collection-json-db-7c4e5ec5a650c4bf5730b323eee2c51f1cb94fc9.tar.xz
example-collection-json-db-7c4e5ec5a650c4bf5730b323eee2c51f1cb94fc9.zip
o Check for HTML, return collection+json as default.
Diffstat (limited to 'routes')
-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
- });
});
});
};