From b50a3218abc5ad810fe3276b78b98003db5dc0f9 Mon Sep 17 00:00:00 2001 From: Paula Rinta-Harri Date: Fri, 24 Nov 2023 20:08:29 +0200 Subject: [PATCH 1/3] Fix Pof api calls to work with Strapi v4 --- src/api/index.js | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 7b6d3e4..f202f91 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -2,60 +2,62 @@ import { PARTIO_API_URL } from './variables' export const fetchAgeGroups = async (language) => { - const res = await fetch(`${PARTIO_API_URL}/age-groups?_locale=${language}`) + const res = await fetch(`${PARTIO_API_URL}/age-groups?locale=${language}`) const ageGroups = await res.json() - return ageGroups + return ageGroups.data } export const fetchSingleAgeGroup = async (id) => { const res = await fetch(`${PARTIO_API_URL}/age-groups/${id}`) const ageGroup = await res.json() - return ageGroup + return ageGroup.data } export const fetchActivityGroups = async (language) => { const locale = language === undefined ? 'fi' : language const countRes = await fetch( - `${PARTIO_API_URL}/activity-groups/count?_locale=${locale}` + `${PARTIO_API_URL}/activity-groups?locale=${locale}` ) const count = await countRes.json() const res = await fetch( - `${PARTIO_API_URL}/activity-groups?_limit=${count}&_locale=${locale}` + `${PARTIO_API_URL}/activity-groups?pagination[start]=0&pagination[limit]=${count.meta.pagination.total}&locale=${locale}` ) const activityGroups = await res.json() - return activityGroups + return activityGroups.data } export const fetchSingleActivityGroup = async (id) => { const res = await fetch(`${PARTIO_API_URL}/activity-groups/${id}`) const activityGroup = await res.json() - return activityGroup + return activityGroup.data } export const fetchActivities = async () => { const res = await fetch(`${PARTIO_API_URL}/activities`) const activities = await res.json() - return activities + return activities.data } export const fetchActivity = async (wp_guid, language) => { const res = await fetch( - `${PARTIO_API_URL}/activities?wp_guid=${wp_guid}&_locale=${language}` + `${PARTIO_API_URL}/activities?wp_guid=${wp_guid}&locale=${language}` ) const activity = await res.json() - return activity + return activity.data } export const fetchTaskDetails = async (guid, lang) => { const res = await fetch( - `https://pof-backend.partio.fi/item-json/?postGUID=${guid}&lang=${lang}` + `https://pof-backend.partio.fi/api/item-json/?postGUID=${guid}&lang=${lang}` ) - return await res.json() + const task = await res.json() + return task.data } export const fetchTranslations = async (lang) => { - const res = await fetch(`${PARTIO_API_URL}/settings/translations/${lang}`) - return await res.json() + const res = await await fetch(`${PARTIO_API_URL}/setting?locale=${lang}`) + const translations = await res.json() + return translations.data } // POS BACKEND From 809b1201cc42828584e1a88c6c0746c98b4e8ed0 Mon Sep 17 00:00:00 2001 From: Paula Rinta-Harri Date: Fri, 24 Nov 2023 20:20:00 +0200 Subject: [PATCH 2/3] Populate fetchAgeGroups --- src/api/index.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/api/index.js b/src/api/index.js index f202f91..1a010f7 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -2,7 +2,9 @@ import { PARTIO_API_URL } from './variables' export const fetchAgeGroups = async (language) => { - const res = await fetch(`${PARTIO_API_URL}/age-groups?locale=${language}`) + const res = await fetch( + `${PARTIO_API_URL}/age-groups?populate=*&locale=${language}` + ) const ageGroups = await res.json() return ageGroups.data } From ca5819faee90baa1cc889012094b3530e3c33f73 Mon Sep 17 00:00:00 2001 From: Paula Rinta-Harri Date: Fri, 24 Nov 2023 20:50:59 +0200 Subject: [PATCH 3/3] Populate all api calls --- src/api/index.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/api/index.js b/src/api/index.js index 1a010f7..7a15115 100644 --- a/src/api/index.js +++ b/src/api/index.js @@ -10,7 +10,7 @@ export const fetchAgeGroups = async (language) => { } export const fetchSingleAgeGroup = async (id) => { - const res = await fetch(`${PARTIO_API_URL}/age-groups/${id}`) + const res = await fetch(`${PARTIO_API_URL}/age-groups/${id}?populate=*`) const ageGroup = await res.json() return ageGroup.data } @@ -18,31 +18,31 @@ export const fetchSingleAgeGroup = async (id) => { export const fetchActivityGroups = async (language) => { const locale = language === undefined ? 'fi' : language const countRes = await fetch( - `${PARTIO_API_URL}/activity-groups?locale=${locale}` + `${PARTIO_API_URL}/activity-groups?populate=*&locale=${locale}` ) const count = await countRes.json() const res = await fetch( - `${PARTIO_API_URL}/activity-groups?pagination[start]=0&pagination[limit]=${count.meta.pagination.total}&locale=${locale}` + `${PARTIO_API_URL}/activity-groups?pagination[start]=0&pagination[limit]=${count.meta.pagination.total}&locale=${locale}&populate=*` ) const activityGroups = await res.json() return activityGroups.data } export const fetchSingleActivityGroup = async (id) => { - const res = await fetch(`${PARTIO_API_URL}/activity-groups/${id}`) + const res = await fetch(`${PARTIO_API_URL}/activity-groups/${id}?populate=*`) const activityGroup = await res.json() return activityGroup.data } export const fetchActivities = async () => { - const res = await fetch(`${PARTIO_API_URL}/activities`) + const res = await fetch(`${PARTIO_API_URL}/activities?populate=*`) const activities = await res.json() return activities.data } export const fetchActivity = async (wp_guid, language) => { const res = await fetch( - `${PARTIO_API_URL}/activities?wp_guid=${wp_guid}&locale=${language}` + `${PARTIO_API_URL}/activities?populate=*&wp_guid=${wp_guid}&locale=${language}` ) const activity = await res.json() return activity.data @@ -57,9 +57,12 @@ export const fetchTaskDetails = async (guid, lang) => { } export const fetchTranslations = async (lang) => { - const res = await await fetch(`${PARTIO_API_URL}/setting?locale=${lang}`) + const res = await await fetch( + `${PARTIO_API_URL}/setting?populate=*&locale=${lang}` + ) const translations = await res.json() - return translations.data + console.log(translations) + return translations.data.translations } // POS BACKEND