ForgeTotal.js 5
en

Total.js 5

Chain several actions in one route

Total.js 5 · total5@0.0.19 actionsrouting Executed against Total.js 5

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.

definitions/order.js
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 });
	}
});
controllers/order.js
exports.install = function() {
	ROUTE('POST /order/ --> *Order/validate *Order/save (response)');
};