Skip to content

Instantly share code, notes, and snippets.

@Pyrolistical
Last active October 9, 2021 20:56
Show Gist options
  • Save Pyrolistical/c82d97456bab978bc3f2ad950f5e48d9 to your computer and use it in GitHub Desktop.
Save Pyrolistical/c82d97456bab978bc3f2ad950f5e48d9 to your computer and use it in GitHub Desktop.
separate business layer from infrastructure layer before service.js
export default (db) => {
return {
async checkIn(teamID) {
const disqualifiedPlayers = await db.collection('playerDisqualifications').find({
teamID
})
.toArray();
if (disqualifiedPlayers.length > 0) {
throw new Error('cannot check-in with disqualified players');
}
return db.collection('checkIns').insert({
teamID,
checkedInAt: new Date()
});
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment