From f14d5a1dbfd47a3d9055dea051e6f7059bbddceb Mon Sep 17 00:00:00 2001 From: Sam Date: Fri, 18 Jan 2019 19:34:38 +0100 Subject: [PATCH 1/3] refactor --- fittrackee_client/src/actions/index.js | 4 +-- fittrackee_client/src/fitTrackeeApi/index.js | 29 ++++++++++---------- fittrackee_client/src/fitTrackeeApi/user.js | 10 +++---- fittrackee_client/src/utils.js | 9 ++++-- 4 files changed, 27 insertions(+), 25 deletions(-) diff --git a/fittrackee_client/src/actions/index.js b/fittrackee_client/src/actions/index.js index de4579f2..132536ec 100644 --- a/fittrackee_client/src/actions/index.js +++ b/fittrackee_client/src/actions/index.js @@ -27,7 +27,7 @@ export const getOrUpdateData = (action, target, data) => dispatch => { if (ret.status === 'success') { dispatch(setData(target, ret.data)) } else { - dispatch(setError(`${target}: ${ret.message}`)) + dispatch(setError(`${target}: ${ret.message || ret.status}`)) } }) .catch(error => dispatch(setError(`${target}: ${error}`))) @@ -54,7 +54,7 @@ export const deleteData = (target, id) => dispatch => { if (ret.status === 204) { history.push(`/admin/${target}`) } else { - dispatch(setError(`${target}: ${ret.message}`)) + dispatch(setError(`${target}: ${ret.message || ret.status}`)) } }) .catch(error => dispatch(setError(`${target}: ${error}`))) diff --git a/fittrackee_client/src/fitTrackeeApi/index.js b/fittrackee_client/src/fitTrackeeApi/index.js index be5bcef1..d6a90674 100644 --- a/fittrackee_client/src/fitTrackeeApi/index.js +++ b/fittrackee_client/src/fitTrackeeApi/index.js @@ -1,10 +1,9 @@ -import { apiUrl, createRequest } from '../utils' +import { createApiRequest } from '../utils' export default class FitTrackeeApi { - static getData(target, - data = {}) { - let url = `${apiUrl}${target}` + static getData(target, data = {}) { + let url = target if (data.id) { url = `${url}/${data.id}` } else if (Object.keys(data).length > 0) { @@ -16,54 +15,54 @@ export default class FitTrackeeApi { method: 'GET', type: 'application/json', } - return createRequest(params) + return createApiRequest(params) } static addData(target, data) { const params = { - url: `${apiUrl}${target}`, + url: target, method: 'POST', body: data, type: 'application/json', } - return createRequest(params) + return createApiRequest(params) } static addDataWithFile(target, data) { const params = { - url: `${apiUrl}${target}`, + url: target, method: 'POST', body: data, } - return createRequest(params) + return createApiRequest(params) } static postData(target, data) { const params = { - url: `${apiUrl}${target}${data.id ? `/${data.id}` : '' }`, + url: `${target}${data.id ? `/${data.id}` : '' }`, method: 'POST', body: data, type: 'application/json', } - return createRequest(params) + return createApiRequest(params) } static updateData(target, data) { const params = { - url: `${apiUrl}${target}/${data.id}`, + url: `${target}/${data.id}`, method: 'PATCH', body: data, type: 'application/json', } - return createRequest(params) + return createApiRequest(params) } static deleteData(target, id) { const params = { - url: `${apiUrl}${target}/${id}`, + url: `${target}/${id}`, method: 'DELETE', type: 'application/json', } - return createRequest(params) + return createApiRequest(params) } } diff --git a/fittrackee_client/src/fitTrackeeApi/user.js b/fittrackee_client/src/fitTrackeeApi/user.js index c589465d..3cadf81c 100644 --- a/fittrackee_client/src/fitTrackeeApi/user.js +++ b/fittrackee_client/src/fitTrackeeApi/user.js @@ -1,23 +1,23 @@ -import { apiUrl, createRequest } from '../utils' +import { createApiRequest } from '../utils' export default class FitTrackeeApi { static loginOrRegister(target, data) { const params = { - url: `${apiUrl}auth/${target}`, + url: `auth/${target}`, method: 'POST', noAuthorization: true, body: data, type: 'application/json', } - return createRequest(params) + return createApiRequest(params) } static deletePicture() { const params = { - url: `${apiUrl}auth/picture`, + url: 'auth/picture', method: 'DELETE', } - return createRequest(params) + return createApiRequest(params) } } diff --git a/fittrackee_client/src/utils.js b/fittrackee_client/src/utils.js index d67a0d5a..dfd19df8 100644 --- a/fittrackee_client/src/utils.js +++ b/fittrackee_client/src/utils.js @@ -30,7 +30,7 @@ export const generateIds = arr => { } -export const createRequest = params => { +export const createApiRequest = params => { const headers = {} if (!params.noAuthorization) { headers.Authorization = `Bearer ${ @@ -48,12 +48,15 @@ export const createRequest = params => { } else if (params.body) { requestParams.body = params.body } - const request = new Request(params.url, requestParams) + const request = new Request(`${apiUrl}${params.url}`, requestParams) return fetch(request) .then(response => params.method === 'DELETE' ? response : response.json()) - .catch(error => error) + .catch(error => { + console.error(error) + return new Error('An error occurred. Please contact the administrator.') + }) } From 44fea47a5dfb2c52c96849317ef69dd5faba6a6a Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 13 Jan 2019 13:01:09 +0100 Subject: [PATCH 2/3] Revert "update ci config" This reverts commit 8fa693695b0ba8499e5cafcaa861b63a07890f44. => back to trusty --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 5e24351c..c7e540ea 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ language: node_js node_js: '11' -dist: xenial +dist: trusty sudo: required addons: From 432874294a9151ea02b4a3e5835e4e42936cd211 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 6 Feb 2019 23:26:37 +0100 Subject: [PATCH 3/3] [skip travis] update CHANGELOG.md --- CHANGELOG.md | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ae87c606..9f46e983 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,22 +1,24 @@ # Change log -## Version 0.1.1 - Fix and improvements (2019/01/xx) +## Version 0.1.1 - Fix and improvements (2019/02/07) ### Issues Closed -#### Bugs Fixed - -* [#31](https://github.com/SamR1/FitTrackee/issues/31) - Use moving duration for stats -* [#29](https://github.com/SamR1/FitTrackee/issues/29) - Pause duration calculation with segments -* [#26](https://github.com/SamR1/FitTrackee/issues/26) - Total is incorrect in tooltip when duration is displayed -* [#24](https://github.com/SamR1/FitTrackee/issues/24) - Some distances are not displayed correctly on current month statistics - #### New Features * [#25](https://github.com/SamR1/FitTrackee/issues/25) - Display records on calendar * [#22](https://github.com/SamR1/FitTrackee/issues/22) - Add a total on current month statistics -In this release 6 issues were closed. +#### Bugs Fixed + +* [#31](https://github.com/SamR1/FitTrackee/issues/31) - Use moving duration for stats +* [#29](https://github.com/SamR1/FitTrackee/issues/29) - Pause duration calculation with segments +* [#28](https://github.com/SamR1/FitTrackee/issues/28) - Error on uploading gpx file +* [#26](https://github.com/SamR1/FitTrackee/issues/26) - Total is incorrect in tooltip when duration is displayed +* [#24](https://github.com/SamR1/FitTrackee/issues/24) - Some distances are not displayed correctly on current month statistics + + +In this release 7 issues were closed. ## Version 0.1 - Minimal version (2018-07-04)