()
| 15 | }; |
| 16 | |
| 17 | export const generateUniqueReferralCode = async (): Promise<string> => { |
| 18 | for (let attempt = 0; attempt < 5; attempt++) { |
| 19 | const candidate = generateCandidate(7); |
| 20 | const exists = await prisma.user.findUnique({ |
| 21 | where: { referralCode: candidate }, |
| 22 | select: { id: true }, |
| 23 | }); |
| 24 | if (!exists) return candidate; |
| 25 | } |
| 26 | |
| 27 | while (true) { |
| 28 | const candidate = generateCandidate(7); |
| 29 | const exists = await prisma.user.findUnique({ |
| 30 | where: { referralCode: candidate }, |
| 31 | select: { id: true }, |
| 32 | }); |
| 33 | if (!exists) return candidate; |
| 34 | } |
| 35 | }; |
no test coverage detected