Require invite limit (#1748)

* Fix invite limit required

* Fix redeeming of unlimited invites

* Require invite limit
This commit is contained in:
ekzyis 2024-12-28 16:28:05 +01:00 committed by GitHub
parent 74f771adf4
commit 9783df8e3b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View File

@ -21,7 +21,7 @@ export async function perform ({ id, userId }, { me, cost, tx }) {
where: { id, userId: me.id, revoked: false }
})
if (invite.giftedCount >= invite.limit) {
if (invite.limit && invite.giftedCount >= invite.limit) {
throw new Error('invite limit reached')
}
@ -45,7 +45,7 @@ export async function perform ({ id, userId }, { me, cost, tx }) {
})
return await tx.invite.update({
where: { id, userId: me.id, giftedCount: { lt: invite.limit }, revoked: false },
where: { id, userId: me.id, revoked: false, ...(invite.limit ? { giftedCount: { lt: invite.limit } } : {}) },
data: {
giftedCount: {
increment: 1

View File

@ -7,7 +7,7 @@ export default gql`
}
extend type Mutation {
createInvite(id: String, gift: Int!, limit: Int, description: String): Invite
createInvite(id: String, gift: Int!, limit: Int!, description: String): Invite
revokeInvite(id: ID!): Invite
}

View File

@ -19,7 +19,7 @@ function InviteForm () {
const [createInvite] = useMutation(
gql`
${INVITE_FIELDS}
mutation createInvite($id: String, $gift: Int!, $limit: Int, $description: String) {
mutation createInvite($id: String, $gift: Int!, $limit: Int!, $description: String) {
createInvite(id: $id, gift: $gift, limit: $limit, description: $description) {
...InviteFields
}
@ -57,7 +57,7 @@ function InviteForm () {
variables: {
id: id || undefined,
gift: Number(gift),
limit: limit ? Number(limit) : limit,
limit: Number(limit),
description: description || undefined
}
})
@ -72,7 +72,7 @@ function InviteForm () {
required
/>
<Input
label={<>invitee limit <small className='text-muted ms-2'>optional</small></>}
label='invitee limit'
name='limit'
/>
<AccordianItem