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 }
|
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')
|
throw new Error('invite limit reached')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ export async function perform ({ id, userId }, { me, cost, tx }) {
|
||||||
})
|
})
|
||||||
|
|
||||||
return await tx.invite.update({
|
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: {
|
data: {
|
||||||
giftedCount: {
|
giftedCount: {
|
||||||
increment: 1
|
increment: 1
|
||||||
|
|
|
@ -7,7 +7,7 @@ export default gql`
|
||||||
}
|
}
|
||||||
|
|
||||||
extend type Mutation {
|
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
|
revokeInvite(id: ID!): Invite
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ function InviteForm () {
|
||||||
const [createInvite] = useMutation(
|
const [createInvite] = useMutation(
|
||||||
gql`
|
gql`
|
||||||
${INVITE_FIELDS}
|
${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) {
|
createInvite(id: $id, gift: $gift, limit: $limit, description: $description) {
|
||||||
...InviteFields
|
...InviteFields
|
||||||
}
|
}
|
||||||
|
@ -57,7 +57,7 @@ function InviteForm () {
|
||||||
variables: {
|
variables: {
|
||||||
id: id || undefined,
|
id: id || undefined,
|
||||||
gift: Number(gift),
|
gift: Number(gift),
|
||||||
limit: limit ? Number(limit) : limit,
|
limit: Number(limit),
|
||||||
description: description || undefined
|
description: description || undefined
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -72,7 +72,7 @@ function InviteForm () {
|
||||||
required
|
required
|
||||||
/>
|
/>
|
||||||
<Input
|
<Input
|
||||||
label={<>invitee limit <small className='text-muted ms-2'>optional</small></>}
|
label='invitee limit'
|
||||||
name='limit'
|
name='limit'
|
||||||
/>
|
/>
|
||||||
<AccordianItem
|
<AccordianItem
|
||||||
|
|
Loading…
Reference in New Issue