Skip to content

Instantly share code, notes, and snippets.

@AngelMunoz
Last active December 2, 2017 08:06
Show Gist options
  • Save AngelMunoz/a11c3bf0461236f9a534ef43638710c2 to your computer and use it in GitHub Desktop.
Save AngelMunoz/a11c3bf0461236f9a534ef43638710c2 to your computer and use it in GitHub Desktop.
/**
Let say I have a fancy class with some fancy methods in services|helpers
withoud any sails logic in it, eg no waterline, no sails.*.*.js
*/
class FancyService {
async fancyMethod() {
return await Promise.resolve('Fancy Result')
}
}
module.exports = { FancyService };
/**
Let say I have a fancy class in Service.js which I do want to use as a service
the convention is to call that service like this
sails.services.service.notSoFancyMethod()
is there any overhead/problem antipattern, etc in requiring the service instead of calling it from sails.*.*.js?
*/
const { FancyService } = require('../services/FancyService');
module.exports = {
someAction: async function(req, res) {
const fancy = new FancyService(); // this?
// or this: const fancy = new sails.services.fancyservice.FancyService(); ?
// some logic, etc, etc
const results = await fancy.fancyMethod();
res.send({ results });
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment