Various updates.

This commit is contained in:
Julien Fontanet 2013-07-11 10:51:55 +02:00
parent 16667e0d40
commit c9cd1ebee2
5 changed files with 15 additions and 11 deletions

View File

@ -112,6 +112,8 @@ Collection.prototype.remove = function (ids) {
delete this.models[id]; delete this.models[id];
}, this); }, this);
this.emit('remove', ids);
// @todo Maybe return a more meaningful value. // @todo Maybe return a more meaningful value.
/* jshint newcap: false */ /* jshint newcap: false */
return Q(true); return Q(true);

View File

@ -66,7 +66,7 @@ function json_api_call(session, message)
function (error) { function (error) {
if (error instanceof Error) if (error instanceof Error)
{ {
console.error(error); console.error(error.stack);
return format_error(Api.err.SERVER_ERROR); return format_error(Api.err.SERVER_ERROR);
} }

View File

@ -46,7 +46,7 @@ Model.prototype.get = function (property, def) {
* Checks if a property exists. * Checks if a property exists.
*/ */
Model.prototype.has = function (property) { Model.prototype.has = function (property) {
return (undefined !== this.get(property)); return (undefined !== this.properties[property]);
}; };
/** /**
@ -64,7 +64,6 @@ Model.prototype.set = function (properties, value) {
var model = this; var model = this;
_.each(properties, function (value, key) { _.each(properties, function (value, key) {
var prev = model.get(key); var prev = model.get(key);
// New value. // New value.

View File

@ -14,8 +14,8 @@ var Session = Model.extend({
// If the user associated to this session is deleted or // If the user associated to this session is deleted or
// disabled, the session must close. // disabled, the session must close.
this.on('change:user_id', function (user_id) { this.on('change:user_id', function () {
var event = 'user.revoked'+ user_id; var event = 'user.revoked:'+ this.get('user_id');
xo.on(event, close); xo.on(event, close);
@ -27,8 +27,8 @@ var Session = Model.extend({
// If the token associated to this session is deleted, the // If the token associated to this session is deleted, the
// session must close. // session must close.
this.on('change:token_id', function (token_id) { this.on('change:token_id', function () {
var event = 'token.revoked'+ token_id; var event = 'token.revoked:'+ this.get('token_id');
xo.on(event, close); xo.on(event, close);

View File

@ -1,6 +1,8 @@
var _ = require('underscore');
var crypto = require('crypto'); var crypto = require('crypto');
var hashy = require('hashy'); var hashy = require('hashy');
var Q = require('q'); var Q = require('q');
var Collection = require('./collection'); var Collection = require('./collection');
var Model = require('./model'); var Model = require('./model');
@ -149,14 +151,15 @@ function Xo()
// This events are used to automatically close connections if the // This events are used to automatically close connections if the
// associated credentials are invalidated. // associated credentials are invalidated.
var self = this;
this.tokens.on('remove', function (token_ids) { this.tokens.on('remove', function (token_ids) {
token_ids.each(function (token_id) { _.each(token_ids, function (token_id) {
this.emit('token.revoked:'+ token_id); self.emit('token.revoked:'+ token_id);
}); });
}); });
this.users.on('remove', function (user_ids) { this.users.on('remove', function (user_ids) {
user_ids.each(function (user_id) { _.each(user_ids, function (user_id) {
this.emit('user.revoked:'+ user_id); self.emit('user.revoked:'+ user_id);
}); });
}); });
} }