From 8fb5ac57db0c6d6c23add26b57f685649521c947 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diana=20L=C3=B3pez=20Alvas?= Date: Tue, 5 Dec 2023 14:34:49 -0300 Subject: [PATCH] no numToAlpha --- src/api/routes/userChallenges.ts | 27 ++------------------------- test/api/userChallenges.spec.ts | 10 +--------- 2 files changed, 3 insertions(+), 34 deletions(-) diff --git a/src/api/routes/userChallenges.ts b/src/api/routes/userChallenges.ts index d48503f..1b4e270 100644 --- a/src/api/routes/userChallenges.ts +++ b/src/api/routes/userChallenges.ts @@ -35,34 +35,11 @@ const upsertChallenge = async (sharedId, user, body) => { function generateChallengeID(): string { const nowTimestamp: number = Date.now() - Date.UTC(2023, 0, 1) - return numToAlpha(nowTimestamp) -} - -function numToAlpha(num: number): string { - const mapping = '012345679' //We dont use letters to prevent offensive words. We removed the 8 for the same reason. - const alpha: string[] = [] - let remainingNum: number = num - 1 - while (remainingNum >= 0) { - alpha.push(mapping[remainingNum % 9]) - remainingNum = Math.floor(remainingNum / 9) - 1 - } - return alpha.reverse().join('') -} - -const existChallengeWithSharedId = async (sharedId) => await UserChallengeModel.exists({ sharedId }) - -const generateUniqueChallengeSharedId = async () => { - let sharedId - - do { - sharedId = generateChallengeID() - } while (await existChallengeWithSharedId(sharedId)) - - return sharedId + return nowTimestamp.toString() } const createUserChallenge = async (body, user) => { - const sharedId = await generateUniqueChallengeSharedId() + const sharedId = generateChallengeID() return await UserChallengeModel.create({ ...body, user, sharedId }) } diff --git a/test/api/userChallenges.spec.ts b/test/api/userChallenges.spec.ts index 3c6b767..b0bbda0 100644 --- a/test/api/userChallenges.spec.ts +++ b/test/api/userChallenges.spec.ts @@ -57,12 +57,4 @@ describeApi('User challenges', (request, { authenticated }) => { }) -}) - -/** - * Si no está logueado nunca entra, asi que siempre testear logueado - * - * - Challenge no existe, lo guardo, el id ya existe, creo otro. - * - * - */ \ No newline at end of file +}) \ No newline at end of file