1 line
No EOL
2.7 KiB
JavaScript
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={},t=dayjs().month();for(let a=t;a<t+12;a++){const t=dayjs().month(a),n=t.daysInMonth();e[t.month()+1]={};for(let a=1;a<=n;a++){const n=t.date(a),o=n.format("dd")[0].toUpperCase();e[t.month()+1][a]={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(){const e={calendar:createEmptyCalendar()},t={method:"POST",body:JSON.stringify(e)},a=await fetch("/get-current-season-calendar.json",t);return await a.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"); |