Fixing getting all court statuses

This commit is contained in:
Collin Duncan 2024-03-18 17:16:50 +01:00
parent 91520e01f1
commit c47cfbd55d
No known key found for this signature in database

View file

@ -580,21 +580,23 @@ export class BaanReserverenService {
duration: string duration: string
}[] = [] }[] = []
for (const court of courts) { for (const court of courts) {
const courtJsonValue = await court.jsonValue() const classListObj = await (
const courtParent = courtJsonValue.parentElement await court.getProperty('classList')
const startTime = dayjs( ).jsonValue()
Number(courtParent?.getAttribute('utc') ?? 0), const classList = Object.values(classListObj)
).toISOString() const rClass = classList.filter((cl) => /r-\d{2}/.test(cl))[0]
const status = courtJsonValue.getAttribute('type') ?? 'closed'
const courtSlot = courtJsonValue.getAttribute('slot')
const courtNumber = const courtNumber =
courtSlot != null `${CourtSlotToNumber[rClass.replace(/r-/, '') as CourtSlot]}` ??
? `${CourtSlotToNumber[courtSlot as CourtSlot]}` 'unknown court'
: 'unknown' const startTime = await court
const duration = `${ .$eval('div.slot-period', (e) => e.innerText.trim())
Number(courtJsonValue.getAttribute('rowspan') ?? '0') * 15 .catch(() => 'unknown')
} minutes` const status = classList.includes('free') ? 'available' : 'unavailable'
courtStatuses.push({ courtNumber, startTime, status, duration }) const courtRowSpan = await (
await court.getProperty('rowSpan')
).jsonValue()
const duration = `${Number(courtRowSpan ?? '0') * 15} minutes`
courtStatuses.push({ courtNumber, startTime, status, duration }) //const d = require('dayjs'); await get(BaanReserverenService).monitorCourtReservations(d());
} }
return courtStatuses return courtStatuses
@ -612,9 +614,9 @@ export class BaanReserverenService {
data: statuses, data: statuses,
}) })
} catch (error: unknown) { } catch (error: unknown) {
this.loggerService.error('Failed to monitor court reservations', { this.loggerService.error(
error, `Failed to monitor court reservations: ${(error as Error).message}`,
}) )
if (!swallowError) { if (!swallowError) {
throw error throw error
} }