Skip to content
This repository has been archived by the owner on Jul 31, 2024. It is now read-only.

Commit

Permalink
feat: added textid column to games table
Browse files Browse the repository at this point in the history
  • Loading branch information
vycdev committed Jul 16, 2020
1 parent e661bc6 commit 4a72b79
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 16 deletions.
16 changes: 16 additions & 0 deletions packages/api/db/migrations/20200716182727_add_text_id_to_games.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import Knex from "knex";

export const up = async (knex: Knex) => {
return knex.schema.alterTable("games", table => {
table
.integer("textid")
.notNullable()
.defaultTo(11);
});
};

export const down = async (knex: Knex) => {
return knex.schema.alterTable("games", table => {
return table.dropColumn("textid");
});
};
4 changes: 3 additions & 1 deletion packages/api/src/modules/games/actions/createGame.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ export const createGame = async (
wpm: number,
rawwpm: number,
accuracy: number,
difficulty: number
difficulty: number,
textid: number
): Promise<Game> => {
const newGame = {
gameid: (await highestGameId()) + 1,
Expand All @@ -19,6 +20,7 @@ export const createGame = async (
rawwpm,
accuracy,
difficulty,
textid,
date: Date.now()
};
const possibleAchievements: Achievement[] = await findAchievementsByRequirement(
Expand Down
26 changes: 13 additions & 13 deletions packages/api/src/modules/games/router.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@ describe("Game routes", async () => {
it("Deletes games past 10 games", async function() {
this.timeout(5000);

await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);
await createGame(4, 0, 0, 0, 1, 11);

await Promise.all([
removeOldGame(4),
Expand All @@ -67,7 +67,7 @@ describe("Game routes", async () => {
});

it("Checks for achievements", async () => {
await createGame(4, 32, 40, 80, 5);
await createGame(4, 32, 40, 80, 5, 11);
await removeOldGame(4);

const achievements = await agent.get("/api/users/achievements/4");
Expand Down
5 changes: 3 additions & 2 deletions packages/api/src/modules/games/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ router.post(
requireAuthenticated(),
validateSchema(newGameBody, "body"),
async (ctx, next) => {
const { wpm, rawwpm, accuracy, difficulty } = ctx.request.body;
const { wpm, rawwpm, accuracy, difficulty, textid } = ctx.request.body;
const { user } = ctx.session!;
const newGame = await createGame(
user,
wpm,
rawwpm,
accuracy,
difficulty
difficulty,
textid
);
await removeOldGame(user);
await checkPB(newGame);
Expand Down

0 comments on commit 4a72b79

Please sign in to comment.