64 lines
1.8 KiB
JavaScript
64 lines
1.8 KiB
JavaScript
dayjs.locale("fr");
|
|
|
|
function getDatesInMonth(month) {
|
|
const year = dayjs().month(month).year();
|
|
const daysInMonth = dayjs(new Date(year, month, 0)).daysInMonth() + 1;
|
|
const dates = {};
|
|
|
|
for (let day = 1; day <= daysInMonth; day++) {
|
|
const currentDay = dayjs(new Date(year, month, day));
|
|
dates[parseInt(currentDay.format("DD"))] = [];
|
|
}
|
|
|
|
return dates;
|
|
}
|
|
|
|
async function getMapadoDates(monthNumb) {
|
|
const myHeaders = new Headers();
|
|
|
|
const mapadoToken =
|
|
"9bc321f5f47cf366c1c69eab4db69fe2a46819c75018237570473e2c961e210e227cc1e8cd8da7ba";
|
|
|
|
myHeaders.append("Authorization", "Bearer " + mapadoToken);
|
|
|
|
const requestOptions = {
|
|
method: "GET",
|
|
headers: myHeaders,
|
|
redirect: "follow",
|
|
};
|
|
|
|
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;
|
|
}
|