fixes missing _id error

This commit is contained in:
Ritchie Martori
2011-11-26 19:09:40 -08:00
parent 0a29ec3adc
commit 8c6180a256
6 changed files with 42 additions and 13 deletions

View File

@@ -69,9 +69,11 @@ module.exports = {
remove: ready(function(model) {
collection(db, model, function(err, collection) {
var id = ObjectID(model.get('_id'));
var id = model.get('_id')
, _id = id && ObjectID(id)
;
collection.remove({_id: id});
collection.remove({_id: _id});
model.refresh({removed: true});
});
}),

View File

@@ -246,6 +246,7 @@ Model = module.exports = emitter.spawn({
}
function error() {
arguments[0] = arguments[0].replace('{key}', key);
_self.error.apply(_self, arguments);
}
@@ -414,11 +415,14 @@ Model = module.exports = emitter.spawn({
;
function handler(req, res) {
var query = req.params
var query = req.query
, id = req.param('id')
, action = methodMap[req.method] || 'fetch'
;
model
if(id && !query._id) query._id = id;
var m = model
.spawn()
.for(req)
.find(query)

View File

@@ -1,5 +1,6 @@
var app = require('../../app')
, App = require('./app')
, Invite = require('./invite')
;
if(process.argv.length < 3) {
@@ -9,15 +10,29 @@ if(process.argv.length < 3) {
app.post('/app', function(req, res) {
var session = req.session
, me = session && session.user && session.user.email
, secret = req.param('secret')
, app = App.spawn().for(req).notify(res)
;
App
Invite
.spawn()
.for(req)
.set({name: req.param('name'), creator: me})
.notify(res)
.save()
.unlock()
.find({secret: secret})
.set({left: 0})
.notify(function(json) {
if(json.errors || !json.left) {
app.error('Invalid secret');
}
app
.set({name: req.param('name'), creator: me})
.save()
;
})
.fetch()
;
});
app.get('/app/:id', function(req, res) {

View File

@@ -34,8 +34,8 @@ app.get('/settings/:name', function(req, res) {
// create or update general app settings
Setting
.spawn()
.find({plugin: 'app'})
.find({plugin: 'app', name: 'app'})
.set(config)
.set({plugin: 'app'})
.set({plugin: 'app', name: 'app'})
.save()
;

View File

@@ -57,7 +57,15 @@ exports.compile = function(source) {
var sourceType = typeof source
, type = sourceType === 'string' ? source : source && source.type
, validator = sourceType === 'function' ? source : validators[type]
, required = sourceType === 'object' && source.required
;
if(required) {
return function(val, error) {
if(!val) error('{key} is required', 'Validation');
return false;
}
}
return validator || function() {};
}

View File

@@ -17,7 +17,8 @@ var user = {
var auth;
var app = {
name: 'My Testing App'
name: 'My Testing App',
secret: 'tag soup'
};
var tests = {
@@ -83,7 +84,6 @@ var tests = {
},
after: function(result) {
app = result;
console.log(app);
}
},