Skip to content

Instantly share code, notes, and snippets.

@Pyrolistical
Last active October 9, 2021 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pyrolistical/bf337eacb2e7d7a1755148f74350e340 to your computer and use it in GitHub Desktop.
Save Pyrolistical/bf337eacb2e7d7a1755148f74350e340 to your computer and use it in GitHub Desktop.
separate business layer from infrastructure layer after
export default (db) => {
return {
async findDisqualifiedPlayers(teamID) {
return db.collection('playerDisqualifications').find({
teamID
})
.toArray();
},
async checkInTeam(teamID) {
return db.collection('checkIns').insert({
teamID,
checkedInAt: new Date()
});
}
};
};
export default (repository) => {
return {
async checkIn(teamID) {
const disqualifiedPlayers = await repository.findDisqualifiedPlayers(teamID);
if (disqualifiedPlayers.length > 0) {
throw new Error('cannot check-in with disqualified players');
}
return repository.checkinTeam(teamID);
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment