diff --git a/packages/api/db/migrations/20200608182453_create_users_table.ts b/packages/api/db/migrations/20200608182453_create_users_table.ts index 60be638..8b1cc1c 100644 --- a/packages/api/db/migrations/20200608182453_create_users_table.ts +++ b/packages/api/db/migrations/20200608182453_create_users_table.ts @@ -6,7 +6,8 @@ export const up = async (knex: Knex) => { table.string("name").notNullable(); table.string("email").notNullable(); table.string("password").notNullable(); - table.string("role"); + table.string("role").notNullable(); + table.integer("rank").notNullable(); table.string("description"); }); }; diff --git a/packages/api/db/migrations/20200705082902_create_games_table.ts b/packages/api/db/migrations/20200705082902_create_games_table.ts new file mode 100644 index 0000000..ab2e5d2 --- /dev/null +++ b/packages/api/db/migrations/20200705082902_create_games_table.ts @@ -0,0 +1,16 @@ +import Knex from "knex"; + +export const up = async (knex: Knex) => { + return knex.schema.createTable("games", table => { + table.integer("gameid").notNullable(); + table.integer("userid").notNullable(); + table.integer("date").notNullable(); + table.integer("wpm").notNullable(); + table.integer("uncorrectedwpm").notNullable(); + table.integer("accuracy").notNullable(); + }); +}; + +export const down = async (knex: Knex) => { + return knex.schema.dropTable("games"); +}; diff --git a/packages/api/db/seeds/examples/users.ts b/packages/api/db/seeds/examples/users.ts index 1f6b8ad..9f8e1d9 100644 --- a/packages/api/db/seeds/examples/users.ts +++ b/packages/api/db/seeds/examples/users.ts @@ -4,6 +4,7 @@ interface Users { password: string; role?: string | null; description?: string | null; + rank: number; } export default [ @@ -12,27 +13,31 @@ export default [ email: "UserUser@fake.com", password: "UserPass", role: "admin", - description: null + description: null, + rank: 8 }, { name: "MKGUN3", email: "Deliver@bullets.com", password: "MaoGay", - role: null, - description: null + role: "member", + description: null, + rank: 4 }, { name: "NotAUser", email: "none@nope.com", password: "nothing", - role: null, - description: null + role: "member", + description: null, + rank: 2 }, { name: "Guy2", email: "Guy2@fake.com", password: "JustAGuy", - role: null, - description: "But hey, I have a description!" + role: "member", + description: "But hey, I have a description!", + rank: 0 } ] as readonly Users[]; diff --git a/packages/api/src/modules/users/actions/createUser.ts b/packages/api/src/modules/users/actions/createUser.ts index 4dbe274..80a023c 100644 --- a/packages/api/src/modules/users/actions/createUser.ts +++ b/packages/api/src/modules/users/actions/createUser.ts @@ -19,7 +19,9 @@ export const createUser = async ( await knex("users").insert( { ...user, - password: encryptedPassword + role: "member", + password: encryptedPassword, + rank: 0 }, "*" ) diff --git a/packages/api/src/modules/users/types/PreviousUserGame.ts b/packages/api/src/modules/users/types/PreviousUserGame.ts deleted file mode 100644 index 09786df..0000000 --- a/packages/api/src/modules/users/types/PreviousUserGame.ts +++ /dev/null @@ -1,6 +0,0 @@ -export default interface PreviousUserGame { - date: string; - wpm: number; - uncorrectedwpm: number; - accuracy: number; -} diff --git a/packages/api/src/modules/users/types/User.ts b/packages/api/src/modules/users/types/User.ts index 74741c4..edc6d4b 100644 --- a/packages/api/src/modules/users/types/User.ts +++ b/packages/api/src/modules/users/types/User.ts @@ -3,6 +3,7 @@ export default interface User { email: string; name: string; password: string; + rank: number; role?: string | null; description?: string | null; }