calendar-strip - get mapado events for month working
This commit is contained in:
parent
801fe38447
commit
02554fa718
3 changed files with 64 additions and 14 deletions
|
|
@ -1,19 +1,24 @@
|
|||
dayjs.locale("fr");
|
||||
|
||||
async function getDaysInMonth(month, year) {
|
||||
function getDatesInMonth(month) {
|
||||
const year = dayjs().month(month).year();
|
||||
const daysInMonth = dayjs(new Date(year, month, 0)).daysInMonth();
|
||||
const days = [];
|
||||
const dates = {};
|
||||
|
||||
for (let day = 1; day <= daysInMonth; day++) {
|
||||
const currentDay = dayjs(new Date(year, month - 1, day));
|
||||
days.push(currentDay.format("DD-MM-YYYY"));
|
||||
dates[parseInt(currentDay.format("DD"))] = [];
|
||||
}
|
||||
|
||||
return days;
|
||||
return dates;
|
||||
}
|
||||
|
||||
function getEvents(monthNumb) {
|
||||
async function getMapadoDates(monthNumb) {
|
||||
const myHeaders = new Headers();
|
||||
|
||||
const mapadoToken =
|
||||
"9bc321f5f47cf366c1c69eab4db69fe2a46819c75018237570473e2c961e210e227cc1e8cd8da7ba";
|
||||
|
||||
myHeaders.append("Authorization", "Bearer " + mapadoToken);
|
||||
|
||||
const requestOptions = {
|
||||
|
|
@ -22,6 +27,38 @@ function getEvents(monthNumb) {
|
|||
redirect: "follow",
|
||||
};
|
||||
|
||||
const url =
|
||||
"https://ticketing.mapado.net/v1/event_dates?itemsPerPage=31&contract=1941&after=2024-10-01&before=2024-11-01&order=asc&fields=startDate,bookableStock,ticketing{@id,title,firstFutureEventDateStartDate,isOnSale,minisite{domain,online,slug,name},venue{@id,name,seatingName,address,zipCode,city,countryCode,timezone}}";
|
||||
const contractId = "1941";
|
||||
|
||||
const firstDayOfMonth = dayjs()
|
||||
.month(monthNumb)
|
||||
.startOf("month")
|
||||
.format("YYYY-MM-DD");
|
||||
const firstDayOfNextMonth = dayjs(firstDayOfMonth)
|
||||
.add(1, "month")
|
||||
.format("YYYY-MM-DD");
|
||||
|
||||
const url = `https://ticketing.mapado.net/v1/event_dates?itemsPerPage=100&contract=${contractId}&after=${firstDayOfMonth}&before=${firstDayOfNextMonth}&order=asc&fields=startDate,bookableStock,ticketing{@id,title,venue{@id,name,seatingName,address,zipCode,city,countryCode,timezone}}`;
|
||||
|
||||
const response = await fetch(url, requestOptions);
|
||||
const json = await response.json();
|
||||
const eventDates = json["hydra:member"];
|
||||
|
||||
console.log(
|
||||
`Événements Mapado de ${dayjs(firstDayOfMonth).format("MMMM")} ${dayjs(
|
||||
firstDayOfMonth
|
||||
).format("YYYY")}`,
|
||||
eventDates
|
||||
);
|
||||
|
||||
const mapadoDates = eventDates.map((eventDate) => {
|
||||
const date = eventDate.startDate.slice(0, 10);
|
||||
const splittedDate = date.split("-");
|
||||
const day = splittedDate[2];
|
||||
return {
|
||||
day: day,
|
||||
name: eventDate.ticketing.title,
|
||||
};
|
||||
});
|
||||
|
||||
return mapadoDates;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue