Skip to content

Commit

Permalink
add error message for no games available on given date
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Adams committed Nov 15, 2018
1 parent f8951c4 commit 5e08a5d
Showing 1 changed file with 25 additions and 5 deletions.
30 changes: 25 additions & 5 deletions src/command/game/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ const getLosAngelesTimezone = date =>
.format();

const getSeason = date => {
const year = R.compose(getYear, parse)(date);
const month = R.compose(getMonth, parse)(date);
const year = R.compose(
getYear,
parse
)(date);
const month = R.compose(
getMonth,
parse
)(date);

if (year < 2012 || (year === 2012 && month < 5)) {
error(
Expand Down Expand Up @@ -88,7 +94,12 @@ const game = async option => {
let seasonMetaData;

if (option.date) {
if (R.compose(isValid, parse)(option.date)) {
if (
R.compose(
isValid,
parse
)(option.date)
) {
_date = format(option.date, 'YYYY-MM-DD');
} else {
error('Date is invalid');
Expand All @@ -104,15 +115,24 @@ const game = async option => {
error(`Can't find any option ${emoji.get('confused')}`);
process.exit(1);
}
R.compose(cfontsDate, getSeason)(_date);
R.compose(
cfontsDate,
getSeason
)(_date);

const LADate = getLosAngelesTimezone(_date);

try {
const {
sports_content: { games: { game: _gamesData } },
sports_content: {
games: { game: _gamesData },
},
} = await NBA.getGamesFromDate(LADate);
gamesData = _gamesData;
if (!gamesData.length) {
error('No game available on this date.');
process.exit(1);
}
} catch (err) {
catchAPIError(err, 'NBA.getGamesFromDate()');
}
Expand Down

0 comments on commit 5e08a5d

Please sign in to comment.