I
I
Ivan2021-12-06 10:10:57
JavaScript
Ivan, 2021-12-06 10:10:57

How to get a timestamp and delete a row from the database, with the condition that the current time is greater than the specified one?

Hello! Please help me figure it out, I'm confused.
The sequelize module is used to work with the database.
So, there is some function to unlock the user. unban is a column that is timestamped from when the user was unbanned.

Task: need to delete a row if the current time is greater than the time in the unban column.

async function checkUnbans(bot){
    console.log('timer is working');
    let ban = await Ban.findOne({where: {
                    unban: {
            $lte: new Date().getTime()+1
        }
        }});
    if(ban) {
        await ban.destroy();
        await bot.sendMessage(ban.chat_id, " Вы разблокированы в боте!");
    }
}


The function itself is working, you just need to replace $lte: new Date().getTime()+1 with some kind of comparison. Hm...

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question