This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
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.
feat: added a route for getting a users's country
- Loading branch information
Showing
3 changed files
with
19 additions
and
1 deletion.
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,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; | ||
}; |
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 |
---|---|---|
|
@@ -2,4 +2,5 @@ export interface RegisterBody { | |
email: string; | ||
name: string; | ||
password: string; | ||
country: string; | ||
} |