41 lines
970 B
TypeScript
41 lines
970 B
TypeScript
import { etjanst } from './etjanst'
|
|
import { ScheduleItem } from '../types'
|
|
import { parseDate } from '../utils/dateHandling'
|
|
|
|
export const scheduleItem = ({
|
|
title,
|
|
description,
|
|
location,
|
|
longEventDateTime,
|
|
longEndDateTime,
|
|
isSameDay,
|
|
allDayEvent,
|
|
}: any): ScheduleItem => ({
|
|
title,
|
|
description,
|
|
location,
|
|
allDayEvent,
|
|
startDate: parseDate(longEventDateTime),
|
|
endDate: parseDate(longEndDateTime),
|
|
oneDayEvent: isSameDay,
|
|
})
|
|
|
|
export const schedule = (data: any): ScheduleItem[] => {
|
|
try{
|
|
const scheduleData = etjanst(data)
|
|
const mapped = scheduleData.map(scheduleItem)
|
|
return mapped
|
|
}
|
|
catch(e){
|
|
if (e instanceof Error) {
|
|
// If this happens the child has no schedule
|
|
// It is the same on the official web
|
|
// Instead of retrying and spamming errors - lets return en empty array
|
|
if(e.message === 'A task was canceled.'){
|
|
return new Array<ScheduleItem>()
|
|
}
|
|
}
|
|
throw e
|
|
}
|
|
}
|