Skip to content

Commit

Permalink
Look for fully onboarded accounts in the API
Browse files Browse the repository at this point in the history
  • Loading branch information
romainhuet committed Aug 4, 2017
1 parent 282190e commit 4fc3790
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
13 changes: 10 additions & 3 deletions server/models/pilot.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,16 @@ PilotSchema.methods.validatePassword = function(password) {
return bcrypt.compareSync(password, this.password);
};

// Get the latest pilot.
PilotSchema.statics.getLatest = function() {
return Pilot.findOne()
// Get the first fully onboarded pilot.
PilotSchema.statics.getFirstOnboarded = function() {
return Pilot.findOne({ stripeAccountId: { $ne: null } })
.sort({ created: 1 })
.exec();
};

// Get the latest fully onboarded pilot.
PilotSchema.statics.getLatestOnboarded = function() {
return Pilot.findOne({ stripeAccountId: { $ne: null } })
.sort({ created: -1 })
.exec();
};
Expand Down
4 changes: 2 additions & 2 deletions server/routes/api/rides.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ router.post('/', async (req, res, next) => {

try {
// For the purpose of this demo, let's assume we are automatically
// matching with the most recent pilot rather than using their location.
const pilot = await Pilot.getLatest();
// matching with the first fully onboarded pilot rather than using their location.
const pilot = await Pilot.getFirstOnboarded();
// Find the latest passenger (see note above).
const passenger = await Passenger.getLatest();
// Create a new ride.
Expand Down

0 comments on commit 4fc3790

Please sign in to comment.