Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hapi 0.6.0

  • Loading branch information...
commit 4b8e5904ccbb0ca6607b103bdbd9be5ba079e62c 1 parent 42cb6d2
@hueniverse authored
View
6 api/batch.js
@@ -26,7 +26,7 @@ exports.type = {
// Batch processing
-exports.post = function (request, reply) {
+exports.post = function (request) {
var requests = [];
var results = [];
@@ -95,7 +95,7 @@ exports.post = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest(error));
+ request.reply(Hapi.Error.badRequest(error));
}
}
@@ -105,7 +105,7 @@ exports.post = function (request, reply) {
// Return results
- reply(results);
+ request.reply(results);
});
}
View
18 api/details.js
@@ -26,7 +26,7 @@ exports.type = {
// Task details
-exports.get = function (request, reply) {
+exports.get = function (request) {
exports.load(request.params.id, request.userId, false, function (details, err, task, project) {
@@ -72,12 +72,12 @@ exports.get = function (request, reply) {
details.thread[i].user = usersMap[details.thread[i].user] || { id: details.thread[i].user };
}
- reply(details);
+ request.reply(details);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -85,7 +85,7 @@ exports.get = function (request, reply) {
// Add task detail
-exports.post = function (request, reply) {
+exports.post = function (request) {
var now = Hapi.Utils.getTimestamp();
@@ -111,7 +111,7 @@ exports.post = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -130,19 +130,19 @@ exports.post = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(err);
+ request.reply(err);
}
}
else {
- reply(err);
+ request.reply(err);
}
});
@@ -155,7 +155,7 @@ exports.post = function (request, reply) {
}
Stream.update({ object: 'details', project: task.project, task: task._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
};
View
14 api/email.js
@@ -274,7 +274,7 @@ exports.sendReminder = function (user, callback) {
'Use this link to sign into ' + Config.product.name + ': \n\n' +
' ' + Config.host.uri('web') + '/t/' + ticket;
- Hapi.Utils.email(user.emails[0].address, subject, text);
+ Hapi.Email.send(user.emails[0].address, subject, text);
callback(null);
}
else {
@@ -306,7 +306,7 @@ exports.sendValidation = function (user, address, callback) {
'Use this link to verify your email address: \n\n' +
' ' + Config.host.uri('web') + '/t/' + ticket;
- Hapi.Utils.email(address, subject, text);
+ Hapi.Email.send(address, subject, text);
callback(null);
}
else {
@@ -349,7 +349,7 @@ exports.sendWelcome = function (user, callback) {
text += 'Use this link to verify your email address: \n\n';
text += ' ' + Config.host.uri('web') + '/t/' + ticket + '\n\n';
- Hapi.Utils.email(address, subject, text);
+ Hapi.Email.send(address, subject, text);
callback(null);
}
else {
@@ -367,7 +367,7 @@ exports.sendWelcome = function (user, callback) {
text += 'Use this link to sign-into ' + Config.product.name + ': \n\n';
text += ' ' + Config.host.uri('web') + '/\n\n';
- Hapi.Utils.email(address, subject, text);
+ Hapi.Email.send(address, subject, text);
callback(null);
}
else {
@@ -382,7 +382,7 @@ exports.sendWelcome = function (user, callback) {
text += 'Since you have not yet linked a Facebook, Twitter, or Yahoo! account, you will need to use this link to sign back into ' + Config.product.name + ': \n\n';
text += ' ' + Config.host.uri('web') + '/t/' + ticket + '\n\n';
- Hapi.Utils.email(address, subject, text);
+ Hapi.Email.send(address, subject, text);
callback(null);
}
else {
@@ -428,7 +428,7 @@ exports.projectInvite = function (users, pids, project, message, inviter) {
link = 'Use this link to join: \n\n' +
' ' + Config.host.uri('web') + '/view/#project=' + project._id;
- Hapi.Utils.email(users[i].emails[0].address,
+ Hapi.Email.send(users[i].emails[0].address,
subject,
'Hi ' + (users[i].name || users[i].username || users[i].emails[0].address) + ',\n\n' + text + link);
}
@@ -447,7 +447,7 @@ exports.projectInvite = function (users, pids, project, message, inviter) {
link = 'Use this link to join: \n\n' +
' ' + Config.host.uri('web') + '/i/' + invite;
- Hapi.Utils.email(pid.email, subject, 'Hi ' + (pid.display || pid.email) + ',\n\n' + text + link, null, function (err) {
+ Hapi.Email.send(pid.email, subject, 'Hi ' + (pid.display || pid.email) + ',\n\n' + text + link, null, function (err) {
if (err === null) {
View
21 api/index.js
@@ -23,27 +23,30 @@ var internals = {};
// Post handler extension middleware
-internals.onPostHandler = function (req, res, next) {
+internals.onPostHandler = function (request, next) {
- if (res.hapi.result) {
+ if (request.response &&
+ request.response.result) {
+
+ var result = request.response.result;
// Sanitize database fields
- if (res.hapi.result._id) {
+ if (result._id) {
- res.hapi.result.id = res.hapi.result._id;
- delete res.hapi.result._id;
+ result.id = result._id;
+ delete result._id;
}
- if (res.hapi.result instanceof Object) {
+ if (result instanceof Object) {
- for (var i in res.hapi.result) {
+ for (var i in result) {
- if (res.hapi.result.hasOwnProperty(i)) {
+ if (result.hasOwnProperty(i)) {
if (i[0] === '_') {
- delete res.hapi.result[i];
+ delete result[i];
}
}
}
View
24 api/invite.js
@@ -14,7 +14,7 @@ var Stream = require('./stream');
// Check invitation code
-exports.get = function (request, reply) {
+exports.get = function (request) {
// Check invitation code type
@@ -71,17 +71,17 @@ exports.get = function (request, reply) {
about.inviter = inviter.display;
}
- reply(about);
+ request.reply(about);
});
}
else {
- reply(Hapi.Error.badRequest('Invalid invitation code'));
+ request.reply(Hapi.Error.badRequest('Invalid invitation code'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -93,11 +93,11 @@ exports.get = function (request, reply) {
if (err === null) {
- reply(invite);
+ request.reply(invite);
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -106,7 +106,7 @@ exports.get = function (request, reply) {
// Claim a project invitation
-exports.claim = function (request, reply) {
+exports.claim = function (request) {
var inviteRegex = /^project:([^:]+):([^:]+):([^:]+)$/;
var parts = inviteRegex.exec(request.params.id);
@@ -154,28 +154,28 @@ exports.claim = function (request, reply) {
if (err === null) {
Stream.update({ object: 'project', project: projectId }, request);
- reply({ status: 'ok', project: projectId });
+ request.reply({ status: 'ok', project: projectId });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Invalid invitation code'));
+ request.reply(Hapi.Error.badRequest('Invalid invitation code'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Invalid invitation format'));
+ request.reply(Hapi.Error.badRequest('Invalid invitation format'));
}
};
View
34 api/last.js
@@ -18,7 +18,7 @@ var internals = {};
// Last information for project (with tasks)
-exports.getProject = function (request, reply) {
+exports.getProject = function (request) {
exports.load(request.userId, function (last, err) {
@@ -29,15 +29,15 @@ exports.getProject = function (request, reply) {
var record = { id: last._id, projects: {} };
record.projects[request.params.id] = last.projects[request.params.id];
- reply(record);
+ request.reply(record);
}
else if (err === null) {
- reply({ id: request.userId, projects: {} });
+ request.reply({ id: request.userId, projects: {} });
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -45,7 +45,7 @@ exports.getProject = function (request, reply) {
// Set last project timestamp
-exports.postProject = function (request, reply) {
+exports.postProject = function (request) {
Project.load(request.params.id, request.userId, false, function (project, member, err) {
@@ -55,17 +55,17 @@ exports.postProject = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -73,7 +73,7 @@ exports.postProject = function (request, reply) {
// Last information for single task
-exports.getTask = function (request, reply) {
+exports.getTask = function (request) {
Task.load(request.params.id, request.userId, false, function (task, err, project) {
@@ -91,21 +91,21 @@ exports.getTask = function (request, reply) {
record.projects[task.project] = { tasks: {} };
record.projects[task.project].tasks[request.params.id] = last.projects[task.project].tasks[request.params.id];
- reply(record);
+ request.reply(record);
}
else if (err === null) {
- reply({ id: request.userId, projects: {} });
+ request.reply({ id: request.userId, projects: {} });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -113,7 +113,7 @@ exports.getTask = function (request, reply) {
// Set last task timestamp
-exports.postTask = function (request, reply) {
+exports.postTask = function (request) {
Task.load(request.params.id, request.userId, false, function (task, err, project) {
@@ -123,17 +123,17 @@ exports.postTask = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
View
6 api/package.json
@@ -1,11 +1,11 @@
{
"name": "postmile.api",
"description": "Postmile API Server",
- "version": "0.0.2",
- "author": "Eran Hammer-Lahav <eran@hammer-lahav.net>",
+ "version": "0.0.3",
+ "author": "Eran Hammer-Lahav <eran@hueniverse.com>",
"private": true,
"dependencies": {
- "hapi": "0.4.x",
+ "hapi": "0.6.x",
"mongodb": "0.9.x",
"oauth": "0.9.x",
"socket.io": "0.8.x",
View
116 api/project.js
@@ -55,7 +55,7 @@ exports.type.uninvite = {
// Get project information
-exports.get = function (request, reply) {
+exports.get = function (request) {
exports.load(request.params.id, request.userId, false, function (project, member, err) {
@@ -65,12 +65,12 @@ exports.get = function (request, reply) {
project.participants = participants;
- reply(project);
+ request.reply(project);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -78,7 +78,7 @@ exports.get = function (request, reply) {
// Get list of projects for current user
-exports.list = function (request, reply) {
+exports.list = function (request) {
Sort.list('project', request.userId, 'participants.id', function (projects) {
@@ -122,12 +122,12 @@ exports.list = function (request, reply) {
}
}
- reply(list);
+ request.reply(list);
});
}
else {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
});
};
@@ -135,7 +135,7 @@ exports.list = function (request, reply) {
// Update project properties
-exports.post = function (request, reply) {
+exports.post = function (request) {
exports.load(request.params.id, request.userId, true, function (project, member, err) {
@@ -162,17 +162,17 @@ exports.post = function (request, reply) {
}
}
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Cannot include both position parameter and project object in body'));
+ request.reply(Hapi.Error.badRequest('Cannot include both position parameter and project object in body'));
}
}
else if (request.query.position) {
@@ -182,22 +182,22 @@ exports.post = function (request, reply) {
if (err === null) {
Stream.update({ object: 'projects', user: request.userId }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Missing position parameter or project object in body'));
+ request.reply(Hapi.Error.badRequest('Missing position parameter or project object in body'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -205,7 +205,7 @@ exports.post = function (request, reply) {
// Create new project
-exports.put = function (request, reply) {
+exports.put = function (request) {
var project = request.payload;
project.participants = [{ id: request.userId}];
@@ -215,11 +215,11 @@ exports.put = function (request, reply) {
if (err === null) {
Stream.update({ object: 'projects', user: request.userId }, request);
- reply({ status: 'ok', id: items[0]._id }, { created: 'project/' + items[0]._id });
+ request.reply({ status: 'ok', id: items[0]._id }, { created: 'project/' + items[0]._id });
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -227,7 +227,7 @@ exports.put = function (request, reply) {
// Delete a project
-exports.del = function (request, reply) {
+exports.del = function (request) {
exports.load(request.params.id, request.userId, false, function (project, member, err) {
@@ -262,17 +262,17 @@ exports.del = function (request, reply) {
}
}
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -288,18 +288,18 @@ exports.del = function (request, reply) {
Stream.update({ object: 'projects', user: request.userId }, request);
Stream.drop(request.userId, project._id);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -307,7 +307,7 @@ exports.del = function (request, reply) {
// Get list of project tips
-exports.tips = function (request, reply) {
+exports.tips = function (request) {
// Get project
@@ -319,12 +319,12 @@ exports.tips = function (request, reply) {
Tips.list(project, function (results) {
- reply(results);
+ request.reply(results);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -332,7 +332,7 @@ exports.tips = function (request, reply) {
// Get list of project suggestions
-exports.suggestions = function (request, reply) {
+exports.suggestions = function (request) {
// Get project
@@ -344,12 +344,12 @@ exports.suggestions = function (request, reply) {
Suggestions.list(project, request.userId, function (results) {
- reply(results);
+ request.reply(results);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -357,7 +357,7 @@ exports.suggestions = function (request, reply) {
// Add new participants to a project
-exports.participants = function (request, reply) {
+exports.participants = function (request) {
if (request.query.message) {
@@ -369,12 +369,12 @@ exports.participants = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest('Message cannot contain links'));
+ request.reply(Hapi.Error.badRequest('Message cannot contain links'));
}
}
else {
- reply(Hapi.Error.badRequest('Message length is greater than ' + internals.maxMessageLength));
+ request.reply(Hapi.Error.badRequest('Message length is greater than ' + internals.maxMessageLength));
}
}
else {
@@ -417,7 +417,7 @@ exports.participants = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -530,37 +530,37 @@ exports.participants = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('All users are already project participants'));
+ request.reply(Hapi.Error.badRequest('All users are already project participants'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.internal(err));
+ request.reply(Hapi.Error.internal(err));
}
});
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Body must contain a participants or names array'));
+ request.reply(Hapi.Error.badRequest('Body must contain a participants or names array'));
}
}
@@ -578,12 +578,12 @@ exports.participants = function (request, reply) {
var response = { status: 'ok', participants: participants };
- reply(response);
+ request.reply(response);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -592,7 +592,7 @@ exports.participants = function (request, reply) {
// Remove participant from project
-exports.uninvite = function (request, reply) {
+exports.uninvite = function (request) {
// Load project for write
@@ -630,18 +630,18 @@ exports.uninvite = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.notFound('Not a project participant'));
+ request.reply(Hapi.Error.notFound('Not a project participant'));
}
}
else {
- reply(Hapi.Error.badRequest('Cannot uninvite self'));
+ request.reply(Hapi.Error.badRequest('Cannot uninvite self'));
}
}
else if (request.payload.participants) {
@@ -696,28 +696,28 @@ exports.uninvite = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(error);
+ request.reply(error);
}
}
else {
- reply(Hapi.Error.badRequest('No participant for removal included'));
+ request.reply(Hapi.Error.badRequest('No participant for removal included'));
}
}
else {
- reply(Hapi.Error.badRequest('Not an owner'));
+ request.reply(Hapi.Error.badRequest('Not an owner'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
@@ -765,12 +765,12 @@ exports.uninvite = function (request, reply) {
var response = { status: 'ok', participants: participants };
- reply(response);
+ request.reply(response);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -779,7 +779,7 @@ exports.uninvite = function (request, reply) {
// Accept project invitation
-exports.join = function (request, reply) {
+exports.join = function (request) {
// The only place allowed to request a non-writable copy for modification
exports.load(request.params.id, request.userId, false, function (project, member, err) {
@@ -799,22 +799,22 @@ exports.join = function (request, reply) {
Stream.update({ object: 'project', project: project._id }, request);
Stream.update({ object: 'projects', user: request.userId }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Already a member of the project'));
+ request.reply(Hapi.Error.badRequest('Already a member of the project'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
View
110 api/session.js
@@ -32,7 +32,7 @@ exports.type.client = {
// Get client information endpoint
-exports.client = function (request, reply) {
+exports.client = function (request) {
exports.loadClient(request.params.id, function (client, err) {
@@ -41,16 +41,16 @@ exports.client = function (request, reply) {
if (client) {
Hapi.Utils.hide(client, exports.type.client);
- reply(client);
+ request.reply(client);
}
else {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -185,82 +185,84 @@ exports.extensionGrant = function (request, client, callback) {
if (request.payload.grant_type.search('http://ns.postmile.net/') !== 0) {
// Unsupported grant type namespace
- reply(Hapi.Error.oauth('unsupported_grant_type', 'Unknown or unsupported grant type namespace'));
+ callback(null, Hapi.Error.oauth('unsupported_grant_type', 'Unknown or unsupported grant type namespace'));
}
+ else {
- var grantType = request.payload.grant_type.replace('http://ns.postmile.net/', '');
+ var grantType = request.payload.grant_type.replace('http://ns.postmile.net/', '');
- // Check if client has 'login' scope
+ // Check if client has 'login' scope
- if ((client.scope && client.scope.login === true) ||
- (request.scope && request.scope.login === true)) {
+ if ((client.scope && client.scope.login === true) ||
+ (request.scope && request.scope.login === true)) {
- // Switch on grant type
+ // Switch on grant type
- if (grantType === 'id') {
+ if (grantType === 'id') {
- // Get user
+ // Get user
- User.load(request.payload.x_user_id, function (user, err) {
+ User.load(request.payload.x_user_id, function (user, err) {
- if (user) {
+ if (user) {
- callback(user, null);
- }
- else {
+ callback(user, null);
+ }
+ else {
- // Unknown local account
- callback(null, Hapi.Error.oauth('invalid_grant', 'Unknown local account'));
- }
- });
- }
- else if (grantType === 'twitter' ||
- grantType === 'facebook' ||
- grantType === 'yahoo') {
+ // Unknown local account
+ callback(null, Hapi.Error.oauth('invalid_grant', 'Unknown local account'));
+ }
+ });
+ }
+ else if (grantType === 'twitter' ||
+ grantType === 'facebook' ||
+ grantType === 'yahoo') {
- // Check network identifier
+ // Check network identifier
- User.validate(request.payload.x_user_id, grantType, function (user, err) {
+ User.validate(request.payload.x_user_id, grantType, function (user, err) {
- if (user) {
+ if (user) {
- callback(user, null);
- }
- else {
+ callback(user, null);
+ }
+ else {
- // Unregistered network account
- callback(null, Hapi.Error.oauth('invalid_grant', 'Unknown ' + grantType.charAt(0).toUpperCase() + grantType.slice(1) + ' account: ' + request.payload.x_user_id));
- }
- });
- }
- else if (grantType === 'email') {
+ // Unregistered network account
+ callback(null, Hapi.Error.oauth('invalid_grant', 'Unknown ' + grantType.charAt(0).toUpperCase() + grantType.slice(1) + ' account: ' + request.payload.x_user_id));
+ }
+ });
+ }
+ else if (grantType === 'email') {
- // Check email identifier
+ // Check email identifier
- Email.loadTicket(request.payload.x_email_token, function (ticket, user, err) {
+ Email.loadTicket(request.payload.x_email_token, function (ticket, user, err) {
- if (ticket) {
+ if (ticket) {
- callback(user, null, { 'x_action': ticket.action });
- }
- else {
+ callback(user, null, { 'x_action': ticket.action });
+ }
+ else {
- // Invalid email token
- callback(null, Hapi.Error.oauth('invalid_grant', err.message));
- }
- });
+ // Invalid email token
+ callback(null, Hapi.Error.oauth('invalid_grant', err.message));
+ }
+ });
+ }
+ else {
+
+ // Unsupported grant type
+ callback(null, Hapi.Error.oauth('unsupported_grant_type', 'Unknown or unsupported grant type: ' + grantType));
+ }
}
else {
- // Unsupported grant type
- callback(null, Hapi.Error.oauth('unsupported_grant_type', 'Unknown or unsupported grant type: ' + grantType));
+ // No client scope for local account access
+ callback(null, Hapi.Error.oauth('unauthorized_client', 'Client missing \'login\' scope'));
}
}
- else {
-
- // No client scope for local account access
- callback(null, Hapi.Error.oauth('unauthorized_client', 'Client missing \'login\' scope'));
- }
};
View
44 api/storage.js
@@ -24,7 +24,7 @@ exports.type = {
// User client data
-exports.get = function (request, reply) {
+exports.get = function (request) {
exports.load(request.userId, function (storage, err) {
@@ -41,37 +41,37 @@ exports.get = function (request, reply) {
var result = {};
result[request.params.id] = storage.clients[request.clientId][request.params.id];
- reply(result);
+ request.reply(result);
}
else {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
}
else {
- reply(Hapi.Error.badRequest('Invalid key'));
+ request.reply(Hapi.Error.badRequest('Invalid key'));
}
}
else {
- reply(storage.clients[request.clientId]);
+ request.reply(storage.clients[request.clientId]);
}
}
else if (err === null) {
if (request.params.id) {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
else {
- reply({});
+ request.reply({});
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -79,7 +79,7 @@ exports.get = function (request, reply) {
// Set user client data
-exports.post = function (request, reply) {
+exports.post = function (request) {
if (internals.checkKey(request.params.id)) {
@@ -115,11 +115,11 @@ exports.post = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -135,31 +135,31 @@ exports.post = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Invalid key'));
+ request.reply(Hapi.Error.badRequest('Invalid key'));
}
};
// Delete user client data
-exports.del = function (request, reply) {
+exports.del = function (request) {
if (internals.checkKey(request.params.id)) {
@@ -179,32 +179,32 @@ exports.del = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
}
else if (err === null) {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Invalid key'));
+ request.reply(Hapi.Error.badRequest('Invalid key'));
}
};
View
24 api/stream.js
@@ -66,7 +66,7 @@ exports.update = function (update, request) {
// Subscribe
-exports.subscribe = function (request, reply) {
+exports.subscribe = function (request) {
// Lookup socket
@@ -101,34 +101,34 @@ exports.subscribe = function (request, reply) {
// Send ack via the request
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.forbidden());
+ request.reply(Hapi.Error.forbidden());
}
}
else {
- reply(Hapi.Error.badRequest('Stream not initialized'));
+ request.reply(Hapi.Error.badRequest('Stream not initialized'));
}
}
else {
- reply(Hapi.Error.notFound('Stream not found'));
+ request.reply(Hapi.Error.notFound('Stream not found'));
}
};
// Unsubscribe
-exports.unsubscribe = function (request, reply) {
+exports.unsubscribe = function (request) {
// Lookup socket
@@ -161,26 +161,26 @@ exports.unsubscribe = function (request, reply) {
// Send ack via the request
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(Hapi.Error.notFound('Project subscription not found'));
+ request.reply(Hapi.Error.notFound('Project subscription not found'));
}
}
else {
- reply(Hapi.Error.forbidden());
+ request.reply(Hapi.Error.forbidden());
}
}
else {
- reply(Hapi.Error.badRequest('Stream not initialized'));
+ request.reply(Hapi.Error.badRequest('Stream not initialized'));
}
}
else {
- reply(Hapi.Error.notFound('Stream not found'));
+ request.reply(Hapi.Error.notFound('Stream not found'));
}
};
View
16 api/suggestions.js
@@ -56,7 +56,7 @@ exports.initialize = function () {
// Remove suggestion from project
-exports.exclude = function (request, reply) {
+exports.exclude = function (request) {
Project.load(request.params.id, request.userId, false, function (project, member, err) {
@@ -107,11 +107,11 @@ exports.exclude = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -127,29 +127,29 @@ exports.exclude = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
View
58 api/task.js
@@ -20,7 +20,7 @@ exports.type = {};
exports.type.post = {
- project: { type: 'id', set: false },
+ project: { type: 'id', set: false },
title: { type: 'string' },
status: { type: 'enum', values: { open: 1, pending: 2, close: 3 } },
participants: { type: 'id', array: true, empty: true },
@@ -33,7 +33,7 @@ exports.type.put.participants.set = false;
// Task information
-exports.get = function (request, reply) {
+exports.get = function (request) {
exports.load(request.params.id, request.userId, false, function (task, err) {
@@ -50,12 +50,12 @@ exports.get = function (request, reply) {
}
Hapi.Utils.hide(task, exports.type.post);
- reply(task);
+ request.reply(task);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -63,7 +63,7 @@ exports.get = function (request, reply) {
// Get list of tasks for given project
-exports.list = function (request, reply) {
+exports.list = function (request) {
Project.load(request.params.id, request.userId, false, function (project, member, err) {
@@ -122,18 +122,18 @@ exports.list = function (request, reply) {
}
}
- reply(list);
+ request.reply(list);
});
}
else {
- reply(Hapi.Error.notFound());
+ request.reply(Hapi.Error.notFound());
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -141,7 +141,7 @@ exports.list = function (request, reply) {
// Update task properties
-exports.post = function (request, reply) {
+exports.post = function (request) {
exports.load(request.params.id, request.userId, true, function (task, err, project) {
@@ -185,7 +185,7 @@ exports.post = function (request, reply) {
if (error) {
isInvalid = true;
- reply(Hapi.Error.badRequest(error));
+ request.reply(Hapi.Error.badRequest(error));
}
}
@@ -196,18 +196,18 @@ exports.post = function (request, reply) {
if (err === null) {
Stream.update({ object: 'task', project: task.project, task: task._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(Hapi.Error.badRequest('Cannot include both position parameter and task object in body'));
+ request.reply(Hapi.Error.badRequest('Cannot include both position parameter and task object in body'));
}
}
else if (request.query.position !== null &&
@@ -220,22 +220,22 @@ exports.post = function (request, reply) {
if (err === null) {
Stream.update({ object: 'tasks', project: task.project }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Missing position parameter or task object in body'));
+ request.reply(Hapi.Error.badRequest('Missing position parameter or task object in body'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -243,7 +243,7 @@ exports.post = function (request, reply) {
// Create new task
-exports.put = function (request, reply) {
+exports.put = function (request) {
Project.load(request.params.id, request.userId, true, function (project, member, err) {
@@ -264,13 +264,13 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest('Suggestion not found'));
+ request.reply(Hapi.Error.badRequest('Suggestion not found'));
}
});
}
else {
- reply(Hapi.Error.badRequest('New task cannot have both body and suggestion id'));
+ request.reply(Hapi.Error.badRequest('New task cannot have both body and suggestion id'));
}
}
else {
@@ -283,13 +283,13 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest('New task must include a title or a suggestion id'));
+ request.reply(Hapi.Error.badRequest('New task must include a title or a suggestion id'));
}
}
}
else {
- reply(err);
+ request.reply(err);
}
});
@@ -318,17 +318,17 @@ exports.put = function (request, reply) {
result.position = request.query.position;
}
- reply(result, replyOptions);
+ request.reply(result, replyOptions);
});
}
else {
- reply(result, replyOptions);
+ request.reply(result, replyOptions);
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -337,7 +337,7 @@ exports.put = function (request, reply) {
// Delete a task
-exports.del = function (request, reply) {
+exports.del = function (request) {
exports.load(request.params.id, request.userId, true, function (task, err) {
@@ -350,17 +350,17 @@ exports.del = function (request, reply) {
Db.remove('task.details', task._id, function (err) { });
Stream.update({ object: 'tasks', project: task.project }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
View
212 api/user.js
@@ -104,18 +104,18 @@ internals.forbiddenUsernames = {
// Current user information
-exports.get = function (request, reply) {
+exports.get = function (request) {
exports.load(request.userId, function (user, err) {
if (user) {
Hapi.Utils.hide(user, exports.type.user);
- reply(user);
+ request.reply(user);
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -123,7 +123,7 @@ exports.get = function (request, reply) {
// Change profile properties
-exports.post = function (request, reply) {
+exports.post = function (request) {
exports.load(request.userId, function (user, err) {
@@ -151,17 +151,17 @@ exports.post = function (request, reply) {
if (err === null) {
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(typeof err === 'string' ? Hapi.Error.badRequest('Invalid username: ' + err) : err);
+ request.reply(typeof err === 'string' ? Hapi.Error.badRequest('Invalid username: ' + err) : err);
}
});
}
@@ -172,18 +172,18 @@ exports.post = function (request, reply) {
if (err === null) {
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -191,7 +191,7 @@ exports.post = function (request, reply) {
// Change profile email settings
-exports.email = function (request, reply) {
+exports.email = function (request) {
var address = request.payload.address.toLowerCase();
@@ -245,29 +245,29 @@ exports.email = function (request, reply) {
}
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
});
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Email already assigned to another account'));
+ request.reply(Hapi.Error.badRequest('Email already assigned to another account'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Address already present'));
+ request.reply(Hapi.Error.badRequest('Address already present'));
}
break;
@@ -301,27 +301,27 @@ exports.email = function (request, reply) {
if (err === null) {
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Email must be verified before made primary'));
+ request.reply(Hapi.Error.badRequest('Email must be verified before made primary'));
}
}
else {
- reply(Hapi.Error.badRequest('Address already primary'));
+ request.reply(Hapi.Error.badRequest('Address already primary'));
}
}
else {
- reply(Hapi.Error.notFound('No such email address'));
+ request.reply(Hapi.Error.notFound('No such email address'));
}
break;
@@ -345,27 +345,27 @@ exports.email = function (request, reply) {
if (err === null) {
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Cannot remove the only address present'));
+ request.reply(Hapi.Error.badRequest('Cannot remove the only address present'));
}
}
else {
- reply(Hapi.Error.badRequest('Cannot remove primary address'));
+ request.reply(Hapi.Error.badRequest('Cannot remove primary address'));
}
}
else {
- reply(Hapi.Error.notFound('No such email address'));
+ request.reply(Hapi.Error.notFound('No such email address'));
}
break;
@@ -382,29 +382,29 @@ exports.email = function (request, reply) {
if (err === null) {
- reply({ result: 'ok' });
+ request.reply({ result: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Account already verified'));
+ request.reply(Hapi.Error.badRequest('Account already verified'));
}
}
else {
- reply(Hapi.Error.notFound('No such email address'));
+ request.reply(Hapi.Error.notFound('No such email address'));
}
break;
}
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -412,7 +412,7 @@ exports.email = function (request, reply) {
// Current user contacts list
-exports.contacts = function (request, reply) {
+exports.contacts = function (request) {
if (request.query.exclude) {
@@ -424,7 +424,7 @@ exports.contacts = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -509,12 +509,12 @@ exports.contacts = function (request, reply) {
return 0;
});
- reply(contacts);
+ request.reply(contacts);
});
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -523,15 +523,15 @@ exports.contacts = function (request, reply) {
// Who am I?
-exports.who = function (request, reply) {
+exports.who = function (request) {
- reply({ user: request.userId });
+ request.reply({ user: request.userId });
};
// Register new user
-exports.put = function (request, reply) {
+exports.put = function (request) {
// Check invitation code
@@ -602,18 +602,18 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest('Invalid invitation code'));
+ request.reply(Hapi.Error.badRequest('Invalid invitation code'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Invalid invitation format'));
+ request.reply(Hapi.Error.badRequest('Invalid invitation format'));
}
}
else {
@@ -631,14 +631,14 @@ exports.put = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
}
else {
- reply(Hapi.Error.badRequest('Invitation code missing'));
+ request.reply(Hapi.Error.badRequest('Invitation code missing'));
}
function validate() {
@@ -657,7 +657,7 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest('Must include either a network id or email address'));
+ request.reply(Hapi.Error.badRequest('Must include either a network id or email address'));
}
}
@@ -675,12 +675,12 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest('Email address already linked to an existing user'));
+ request.reply(Hapi.Error.badRequest('Email address already linked to an existing user'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -739,18 +739,18 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.badRequest(request.payload.network[0].replace(/^\w/, function ($0) { return $0.toUpperCase(); }) + ' account already linked to an existing user'));
+ request.reply(Hapi.Error.badRequest(request.payload.network[0].replace(/^\w/, function ($0) { return $0.toUpperCase(); }) + ' account already linked to an existing user'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest(error));
+ request.reply(Hapi.Error.badRequest(error));
}
}
else {
@@ -772,7 +772,7 @@ exports.put = function (request, reply) {
}
else {
- reply(typeof err === 'string' ? Hapi.Error.badRequest('Invalid username: ' + err) : err);
+ request.reply(typeof err === 'string' ? Hapi.Error.badRequest('Invalid username: ' + err) : err);
}
});
}
@@ -835,7 +835,7 @@ exports.put = function (request, reply) {
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -846,12 +846,12 @@ exports.put = function (request, reply) {
}
else {
- reply(Hapi.Error.internal('Failed to retrieve new user id', user));
+ request.reply(Hapi.Error.internal('Failed to retrieve new user id', user));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
@@ -862,7 +862,7 @@ exports.put = function (request, reply) {
Email.sendWelcome(user, function (err) { // Ignore error
- reply({ status: 'ok', id: user._id });
+ request.reply({ status: 'ok', id: user._id });
});
}
};
@@ -870,7 +870,7 @@ exports.put = function (request, reply) {
// Set Terms of Service version
-exports.tos = function (request, reply) {
+exports.tos = function (request) {
exports.load(request.params.id, function (user, err) {
@@ -883,17 +883,17 @@ exports.tos = function (request, reply) {
if (err === null) {
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(err);
+ request.reply(err);
}
});
};
@@ -901,7 +901,7 @@ exports.tos = function (request, reply) {
// Link other account
-exports.link = function (request, reply) {
+exports.link = function (request) {
if (request.params.network === 'facebook' ||
request.params.network === 'twitter' ||
@@ -934,46 +934,46 @@ exports.link = function (request, reply) {
if (err === null) {
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Network id already linked to another user'));
+ request.reply(Hapi.Error.badRequest('Network id already linked to another user'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Network already linked'));
+ request.reply(Hapi.Error.badRequest('Network already linked'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Unknown network'));
+ request.reply(Hapi.Error.badRequest('Unknown network'));
}
};
// Unlink other account
-exports.unlink = function (request, reply) {
+exports.unlink = function (request) {
if (request.params.network === 'facebook' ||
request.params.network === 'twitter' ||
@@ -1002,40 +1002,40 @@ exports.unlink = function (request, reply) {
if (err === null) {
Stream.update({ object: 'profile', user: user._id }, request);
- reply({ status: 'ok' });
+ request.reply({ status: 'ok' });
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Cannot remove last linked account'));
+ request.reply(Hapi.Error.badRequest('Cannot remove last linked account'));
}
}
else {
- reply(Hapi.Error.badRequest('Account not linked'));
+ request.reply(Hapi.Error.badRequest('Account not linked'));
}
}
else {
- reply(err);
+ request.reply(err);
}
});
}
else {
- reply(Hapi.Error.badRequest('Unknown network'));
+ request.reply(Hapi.Error.badRequest('Unknown network'));