From 6e834251b6ff022d10a77079ab2029c86bbd18d0 Mon Sep 17 00:00:00 2001 From: Daniel Seripap Date: Wed, 4 Oct 2017 09:06:06 -0400 Subject: [PATCH] Changing default createdAtStart to 28 days, Fixes #18 --- README.md | 6 ++++-- src/Http.js | 19 ++++++++++--------- src/api/matches/index.js | 6 ++++-- 3 files changed, 18 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 59750f1..7055adb 100644 --- a/README.md +++ b/README.md @@ -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 = { @@ -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: [], diff --git a/src/Http.js b/src/Http.js index ec0dfe1..51bc981 100644 --- a/src/Http.js +++ b/src/Http.js @@ -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 }; } } @@ -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) => { diff --git a/src/api/matches/index.js b/src/api/matches/index.js index b8bc6cf..cd0ec51 100644 --- a/src/api/matches/index.js +++ b/src/api/matches/index.js @@ -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 };