Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Commit

Permalink
Changing default createdAtStart to 28 days, Fixes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
seripap committed Oct 4, 2017
1 parent 8afb65c commit 6e83425
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,9 @@ __Arguments__

```javascript
const now = new Date();
const minus3Hours = new Date(new Date() * 1 - 1000 * 3600 * 3);
const minus28days = new Date();

minus28Days.setDate(now.getDate() - 28);

/* defaults */
const options = {
Expand All @@ -247,7 +249,7 @@ const options = {
},
sort: 'createdAt', // -createdAt for reverse
filter: {
'createdAt-start': minus3Hours.toISOString(), // ISO Date
'createdAt-start': minus28days.toISOString(), // ISO Date
'createdAt-end': now.toISOString(), // ISO Date
playerNames: [],
teamNames: [],
Expand Down
19 changes: 10 additions & 9 deletions src/Http.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,24 +79,25 @@ export default class Http {
return queries.join('&');
}

parseErrors(status, requestOptions, rateLimit) {
parseErrors(res, requestOptions, rateLimit) {
const { status } = res;
const err = { errors: true };
const region = this.getRequestedRegion();
switch (status) {
case 401:
return { ...err, messages: UNAUTHORIZED, region, debug: requestOptions, rateLimit };
return { ...err, messages: UNAUTHORIZED, region, debug: requestOptions, rateLimit, ...res };
case 404:
return { ...err, messages: NOT_FOUND, region, debug: requestOptions, rateLimit };
return { ...err, messages: NOT_FOUND, region, debug: requestOptions, rateLimit, ...res };
case 500:
return { ...err, messages: INTERNAL, region, debug: requestOptions, rateLimit };
return { ...err, messages: INTERNAL, region, debug: requestOptions, rateLimit, ...res };
case 429:
return { ...err, messages: RATE_LIMIT, region, debug: requestOptions, rateLimit };
return { ...err, messages: RATE_LIMIT, region, debug: requestOptions, rateLimit, ...res };
case 503:
return { ...err, messages: OFFLINE, region, debug: requestOptions, rateLimit };
return { ...err, messages: OFFLINE, region, debug: requestOptions, rateLimit, ...res };
case 406:
return { ...err, messages: NOT_ACCEPTABLE, region, debug: requestOptions, rateLimit };
return { ...err, messages: NOT_ACCEPTABLE, region, debug: requestOptions, rateLimit, ...res };
default:
return { ...err, messages: UNKNOWN, region, debug: requestOptions, rateLimit };
return { ...err, messages: UNKNOWN, region, debug: requestOptions, rateLimit, ...res };
}
}

Expand Down Expand Up @@ -138,7 +139,7 @@ export default class Http {
}).then((res) => {
rateLimit = this.parseRateLimit(res.headers);
if (res.status !== 200) {
return this.parseErrors(res.status, requestOptions, rateLimit);
return this.parseErrors(res, requestOptions, rateLimit);
}
return res.json();
}).then((body) => {
Expand Down
6 changes: 4 additions & 2 deletions src/api/matches/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@ export default (http) => {

async function collection(collectionOptions = {}) {
const now = new Date();
const minus3Hours = new Date(new Date() * 1 - 1000 * 3600 * 3);
const minus28Days = new Date();

minus28Days.setDate(now.getDate() - 28);

const defaults = {
page: { offset: 0, limit: 50 },
sort: 'createdAt',
filter: { 'createdAt-start': minus3Hours.toISOString(), 'createdAt-end': now.toISOString(), playerNames: [], teamNames: [] },
filter: { 'createdAt-start': minus28Days.toISOString(), 'createdAt-end': now.toISOString(), playerNames: [], teamNames: [] },
};

const query = { ...defaults, ...collectionOptions };
Expand Down

0 comments on commit 6e83425

Please sign in to comment.