Files
freeCodeCamp/common/models/Access-Token.js
Berkeley Martinez 750c9f1eab fix(passwordless): Reduce db calls, run in parallel
Adds validations, reduces the number of database calls, separates
concers. reduces logic
2018-01-02 23:38:01 +05:30

19 lines
582 B
JavaScript

import { Observable } from 'rx';
module.exports = AccessToken => {
// wait for datasource to attach before adding methods
// prevents loopback from unnecessarily
// adding watchers on startup
AccessToken.on('dataSourceAttached', () => {
AccessToken.findOne$ = Observable.fromNodeCallback(
AccessToken.findOne.bind(AccessToken)
);
AccessToken.prototype.validate$ = Observable.fromNodeCallback(
AccessToken.prototype.validate
);
AccessToken.prototype.destroy$ = Observable.fromNodeCallback(
AccessToken.prototype.destroy
);
});
};