From 9783df8e3b43849f28f16af96871f653f536c732 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Sat, 28 Dec 2024 16:28:05 +0100 Subject: [PATCH] Require invite limit (#1748) * Fix invite limit required * Fix redeeming of unlimited invites * Require invite limit --- api/paidAction/inviteGift.js | 4 ++-- api/typeDefs/invite.js | 2 +- pages/invites/index.js | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/api/paidAction/inviteGift.js b/api/paidAction/inviteGift.js index 0cc52cae..c96f5c92 100644 --- a/api/paidAction/inviteGift.js +++ b/api/paidAction/inviteGift.js @@ -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 diff --git a/api/typeDefs/invite.js b/api/typeDefs/invite.js index 038447d8..dc7e0857 100644 --- a/api/typeDefs/invite.js +++ b/api/typeDefs/invite.js @@ -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 } diff --git a/pages/invites/index.js b/pages/invites/index.js index 7692c9d2..fbccd528 100644 --- a/pages/invites/index.js +++ b/pages/invites/index.js @@ -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 /> invitee limit optional} + label='invitee limit' name='limit' />