Require invite limit (#1748)
* Fix invite limit required * Fix redeeming of unlimited invites * Require invite limit
This commit is contained in:
parent
74f771adf4
commit
9783df8e3b
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue