marat-gainullin / platypus-js

Apache License 2.0
9 stars 9 forks source link

Envets processed on the server #79

Closed Level0r0s closed 8 years ago

Level0r0s commented 8 years ago

all Platypus API are processed on the server?

I can create a event linked to model ? model.BeforePost = function(model){ model.StartTransaction; }; model.BeforeRecordPost = function(model){ if model.id==0 { //new record model.number_document= getNextNumber(model.type_document); // get next number } };

model.AffterScrool = function(model){ model.item_sum = model.qtd * model.value; //calculate }; model.AfterPost = function(){}; if model.inTransaction { model.Commit; } };

marat-gainullin commented 8 years ago

There are some points about Platypus.js server side.

First is about server modules ( session, resident, stateless and web-socket end points ).

The second is data validators. They are invoked when a client posts a change log to the server. They can examine change log from a client and if some validation rules is broken, they can throw an exception or call onFailure callback to prevent commit of a transaction. Also it is possible to complement some data while validation. Though, it is not typical use case. Take a look at https://github.com/altsoft/PlatypusTests/blob/master/app/Script%20data%20validators/EasHRValidator.js This validator is implemented as a global module. It is needed for tests. For applications it is recommended to implement modules as AMD modules.

Also, there is a module id responsible for primary keys generation. It uses random based algorithm with extremely rare collisions. This module is accessible from client code as well. In general, clients generate keys by theirselfs and these keys are used for further changes logging in change log. It provides developers with opportunity to make wide bunch of changes and commit them all inside a single transaction on server, even if those changes are applied to several database tables linked with foreign keys.