Skip to content

Commit 1b8b6bb

Browse files
authored
fix: APPS-3122 Rearrange ongoing events to be after the current events on eventSeries Listing page (#96)
* combine current and ongoing series * delete extraneaous code * delete extraneaous code * linting
1 parent 9e9e427 commit 1b8b6bb

File tree

2 files changed

+83
-10
lines changed

2 files changed

+83
-10
lines changed

composables/useEventSeriesListSearchFilter.js

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// TODO Convert this composable into TypeScript
22

33
export default function useEventSeriesListSearchFilter() {
4-
return { pastEventSeriesQuery, currentEventSeriesQuery }
4+
return { pastEventSeriesQuery, currentEventSeriesQueryCurrent, currentEventSeriesQueryOngoing }
55
}
66

77
async function pastEventSeriesQuery(
@@ -58,7 +58,7 @@ async function pastEventSeriesQuery(
5858
return data
5959
}
6060

61-
async function currentEventSeriesQuery(
61+
async function currentEventSeriesQueryCurrent(
6262
currentPage = 1,
6363
documentsPerPage = 10,
6464
sort,
@@ -97,7 +97,7 @@ async function currentEventSeriesQuery(
9797
should: [
9898
{
9999
term: {
100-
ongoing: true,
100+
ongoing: false,
101101
},
102102
},
103103
{
@@ -108,7 +108,59 @@ async function currentEventSeriesQuery(
108108
},
109109
},
110110
],
111-
minimum_should_match: 1,
111+
minimum_should_match: 2,
112+
}
113+
},
114+
...parseSort(sort, orderBy),
115+
}),
116+
}
117+
)
118+
119+
const data = await response.json()
120+
return data
121+
}
122+
123+
async function currentEventSeriesQueryOngoing(
124+
currentPage = 1,
125+
documentsPerPage = 10,
126+
sort,
127+
orderBy,
128+
source = ['*'],
129+
) {
130+
const config = useRuntimeConfig()
131+
if (
132+
config.public.esReadKey === '' ||
133+
config.public.esURL === '' ||
134+
config.public.esAlias === ''
135+
)
136+
return
137+
138+
const response = await fetch(
139+
`${config.public.esURL}/${config.public.esAlias}/_search`,
140+
{
141+
headers: {
142+
Authorization: `ApiKey ${config.public.esReadKey}`,
143+
'Content-Type': 'application/json',
144+
},
145+
method: 'POST',
146+
body: JSON.stringify({
147+
from: (currentPage - 1) * documentsPerPage,
148+
size: documentsPerPage,
149+
_source: [...source],
150+
query: {
151+
bool: {
152+
filter: [
153+
{
154+
term: {
155+
'sectionHandle.keyword': 'ftvaEventSeries',
156+
},
157+
},
158+
{
159+
term: {
160+
ongoing: true,
161+
},
162+
}
163+
]
112164
}
113165
},
114166
...parseSort(sort, orderBy),

pages/series/index.vue

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,38 @@ async function searchES() {
137137
138138
isLoading.value = true
139139
// COMPOSABLE
140-
const { currentEventSeriesQuery, pastEventSeriesQuery } = useEventSeriesListSearchFilter()
140+
const { currentEventSeriesQueryCurrent, currentEventSeriesQueryOngoing, pastEventSeriesQuery } = useEventSeriesListSearchFilter()
141141
142142
try {
143143
let results
144144
145145
if (currentView.value === 'current') {
146-
results = await currentEventSeriesQuery(currentPage.value,
147-
documentsPerPage,
148-
'startDate',
149-
'asc',
150-
['*'],)
146+
const [currentSeriesResult, ongoingSeriesResult] = await Promise.all([
147+
currentEventSeriesQueryCurrent(
148+
currentPage.value,
149+
documentsPerPage,
150+
'startDate',
151+
'asc',
152+
['*']
153+
),
154+
currentEventSeriesQueryOngoing(
155+
currentPage.value,
156+
documentsPerPage,
157+
'startDate',
158+
'asc',
159+
['*']
160+
)
161+
])
162+
163+
// Combine results with current series first, ongoing series last
164+
const currentSeries = currentSeriesResult?.hits?.hits || []
165+
const ongoingSeries = ongoingSeriesResult?.hits?.hits || []
166+
results = {
167+
hits: {
168+
hits: [...currentSeries, ...ongoingSeries],
169+
total: { value: currentSeries.length + ongoingSeries.length },
170+
},
171+
}
151172
} else {
152173
results = await pastEventSeriesQuery(currentPage.value,
153174
documentsPerPage,

0 commit comments

Comments
 (0)