MCPcopy Create free account
hub / github.com/SuperteamDAO/earn / generateUniqueReferralCode

Function generateUniqueReferralCode

src/utils/referralCodeGenerator.ts:17–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15};
16
17export 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};

Callers 1

POSTFunction · 0.90

Calls 1

generateCandidateFunction · 0.85

Tested by

no test coverage detected