Last active
August 31, 2017 08:16
-
-
Save vengrov/4a348e4d605cb60e124e3ccc49081234 to your computer and use it in GitHub Desktop.
Code reuse in Backendless Business Logic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//handlers/persistence/product/afterCreate.js | |
const productCreatedWorkflow = require('../../../workflows/product/created') | |
Backendless.ServerCode.Persistence.afterCreate('Product', (req, res) => { | |
const product = res.result; | |
return productCreatedWorkflow(product); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//services/products.js | |
const productCreatedWorkflow = require('../workflows/product/created') | |
class ProductsService { | |
create(data) { | |
return Backendless.Data.of('Product').save(data) | |
.then(productCreatedWorkflow) | |
} | |
} | |
Backendless.ServerCode.addService(ProductsService) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//workflows/product/created.js | |
module.exports = product => { | |
// do something with newly created product | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment