2022-01-09 12:11:24 +01:00
|
|
|
import SessionCache from './session-cache.js'
|
2021-04-04 18:03:05 +02:00
|
|
|
import { request } from 'graphql-request'
|
2022-01-09 12:11:24 +01:00
|
|
|
import DateTimeWrapper from './date-time-wrapper.js'
|
2021-01-08 14:08:40 +01:00
|
|
|
|
2021-01-15 20:30:05 +01:00
|
|
|
export function getUpcomingEvents({ url, limit }) {
|
2021-04-04 18:03:05 +02:00
|
|
|
const query = `
|
|
|
|
query ($limit: Int) {
|
|
|
|
events(limit: $limit) {
|
2021-01-15 20:30:05 +01:00
|
|
|
elements {
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
url,
|
|
|
|
beginsOn,
|
2021-04-11 22:42:50 +02:00
|
|
|
endsOn,
|
|
|
|
physicalAddress {
|
|
|
|
description,
|
|
|
|
locality
|
|
|
|
}
|
2021-01-15 20:30:05 +01:00
|
|
|
},
|
|
|
|
total
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
2021-12-09 19:46:19 +01:00
|
|
|
const dataInCache = SessionCache.get(sessionStorage, {
|
|
|
|
url,
|
|
|
|
query,
|
|
|
|
variables: { limit },
|
|
|
|
})
|
|
|
|
if (dataInCache !== null) {
|
2021-04-04 18:03:05 +02:00
|
|
|
return Promise.resolve(dataInCache)
|
2021-12-09 19:46:19 +01:00
|
|
|
}
|
|
|
|
return request(url, query, { limit }).then((data) => {
|
|
|
|
SessionCache.add(sessionStorage, { url, query, variables: { limit } }, data)
|
|
|
|
return Promise.resolve(data)
|
|
|
|
})
|
2021-04-04 18:03:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export function getUpcomingEventsByGroupName({ url, limit, groupName }) {
|
|
|
|
const query = `
|
2022-05-19 08:08:21 +02:00
|
|
|
query ($afterDatetime: DateTime, $groupName: String!, $limit: Int) {
|
2021-04-04 18:03:05 +02:00
|
|
|
group(preferredUsername: $groupName) {
|
|
|
|
organizedEvents(afterDatetime: $afterDatetime, limit: $limit) {
|
|
|
|
elements {
|
|
|
|
id,
|
|
|
|
title,
|
|
|
|
url,
|
|
|
|
beginsOn,
|
2021-04-11 22:42:50 +02:00
|
|
|
endsOn,
|
|
|
|
physicalAddress {
|
|
|
|
description,
|
|
|
|
locality
|
|
|
|
}
|
2021-04-04 18:03:05 +02:00
|
|
|
},
|
|
|
|
total
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`
|
|
|
|
const afterDatetime = DateTimeWrapper.getCurrentDatetimeAsString()
|
2021-12-09 19:46:19 +01:00
|
|
|
const dataInCache = SessionCache.get(sessionStorage, {
|
|
|
|
url,
|
|
|
|
query,
|
|
|
|
variables: { afterDatetime, groupName, limit },
|
|
|
|
})
|
|
|
|
if (dataInCache !== null) {
|
2021-04-04 18:03:05 +02:00
|
|
|
return Promise.resolve(dataInCache)
|
2021-12-09 19:46:19 +01:00
|
|
|
}
|
|
|
|
return request(url, query, { afterDatetime, groupName, limit }).then(
|
|
|
|
(data) => {
|
|
|
|
SessionCache.add(
|
|
|
|
sessionStorage,
|
|
|
|
{ url, query, variables: { afterDatetime, groupName, limit } },
|
2023-11-11 20:28:16 +01:00
|
|
|
data,
|
2021-12-09 19:46:19 +01:00
|
|
|
)
|
2021-04-04 18:03:05 +02:00
|
|
|
return Promise.resolve(data)
|
2023-11-11 20:28:16 +01:00
|
|
|
},
|
2021-12-09 19:46:19 +01:00
|
|
|
)
|
2021-01-15 20:30:05 +01:00
|
|
|
}
|