Search code examples
nestjs

How to ban users for a certain period of time in Nestjs and mongodb?


I want to Implement Ban functionality with Nestjs and Mongodb. Admin can ban a user for a certain period of time or block for a certain period of time. And after that period of time the ban functionality will be automatically removed and user can login again.

It might be happen like this...

If we want to ban some one we can change his role, for example user(1) to ban(0). And for next 7 days the role will be ban(0). And after the 7th day the role will automatically convert into user(1). And user can see how many days are left until the ban restriction is removed from his account.

But I'm getting nothing from internet on this topic. Can anybody tell how do we implement this functionality? Or any blog or document which can help...


Solution

  • I think you are probably looking for task scheduling:

    https://docs.nestjs.com/techniques/task-scheduling

    You can execute a function periodically and either delete users or update their role depending on your business requirements.