@@ -116,31 +116,6 @@ const saveDataToJson = (data: any, filePath: string) => {
116
116
fs . writeFileSync ( filePath , JSON . stringify ( data , null , 2 ) ) ;
117
117
} ;
118
118
119
- /**
120
- * The function returns the nearest upcoming event,
121
- * but if there are no upcoming events, it returns the last past event
122
- */
123
- const findNearestEvent = ( events : TimepadEvent [ ] ) : TimepadEvent | undefined => {
124
- const now = new Date ( ) . toISOString ( ) ;
125
-
126
- const pastEvents = events . filter ( ( event ) => event . starts_at < now ) ;
127
-
128
- if ( pastEvents . length > 0 ) {
129
- const lastPastEvent = pastEvents [ pastEvents . length - 1 ] ;
130
- return lastPastEvent ;
131
- }
132
-
133
- const futureEvents = events
134
- . filter ( ( event ) => event . starts_at >= now )
135
- . sort ( ( a , b ) => a . starts_at . localeCompare ( b . starts_at ) ) ;
136
-
137
- if ( futureEvents . length > 0 ) {
138
- return futureEvents [ 0 ] ;
139
- }
140
-
141
- return undefined ;
142
- } ;
143
-
144
119
/** Fetches a list of events from timepad, saves the list to temp json file and returns the list */
145
120
export const getMeetupList = async ( ) => {
146
121
try {
@@ -167,7 +142,7 @@ export const getMeetupList = async () => {
167
142
}
168
143
169
144
try {
170
- return await fetch ( `https://api.timepad.ru/v1/events?starts_at_min=2023-05-31 &organization_ids=${ timepadId } ` , {
145
+ return await fetch ( `https://api.timepad.ru/v1/events?starts_at_min=2023-05-01 &organization_ids=${ timepadId } ` , {
171
146
headers : {
172
147
Authorization : `Bearer ${ process . env . TIMEPAD_TOKEN } ` ,
173
148
} ,
@@ -179,7 +154,7 @@ export const getMeetupList = async () => {
179
154
throw new Error ( 'Wrong received data from timepad' ) ;
180
155
}
181
156
182
- const eventsSummaryList = data . values . filter ( ( item : any ) => item . moderation_status === 'shown' ) ;
157
+ const eventsSummaryList = data . values ; // .filter((item: any) => item.moderation_status === 'shown');
183
158
const eventsDetailList : TimepadEvent [ ] = [ ] ;
184
159
185
160
for ( let i = 0 ; i < eventsSummaryList . length ; i ++ ) {
@@ -214,6 +189,30 @@ export const getMeetupList = async () => {
214
189
}
215
190
} ;
216
191
192
+ /**
193
+ * The function returns the nearest upcoming event,
194
+ * but if there are no upcoming events, it returns the last past event
195
+ */
196
+ const findNearestEvent = ( events : TimepadEvent [ ] ) : TimepadEvent | undefined => {
197
+ const now = new Date ( ) ;
198
+
199
+ const futureEvents = events
200
+ . filter ( ( event ) => new Date ( event . starts_at ) >= now )
201
+ . sort ( ( a , b ) => a . starts_at . localeCompare ( b . starts_at ) ) ;
202
+
203
+ if ( futureEvents . length > 0 ) {
204
+ return futureEvents [ 0 ] ;
205
+ }
206
+
207
+ const pastEvents = events . filter ( ( event ) => new Date ( event . starts_at ) < now ) ;
208
+
209
+ if ( pastEvents . length > 0 ) {
210
+ return pastEvents [ pastEvents . length - 1 ] ;
211
+ }
212
+
213
+ return undefined ;
214
+ } ;
215
+
217
216
export const getLastMeetup = async (
218
217
eventsList : TimepadEvent [ ]
219
218
) : Promise < {
0 commit comments