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

chore: create a cron job function that will run every hour to clean up expired otps #73

Merged

Conversation

lakshay-saini-au8
Copy link
Contributor

@lakshay-saini-au8 lakshay-saini-au8 commented Jan 4, 2024

Type

enhancement


Description

This PR introduces a new feature to clean up expired OTPs from the database. The main changes include:

  • A new method deleteExpiredOtps has been added to the AuthRepository, IAuthRepository, and MockAuthRepository to delete expired OTPs.
  • A new cron job cleanUpExpiredOtps has been added to the AuthService that runs every hour to delete expired OTPs.
  • The @nestjs/schedule package has been added as a new dependency to handle scheduling tasks.

PR changes walkthrough

Relevant files                                                                                                                                 
Enhancement
4 files
auth.repository.ts                                                                                   
    apps/api/src/auth/repository/auth.repository.ts

    Added a new method deleteExpiredOtps to delete expired
    OTPs from the database.

+11/-0
interface.repository.ts                                                                         
    apps/api/src/auth/repository/interface.repository.ts

    Added a new method deleteExpiredOtps to the
    IAuthRepository interface.

+6/-0
mock.repository.ts                                                                                   
    apps/api/src/auth/repository/mock.repository.ts

    Added a new method deleteExpiredOtps to the
    MockAuthRepository class.

+4/-0
auth.service.ts                                                                                         
    apps/api/src/auth/service/auth.service.ts

    Added a new cron job cleanUpExpiredOtps that runs every
    hour to delete expired OTPs.

+11/-0
Dependencies
2 files
package.json                                                                                               
    package.json

    Added a new dependency @nestjs/schedule for scheduling
    tasks.

+1/-0
pnpm-lock.yaml                                                                                           
    pnpm-lock.yaml

    Updated the lock file to include the new dependency and its
    dependencies.

+38/-0

User description

Description

Create a scheduler to delete expired OTPs.

Fixes #42

Dependencies

@nestjs/schedule

Future Improvements

Mentions

@rajdip-b

Screenshots of relevant screens

Developer's checklist

  • My PR follows the style guidelines of this project
  • I have performed a self-check on my work

If changes are made in the code:

  • I have followed the coding guidelines
  • My changes in code generate no new warnings
  • My changes are breaking another fix/feature of the project
  • I have added test cases to show that my feature works
  • I have added relevant screenshots in my PR
  • There are no UI/UX issues

Documentation Update

  • This PR requires an update to the documentation at docs.keyshade.xyz
  • I have made the necessary updates to the documentation, or no documentation changes are required.

@codiumai-pr-agent-free codiumai-pr-agent-free bot added the type: enhancement New feature or request label Jan 4, 2024
Copy link
Contributor

PR Description updated to latest commit (5ffb54d)

Copy link
Contributor

PR Analysis

  • 🎯 Main theme: Implementing a cron job to clean up expired OTPs
  • 📝 PR summary: This PR introduces a new feature to clean up expired OTPs from the database. It adds a new method deleteExpiredOtps to the AuthRepository, IAuthRepository, and MockAuthRepository. A new cron job cleanUpExpiredOtps is added to the AuthService that runs every hour to delete expired OTPs. The @nestjs/schedule package has been added as a new dependency to handle scheduling tasks.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • ⏱️ Estimated effort to review [1-5]: 3, because the PR introduces a new feature and modifies several files, but the changes are straightforward and well-structured.
  • 🔒 Security concerns: No security concerns found

PR Feedback

💡 General suggestions: The PR is well-structured and the code changes are clear. However, it would be beneficial to add tests to ensure the new cron job and the deleteExpiredOtps method work as expected. Additionally, consider handling potential errors that may occur during the deletion of expired OTPs.

🤖 Code feedback:
relevant fileapps/api/src/auth/service/auth.service.ts
suggestion      

Consider adding a return statement in the cleanUpExpiredOtps method to return the result of the deleteExpiredOtps method. This can be useful for testing and debugging purposes. [medium]

relevant lineasync cleanUpExpiredOtps() {

relevant fileapps/api/src/auth/repository/auth.repository.ts
suggestion      

It might be more efficient to use the Prisma deleteMany method directly without assigning timeNow to a new Date object. You can use new Date() directly in the lte condition. [medium]

relevant lineconst timeNow = new Date()

relevant fileapps/api/src/auth/service/auth.service.ts
suggestion      

Consider adding error handling for the deleteExpiredOtps method call. This can help to avoid unhandled promise rejection warnings. [important]

relevant lineawait this.authRepository.deleteExpiredOtps()

relevant fileapps/api/src/auth/repository/mock.repository.ts
suggestion      

Implement the deleteExpiredOtps method in the MockAuthRepository for testing purposes. [medium]

relevant linedeleteExpiredOtps(): Promise {

✨ Usage tips:

To invoke the PR-Agent, add a comment using one of the following commands:

  • /review: Request a review of your Pull Request.
  • /describe: Update the PR title and description based on the contents of the PR.
  • /improve [--extended]: Suggest code improvements. Extended mode provides a higher quality feedback.
  • /ask <QUESTION>: Ask a question about the PR.
  • /update_changelog: Update the changelog based on the PR's contents.
  • /add_docs 💎: Generate docstring for new components introduced in the PR.
  • /generate_labels 💎: Generate labels for the PR based on the PR's contents.
  • /analyze 💎: Automatically analyzes the PR, and presents changes walkthrough for each component.

See the tools guide for more details.
To edit any configuration parameter from the configuration.toml, add --config_path=new_value.
For example: /review --pr_reviewer.extra_instructions="focus on the file: ..."
To list the possible configuration parameters, add a /config comment.

@rajdip-b rajdip-b changed the title chore:create a cron job function that will run every hour to clean up expired otps chore: create a cron job function that will run every hour to clean up expired otps Jan 4, 2024
Copy link
Member

@rajdip-b rajdip-b left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice to me. I'll review this tomorrow morning and merge it!

@rajdip-b rajdip-b merged commit bc71a29 into keyshade-xyz:main Jan 6, 2024
3 checks passed
@rajdip-b
Copy link
Member

rajdip-b commented Feb 2, 2024

🎉 This PR is included in version 1.0.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@rajdip-b
Copy link
Member

rajdip-b commented Feb 9, 2024

🎉 This PR is included in version 1.0.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create scheduler to delete expired OTPs
2 participants