Skip to content

Added a random comment - #1

Open
zchisholm wants to merge 1 commit into
mainfrom
dev
Open

Added a random comment#1
zchisholm wants to merge 1 commit into
mainfrom
dev

Conversation

@zchisholm

Copy link
Copy Markdown
Owner

Added a random comment for testing.

@vercel

vercel Bot commented Nov 24, 2024

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
z-cord ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 24, 2024 1:00am

@zenseireviews

zenseireviews Bot commented Nov 24, 2024

Copy link
Copy Markdown

invite.ts

Instead of querying the database for the invite twice, you can query it once and store the result in a variable.
Create Issue

    const invite = await ctx.db.get(inviteId);
    if (!invite || invite.expiresAt && Date.now() > invite.expiresAt || invite.maxUses && invite.uses >= invite.maxUses) {
      if (!invite) {
        throw new Error("Invite not found.");
      } else if (invite.expiresAt && Date.now() > invite.expiresAt) {
        throw new Error("Invite expired");
      } else if (invite.maxUses && invite.uses >= invite.maxUses) {
        throw new Error("Invite has been used too many times");
      }
    }

Use optional chaining to simplify the code and make it more readable.
Create Issue

    const invite = await ctx.db.get(inviteId);
    if (!invite?.expiresAt || !invite?.maxUses || Date.now() > invite?.expiresAt || invite?.uses >= invite?.maxUses) {
      if (!invite) {
        throw new Error("Invite not found.");
      } else if (invite.expiresAt && Date.now() > invite.expiresAt) {
        throw new Error("Invite expired");
      } else if (invite.maxUses && invite.uses >= invite.maxUses) {
        throw new Error("Invite has been used too many times");
      }
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant