From 9d1a6c7c6eb1aecff385b16991958c0d53d86430 Mon Sep 17 00:00:00 2001 From: AJaccP Date: Sat, 15 Jun 2024 01:56:06 +0530 Subject: [PATCH] linting --- .../services/challenges-service.ts | 19 ++++++-------- .../services/participants-service.ts | 15 +++++------ .../services/submissions-service.ts | 12 ++++++--- .../factories/accessible-challenge-factory.ts | 26 +++++++++---------- .../accessible-challenges-service.test.ts | 18 ++++++++----- .../services/challenges-service.test.ts | 4 +-- .../services/participants-service.test.ts | 2 +- 7 files changed, 51 insertions(+), 45 deletions(-) diff --git a/app/challenges-platform/services/challenges-service.ts b/app/challenges-platform/services/challenges-service.ts index 861a0f7..53a0f55 100644 --- a/app/challenges-platform/services/challenges-service.ts +++ b/app/challenges-platform/services/challenges-service.ts @@ -21,38 +21,35 @@ export const findByUuid = async ( if (result.length === 0) { return Err(new Error("Challenge not found")); } - + const challenge = await convert(result[0]); - + return Ok(challenge); -} +}; export const findById = async ( id: number, ): Promise> => { - const result = await db .select() .from(challenges) .where(eq(challenges.id, id)); - if (result.length === 0) { - return Err(new Error("Challenge not found")); - } + if (result.length === 0) { + return Err(new Error("Challenge not found")); + } const challenge = await convert(result[0]); return Ok(challenge); }; -export const convert = async ( - result: any, -): Promise => { +export const convert = async (result: any): Promise => { const transformer = challengesPlatform.findTransformer(result.type); const challenge = transformer.newChallenge(result); return challenge; -} +}; export const create = async ({ title, diff --git a/app/challenges-platform/services/participants-service.ts b/app/challenges-platform/services/participants-service.ts index 5e73da3..8e84723 100644 --- a/app/challenges-platform/services/participants-service.ts +++ b/app/challenges-platform/services/participants-service.ts @@ -20,16 +20,15 @@ export const findByUuid = async ( if (result.length === 0) { return Err(new Error("Participant not found")); } - + const participant = await convert(result[0]); - + return Ok(participant); -} +}; export const findById = async ( id: number, ): Promise> => { - const result = await db .select() .from(participants) @@ -42,18 +41,16 @@ export const findById = async ( const participant = await convert(result[0]); return Ok(participant); -} +}; -export const convert = async ( - result: any, -): Promise => { +export const convert = async (result: any): Promise => { const participant = new Participant({ id: result.id, uuid: result.uuid, email: result.email, }); return participant; -} +}; export const findByEmail = async ( email?: string, diff --git a/app/challenges-platform/services/submissions-service.ts b/app/challenges-platform/services/submissions-service.ts index 3a098bf..a4c6df2 100644 --- a/app/challenges-platform/services/submissions-service.ts +++ b/app/challenges-platform/services/submissions-service.ts @@ -38,16 +38,22 @@ export const findByUuid = async ( return Err(new Error("Failed to find challenge")); } - const participantResult = await ParticipantsService.findById(record.participantId); + const participantResult = await ParticipantsService.findById( + record.participantId, + ); if (!participantResult.ok) { return Err(new Error("Failed to find participant")); } const transformer = challengesPlatform.findTransformer(type); - const submission = transformer.newSubmission(result[0], challengeResult.val, participantResult.val); + const submission = transformer.newSubmission( + result[0], + challengeResult.val, + participantResult.val, + ); return Ok(submission); -} +}; export const create = async ( challengeId: string, diff --git a/test/challenges-platform/factories/accessible-challenge-factory.ts b/test/challenges-platform/factories/accessible-challenge-factory.ts index b73dc49..6107179 100644 --- a/test/challenges-platform/factories/accessible-challenge-factory.ts +++ b/test/challenges-platform/factories/accessible-challenge-factory.ts @@ -9,16 +9,16 @@ import { db } from "../../../db"; import { accessibleChallenges } from "../../../db/schema"; export const accessibleChallengeFactory = async ({ - challenge, - participant, - }: { - challenge?: Challenge; - participant?: Participant; - } = {}): Promise => { - const c = challenge || (await challengeFactory()); - const p = participant || (await participantFactory()); + challenge, + participant, +}: { + challenge?: Challenge; + participant?: Participant; +} = {}): Promise => { + const c = challenge || (await challengeFactory()); + const p = participant || (await participantFactory()); - const insertResult = await db + const insertResult = await db .insert(accessibleChallenges) .values({ challengeId: c.id, @@ -26,7 +26,7 @@ export const accessibleChallengeFactory = async ({ }) .returning(); - const result = await AccessibleChallengesService.count(c, p); - if (!result.ok) fail("Expected result to be Ok"); - return result.val; - }; \ No newline at end of file + const result = await AccessibleChallengesService.count(c, p); + if (!result.ok) fail("Expected result to be Ok"); + return result.val; +}; diff --git a/test/challenges-platform/services/accessible-challenges-service.test.ts b/test/challenges-platform/services/accessible-challenges-service.test.ts index 47ae385..facc7f5 100644 --- a/test/challenges-platform/services/accessible-challenges-service.test.ts +++ b/test/challenges-platform/services/accessible-challenges-service.test.ts @@ -10,7 +10,10 @@ describe("AccessibleChallengesService", () => { const challenge = await challengeFactory(); const participant = await participantFactory(); - const result = await AccessibleChallengesService.count(challenge, participant); + const result = await AccessibleChallengesService.count( + challenge, + participant, + ); if (!result.ok) fail("Expected result to be Ok"); expect(result.val).toBe(0); @@ -22,15 +25,18 @@ describe("AccessibleChallengesService", () => { const participant = await participantFactory(); const insert = await accessibleChallengeFactory({ - challenge, - participant + challenge, + participant, }); - const result = await AccessibleChallengesService.count(challenge, participant); + const result = await AccessibleChallengesService.count( + challenge, + participant, + ); if (!result.ok) fail("Expected result to be Ok"); expect(result.val).toBe(1); }); }); - }) -}); \ No newline at end of file + }); +}); diff --git a/test/challenges-platform/services/challenges-service.test.ts b/test/challenges-platform/services/challenges-service.test.ts index 449247f..9e15a09 100644 --- a/test/challenges-platform/services/challenges-service.test.ts +++ b/test/challenges-platform/services/challenges-service.test.ts @@ -52,7 +52,7 @@ describe("ChallengesService", () => { expect(result.val.body).toBe("This is a test challenge"); expect(result.val.points).toBe(100); }); - }); + }); describe("when there is no record", () => { it("returns an error", async () => { @@ -63,7 +63,7 @@ describe("ChallengesService", () => { expect(result.val.toString()).toBe("Error: Challenge not found"); }); }); - }); + }); describe("create", () => { it("succesfully creates a challenge", async () => { diff --git a/test/challenges-platform/services/participants-service.test.ts b/test/challenges-platform/services/participants-service.test.ts index 66e8885..6bbdd58 100644 --- a/test/challenges-platform/services/participants-service.test.ts +++ b/test/challenges-platform/services/participants-service.test.ts @@ -57,7 +57,7 @@ describe("ParticipantsService", () => { expect(result.val.email).toBe(participant.email); }); }); - + describe("when there is no record", () => { it("returns an error", async () => { const testId = -1;