nouveau-theatre-de-besancon/assets/dist/calendar.min.js
2024-09-20 10:32:49 +02:00

1 line
No EOL
2.7 KiB
JavaScript

function getDatesInMonth(e){const t=dayjs().month(e).year(),a=dayjs(new Date(t,e,0)).daysInMonth(),n={};for(let o=1;o<=a;o++){const a=dayjs(new Date(t,e,o)),s=a.format("dd")[0].toUpperCase();n[parseInt(a.format("DD"))]={sessions:[],full:a.format("DD-MM-YYYY"),initial:s}}return n}async function getMapadoEvent(e){const t="ticketings/"+e,a={method:"POST",body:JSON.stringify({requestEndPoint:t,requestParams:[],requestFields:[{name:"startDate"},{name:"bookableStock"},{name:"eventDateList",subfields:[{name:"@id"},{name:"bookableStock"}]}]})},n=await fetch("/mapado-api.json",a),o=(await n.json())["hydra:member"];console.log("Événement Mapado",o)}async function getMapadoDates(e){const t=dayjs().month(e).startOf("month").format("YYYY-MM-DD"),a=[{name:"itemsPerPage",value:100},{name:"contract",value:"1941"},{name:"after",value:t},{name:"before",value:dayjs(t).add(1,"month").format("YYYY-MM-DD")},{name:"order",value:"asc"}],n={method:"POST",body:JSON.stringify({requestEndPoint:"event_dates",requestParams:a,requestFields:[{name:"startDate"},{name:"bookableStock"},{name:"ticketing",subfields:[{name:"@id"},{name:"title"},{name:"slug"},{name:"venue",subfields:[{name:"@id"},{name:"address"},{name:"zipCode"},{name:"city"},{name:"countryCode"},{name:"timezone"}]}]}]})},o=await fetch("/mapado-api.json",n),s=(await o.json())["hydra:member"];console.log(`Événements Mapado de ${dayjs(t).format("MMMM")} ${dayjs(t).format("YYYY")}`,s);return s.map((e=>({day:getDay(e),title:e.ticketing.title,startTime:getStartTime(e),ticketingUrl:getTicketingUrl(e),id:getId(e)})))}function getDay(e){return e.startDate.slice(0,10).split("-")[2]}function getStartTime(e){const t=e.startDate.slice(11,19);return dayjs(`2000-01-01T${t}`).format("HH[h]mm")}function getTicketingUrl(e){return"https://cdn-besancon.mapado.com/event/"+e.ticketing.slug}function getId(e){const t=e.ticketing["@id"].split("/");return parseInt(t[3])}function createEmptyCalendar(){const e={};for(let t=9;t<21;t++){const a=(t-1)%12+1,n=dayjs().month(a-1).daysInMonth();e[a]={};for(let t=1;t<=n;t++){const n=dayjs().month(a-1).date(t),o=n.format("dd")[0].toUpperCase();e[a][t]={sessions:[],full:n.format("DD-MM-YYYY"),initial:o,index:parseInt(n.format("DD")),indexInWeek:0===n.day()?7:n.day()}}}return e}async function getCurrentSeasonCalendar(e,t){const a={calendar:createEmptyCalendar()},n={method:"POST",body:JSON.stringify(a)},o=await fetch("/get-current-season-calendar.json",n);return await o.json()}async function updateMapadoEvent(e){const t={method:"POST",headers:new Headers,redirect:"follow",body:JSON.stringify({pageUri:e})},a=await fetch("/update-mapado-event.json",t),n=await a.json();return console.log("Séance récupérées de Mapado",n),n}function dateToFrench(e){return(e=dayjs(e)).format("D MMMM YYYY")}dayjs.locale("fr");