Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pof data fetch to work with Strapi v4 #131

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 24 additions & 17 deletions src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,67 @@
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
return ageGroups.data
}

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
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?populate=*&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}&populate=*`
)
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 res = await fetch(`${PARTIO_API_URL}/activity-groups/${id}?populate=*`)
const activityGroup = await res.json()
return activityGroup
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
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
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?populate=*&locale=${lang}`
)
const translations = await res.json()
console.log(translations)
return translations.data.translations
}

// POS BACKEND
Expand Down
Loading