Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ts.1411 #1539

Merged
merged 2 commits into from
Nov 7, 2023
Merged

Ts.1411 #1539

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 42 additions & 36 deletions backend/workers/createRecurringEvents.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,52 +60,58 @@ module.exports = (cron, fetch) => {
// forEach function with async/await.
for (filteredEvent of filteredEvents) {
const eventExists = await checkIfEventExists(filteredEvent.name);
// console.log('Event exists? ', eventExists);
const eventDate = new Date(filteredEvent.date);

if (eventExists) {
console.log("Not going to run ceateEvent");
//Do nothing
console.log("➖ Not going to run ceateEvent");
} else {
// Create new event
const hours = eventDate.getHours();
const minutes = eventDate.getMinutes();
const seconds = eventDate.getSeconds();
const milliseconds = eventDate.getMilliseconds();

const yearToday = TODAY_DATE.getFullYear();
const monthToday = TODAY_DATE.getMonth();
const dateToday = TODAY_DATE.getDate();

const newEventDate = new Date(yearToday, monthToday, dateToday, hours, minutes, seconds, milliseconds);

const newEndTime = new Date(yearToday, monthToday, dateToday, hours + filteredEvent.hours, minutes, seconds, milliseconds)

const eventToCreate = {
name: filteredEvent.name && filteredEvent.name,
hacknight: filteredEvent.hacknight && filteredEvent.hacknight,
eventType: filteredEvent.eventType && filteredEvent.eventType,
description: filteredEvent.eventDescription && filteredEvent.eventDescription,
project: filteredEvent.project && filteredEvent.project,
date: filteredEvent.date && newEventDate,
startTime: filteredEvent.startTime && newEventDate,
endTime: filteredEvent.endTime && newEndTime,
hours: filteredEvent.hours && filteredEvent.hours
}
if (filteredEvent.hasOwnProperty("location")) {
eventToCreate.location = {
city: filteredEvent.location.city ? filteredEvent.location.city : 'REMOTE',
state: filteredEvent.location.state ? filteredEvent.location.state : 'REMOTE',
country: filteredEvent.location.country ? filteredEvent.location.country : 'REMOTE'
};
}

const eventToCreate = generateEventData(filteredEvent);

const created = await createEvent(eventToCreate);
console.log(created);
console.log("➕", created);
};
};
};
};

function generateEventData(eventData, TODAY_DATE = new Date()) {
const eventDate = new Date(eventData.startTime);
// Create new event
const hours = eventDate.getHours();
const minutes = eventDate.getMinutes();
const seconds = eventDate.getSeconds();
const milliseconds = eventDate.getMilliseconds();

const yearToday = TODAY_DATE.getFullYear();
const monthToday = TODAY_DATE.getMonth();
const dateToday = TODAY_DATE.getDate();

const newEventDate = new Date(yearToday, monthToday, dateToday, hours, minutes, seconds, milliseconds);

const newEndTime = new Date(yearToday, monthToday, dateToday, hours + filteredEvent.hours, minutes, seconds, milliseconds)

const eventToCreate = {
name: eventData.name && eventData.name,
hacknight: eventData.hacknight && eventData.hacknight,
eventType: eventData.eventType && eventData.eventType,
description: eventData.eventDescription && eventData.eventDescription,
project: eventData.project && eventData.project,
date: eventData.date && newEventDate,
startTime: eventData.startTime && newEventDate,
endTime: eventData.endTime && newEndTime,
hours: eventData.hours && eventData.hours
}
if (eventData.hasOwnProperty("location")) {
eventToCreate.location = {
city: eventData.location.city ? eventData.location.city : 'REMOTE',
state: eventData.location.state ? eventData.location.state : 'REMOTE',
country: eventData.location.country ? eventData.location.country : 'REMOTE'
};
}
return eventToCreate
};

async function checkIfEventExists(eventName) {
const events = EVENTS;
// const today = new Date();
Expand Down
Loading