1.0.0 • Published 2 years ago
scoreboard-lib v1.0.0
scoreboard-lib
Example Node.js library for handling Scoreboard's games. It offers 4 different operations:
- start : starts a game by passing home and away teams & returns gameId. Sets a score to 0 - 0
- update : update a game score by passing gameId and actual score
- finish : finish a game by passing gameId. Game is removed from storage
- getAllGames : returns all ongoing games orderd by score and game's start time
how to use the library
Scoreboard library is a npm module which can be installed locally
npm i scoreboard-lib
If you have a typescript project this is an example usage
import {
GameRepositoryImpl,
GameRepository,
ScoreBoardImpl,
ScoreBoard,
Team,
TeamType
} from 'scoreboard-lib';
const repo: GameRepository = new GameRepositoryImpl();
const scoreboard: ScoreBoard = new ScoreBoardImpl(repo);
const firstTeamHome: Team = { city: "xxx", name: 'Manchester', type: TeamType.HOME};
const firstTeamAway: Team = { city: "yyy", name: 'Liverpool', type: TeamType.AWAY};
const firstGameId: string = scoreboard.start(firstTeamHome, firstTeamAway);
scoreboard.update(firstGameId,7,0);
const secondTeamHome: Team = { city: "xxx", name: 'Barcelona', type: TeamType.HOME};
const secondTeamAway: Team = { city: "yyy", name: 'Real', type: TeamType.AWAY};
const secondGameId: string = scoreboard.start(secondTeamHome, secondTeamAway);
scoreboard.update(secondGameId,3,1);
scoreboard.getAllGames().map( game => {
console.log(`${game}`);
});
Generally to use a scoreboard-lib module you need to create a game repository first
const repo: GameRepository = new GameRepositoryImpl();
and create a score board passing the game repository to the constructor
const scoreboard: ScoreBoard = new ScoreBoardImpl(repo);
The intention of game repositpory is to create a data layer allowing different storage types in future.
unit testing
To run unit tests locally please download the git project
git clone git@github.com:lkorzeniowski/scoreboard-library.git
and run commands
npm install
npm test
1.0.0
2 years ago