-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add assign judge method to submissions
- Loading branch information
Showing
16 changed files
with
232 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export class Judge { | ||
id: number; | ||
uuid: string; | ||
|
||
constructor({ id, uuid }: { id: number; uuid: string }) { | ||
this.id = id; | ||
this.uuid = uuid; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,31 @@ | ||
import { Challenge } from "./Challenge"; | ||
import { Participant } from "./Participant"; | ||
import { Judge } from "./Judge"; | ||
|
||
export class Submission { | ||
id: number; | ||
uuid: string; | ||
challenge: Challenge; | ||
participant: Participant; | ||
assignee: Judge | null; | ||
|
||
constructor({ | ||
id, | ||
uuid, | ||
challenge, | ||
participant, | ||
assignee, | ||
}: { | ||
id: number; | ||
uuid: string; | ||
challenge: Challenge; | ||
participant: Participant; | ||
assignee: Judge | null; | ||
}) { | ||
this.id = id; | ||
this.uuid = uuid; | ||
this.challenge = challenge; | ||
this.participant = participant; | ||
this.assignee = assignee; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import { eq } from "drizzle-orm"; | ||
import { Ok, Err, Result } from "ts-results"; | ||
import { db } from "../../../db"; | ||
import { judges } from "../../../db/schema"; | ||
import { uuid } from "../../../app/common"; | ||
import { Judge } from "../models"; | ||
|
||
export const findByUuid = async (id: string): Promise<Result<Judge, Error>> => { | ||
if (!uuid.isValid(id)) { | ||
return Err(new Error("Invalid UUID")); | ||
} | ||
|
||
const result = await db.select().from(judges).where(eq(judges.uuid, id)); | ||
|
||
if (result.length === 0) { | ||
return Err(new Error("Judge not found")); | ||
} | ||
|
||
const record = result[0]; | ||
const judge = new Judge({ | ||
id: record.id, | ||
uuid: record.uuid, | ||
}); | ||
|
||
return Ok(judge); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { db } from "../../../db"; | ||
import { judges } from "../../../db/schema"; | ||
import { uuid } from "../../../app/common"; | ||
import { Judge } from "../../../app/challenges-platform/models"; | ||
|
||
export const judgeFactory = async (): Promise<Judge> => { | ||
const insertResult = await db | ||
.insert(judges) | ||
.values({ | ||
uuid: uuid.create(), | ||
}) | ||
.returning(); | ||
|
||
const judge = new Judge({ | ||
id: insertResult[0].id, | ||
uuid: insertResult[0].uuid, | ||
}); | ||
|
||
return judge; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { JudgesService } from "../../../app/challenges-platform"; | ||
import { judgeFactory } from "../factories/judge-factory"; | ||
import { uuid } from "../../../app/common"; | ||
|
||
describe("JudgesService", () => { | ||
describe("findByUuid", () => { | ||
describe("when the id is invalid", () => { | ||
it("returns an error", async () => { | ||
const result = await JudgesService.findByUuid("invalid-id"); | ||
|
||
expect(result.err).toBe(true); | ||
expect(result.val.toString()).toBe("Error: Invalid UUID"); | ||
}); | ||
}); | ||
|
||
describe("when there is no record", () => { | ||
it("returns an error", async () => { | ||
const testUuid = uuid.create(); | ||
const result = await JudgesService.findByUuid(testUuid); | ||
|
||
expect(result.err).toBe(true); | ||
expect(result.val.toString()).toBe("Error: Judge not found"); | ||
}); | ||
}); | ||
|
||
describe("when there is an existing record", () => { | ||
it("returns the judge", async () => { | ||
const judge = await judgeFactory(); | ||
const result = await JudgesService.findByUuid(judge.uuid); | ||
|
||
if (!result.ok) fail("Expected result to be Ok"); | ||
expect(result.val.uuid).toBe(judge.uuid); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.