I have a function in which stores the current date, and time (timestamp) in mysql db.
formatted like so:
'2022-01-28 13:00:00.000000'
The way this gets inserted into my table is like so:
var insertNewEvent = "INSERT INTO SCHEDULE (DATE,LOCATION,ASSIGNED_TRAINER,CLIENT_USERNAME,ENDDATE, ID, EVENT_NAME, SESSION_STATUS) VALUES('" + eventDetails.eventDate + " " + eventDetails.eventStartTime + "', '" + eventDetails.eventLocation + "', '" + eventDetails.trainerUserName + "', '" + eventDetails.selectedClient + "', '" + eventDetails.eventDate + " " + eventDetails.eventEndTime + "', '" + uniqueID + "', '" + eventDetails.nameOfEvent + "', '" + session_status + "')"
and yes, I am changing this query as I know it is unsafe and not right.
but now what I want is for example, I want to say insert the same event (all same event details), but have it repeat on the day i inserted it for, and then every let's say monday, wednesday, friday after that. I am a little but stumped on how to go about this, I was hoping someone could guide me. thanks.
try creating a middleware to handle it, for example:
var checkDate= Date.UTC(new Date().getFullYear(), new Date().getMonth(),
(new Date().getDate() + 1));
const myMiddleware= async(req, res, next) =>{
if(Date.now()>= checkDate){
checkDate= Date.UTC(new Date().getFullYear(), new Date().getMonth(),
(new Date().getDate() + 1));
// your code here
}
next();
}
then use it
app.use(myMiddleware);