-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(merge): merge develop into main
- Loading branch information
Showing
177 changed files
with
4,704 additions
and
1,945 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Team, Location, EncounterCompetition } from '@badman/backend-database'; | ||
import { Controller, Get, Query, Res } from '@nestjs/common'; | ||
import { Response } from 'express'; | ||
import { ICalCalendar } from 'ical-generator'; | ||
import moment from 'moment'; | ||
import { Includeable, Op } from 'sequelize'; | ||
|
||
@Controller('calendar') | ||
export class CalendarController { | ||
@Get('team') | ||
async generateCalendarLink( | ||
@Query() query: { teamId: string; linkId: string }, | ||
@Res() res: Response, | ||
) { | ||
if (!query.teamId && !query.linkId) { | ||
return res.status(400).send('Invalid team or link id'); | ||
} | ||
|
||
const team = query.teamId | ||
? await Team.findByPk(query.teamId) | ||
: await Team.findOne({ where: { link: query.linkId } }); | ||
|
||
if (!team) { | ||
return res.status(404).send('Team not found'); | ||
} | ||
|
||
const enconuters = await EncounterCompetition.findAll({ | ||
where: { | ||
[Op.or]: [{ homeTeamId: team.id }, { awayTeamId: team.id }], | ||
}, | ||
include: [ | ||
{ | ||
model: Location, | ||
as: 'location', | ||
}, | ||
{ | ||
model: Team, | ||
as: 'home', | ||
}, | ||
{ | ||
model: Team, | ||
as: 'away', | ||
}, | ||
], | ||
}); | ||
|
||
console.log(`found ${enconuters.length} away encounters`); | ||
|
||
const events = enconuters.map((enc) => ({ | ||
title: `${enc.home.name} vs ${enc.away.name}`, | ||
startTime: enc.date, | ||
endTime: moment(enc.date).add(3, 'hours').toDate(), | ||
description: `${enc.home.name} vs ${enc.away.name}`, | ||
location: enc.location, | ||
})); | ||
|
||
const calendar = new ICalCalendar({ | ||
name: team.name, | ||
}); | ||
|
||
events.forEach((event) => { | ||
calendar.createEvent({ | ||
start: event.startTime, | ||
end: event.endTime, | ||
summary: event.title, | ||
description: event.description, | ||
location: { | ||
title: event.location.name, | ||
address: event.location.address, | ||
// geo: { | ||
// lat: event.location.coordinates. | ||
// } | ||
}, | ||
}); | ||
}); | ||
|
||
res.header('Content-Type', 'text/calendar'); | ||
res.header('Content-Disposition', `attachment; filename="calendar-${team.name}.ics"`); | ||
|
||
// Send the calendar data as an .ics file | ||
res.send(calendar.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"version": "6.166.3" | ||
"version": "6.168.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"version": "6.166.3" | ||
"version": "6.168.3" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.