secret
Created

resourceful-functions-pre.js

  • Download Gist
resourceful-functions-pre.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
var resourceful = require('../lib/resourceful');
resourceful.use('memory');
 
var Creature = resourceful.define('creature');
 
var lazer = function(options){
console.log('firing mah lazar @ ' + options.powa);
};
 
Creature.method('fire', lazer, { properties: {
"powa": {
"type": "string",
"enum": ["high", "low", "med", "SUPA POWA"],
"required": true
}
}});
 
Creature.fire({ powa: "med"});
Creature.fire({ powa: "TOO HIGH"}, function(err, result){
// errors since TOO HIGH is not in enum
console.log(err, result);
});
 
// throws validation error
// Creature.fire({ powa: "TOO HIGH"});
 
Creature.create({
id: 'Marak'
}, function(err, marak){
if(err){
console.log(err.validate)
}
marak.fire({ powa: "med"});
 
// throws validation error
// marak.fire({ powa: "TOO HIGH"});
 
marak.fire({ powa: "low"}, function(err, result){
console.log(err, result);
});
 
marak.fire({ powa: "TOO HIGH"}, function(err, result){
// errors since TOO HIGH is not in enum
console.log(err, result);
});
});

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.