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

Commit

Permalink
feat: added a route for getting a users's country
Browse files Browse the repository at this point in the history
  • Loading branch information
vycdev committed Jul 11, 2020
1 parent 526281c commit f05661d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/api/src/modules/users/actions/createUser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import bcrypt from "bcrypt";
import User from "../types/User";

export const createUser = async (
user: Pick<User, "email" | "name" | "password">
user: Pick<User, "email" | "name" | "password" | "country">
) => {
const isTaken = Boolean(
await knex<User>("users")
Expand Down
17 changes: 17 additions & 0 deletions packages/api/src/modules/users/actions/userCountry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import User from "../types/User";
import knex from "../../../../db/knex";

export default async <T extends keyof Omit<User, "password">>(
property: T,
value: User[T]
) => {
if (!property || !value) return null;
const result = await knex<User>("users")
.select()
.first()
.where({ [property]: value });
if (!result) return null;

const userCountry = result.country;
return userCountry;
};
1 change: 1 addition & 0 deletions packages/api/src/modules/users/types/RegisterBody.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ export interface RegisterBody {
email: string;
name: string;
password: string;
country: string;
}

0 comments on commit f05661d

Please sign in to comment.