Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
AJaccP committed Jun 14, 2024
1 parent 5858d64 commit 9d1a6c7
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 45 deletions.
19 changes: 8 additions & 11 deletions app/challenges-platform/services/challenges-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<Challenge, Error>> => {

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<Challenge> => {
export const convert = async (result: any): Promise<Challenge> => {
const transformer = challengesPlatform.findTransformer(result.type);
const challenge = transformer.newChallenge(result);

return challenge;
}
};

export const create = async ({
title,
Expand Down
15 changes: 6 additions & 9 deletions app/challenges-platform/services/participants-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Result<Participant, Error>> => {

const result = await db
.select()
.from(participants)
Expand All @@ -42,18 +41,16 @@ export const findById = async (
const participant = await convert(result[0]);

return Ok(participant);
}
};

export const convert = async (
result: any,
): Promise<Participant> => {
export const convert = async (result: any): Promise<Participant> => {
const participant = new Participant({
id: result.id,
uuid: result.uuid,
email: result.email,
});
return participant;
}
};

export const findByEmail = async (
email?: string,
Expand Down
12 changes: 9 additions & 3 deletions app/challenges-platform/services/submissions-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
26 changes: 13 additions & 13 deletions test/challenges-platform/factories/accessible-challenge-factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ import { db } from "../../../db";
import { accessibleChallenges } from "../../../db/schema";

export const accessibleChallengeFactory = async ({
challenge,
participant,
}: {
challenge?: Challenge;
participant?: Participant;
} = {}): Promise<Number> => {
const c = challenge || (await challengeFactory());
const p = participant || (await participantFactory());
challenge,
participant,
}: {
challenge?: Challenge;
participant?: Participant;
} = {}): Promise<Number> => {
const c = challenge || (await challengeFactory());
const p = participant || (await participantFactory());

const insertResult = await db
const insertResult = await db
.insert(accessibleChallenges)
.values({
challengeId: c.id,
participantId: p.id,
})
.returning();

const result = await AccessibleChallengesService.count(c, p);
if (!result.ok) fail("Expected result to be Ok");
return result.val;
};
const result = await AccessibleChallengesService.count(c, p);
if (!result.ok) fail("Expected result to be Ok");
return result.val;
};
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
});
});
})
});
});
});
4 changes: 2 additions & 2 deletions test/challenges-platform/services/challenges-service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -63,7 +63,7 @@ describe("ChallengesService", () => {
expect(result.val.toString()).toBe("Error: Challenge not found");
});
});
});
});

describe("create", () => {
it("succesfully creates a challenge", async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 9d1a6c7

Please sign in to comment.