Chain several actions in one route
A route can run more than one action: write them one after another after -->. They run in order, each receives the same payload, and the first error stops the chain. Add (response) after the action whose result must be sent; without it, the last action answers.
NEWACTION('Order/validate', {
name: 'Validate the order',
input: '*product:String, *quantity:Number',
action: function($, model) {
model.quantity > 0 ? $.success() : $.invalid('quantity');
}
});
NEWACTION('Order/save', {
name: 'Save the order',
input: '*product:String, *quantity:Number',
action: function($, model) {
$.callback({ id: 'order-1', product: model.product, quantity: model.quantity });
}
});exports.install = function() {
ROUTE('POST /order/ --> *Order/validate *Order/save (response)');
};