Default to day grouping if invalid parameter

This commit is contained in:
Franco Speziali 2023-05-25 15:48:53 +02:00
parent ea994df145
commit e800147eaa

View File

@ -14,12 +14,24 @@ export default class Calendar {
constructor(json: object) { constructor(json: object) {
this.jsonContent = json; this.jsonContent = json;
this.groupType = json["group"] this.groupType = this.getGroupType(json);
? json["group"].charAt(0).toUpperCase()
: GroupTypes.Day;
this.events = new Events(json["events"]); this.events = new Events(json["events"]);
} }
private getGroupType(json: object): GroupTypes {
if (!json["group"]) {
return GroupTypes.Day;
}
const groupType = json["group"].charAt(0).toUpperCase();
if (!Object.values(GroupTypes).includes(groupType)) {
return GroupTypes.Day;
}
return groupType;
}
render(): HTMLDivElement { render(): HTMLDivElement {
switch (this.groupType) { switch (this.groupType) {
case GroupTypes.Day: case GroupTypes.Day: