This repository was archived by the owner on Sep 4, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +22
-1
lines changed
Expand file tree Collapse file tree 1 file changed +22
-1
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export function userToJSON(user: User): UserJSON {
1919export async function getUsersCountWithEmail ( email : string ) {
2020 const total = ( await global . db < User > ( "users" )
2121 . where ( "email" , email )
22- . count ( "*" , { as : "total" } )
22+ . count ( "*" , { as : "total" } )
2323 ) [ 0 ] . total ;
2424 return Number ( total ) ;
2525}
@@ -43,4 +43,25 @@ export async function saveUser(user: User) {
4343 return getUserByID ( insertId [ 0 ] ) as User ;
4444}
4545
46+ export async function checkUserForAuthToken ( userId : number , token : string ) {
47+ const total = ( await global . db ( "user_auth_tokens" )
48+ . where ( "user_id" , userId )
49+ . where ( "token" , token )
50+ . count ( "*" , { as : "total" } )
51+ ) [ 0 ] . total ;
52+ return Number ( total ) != 0 ;
53+ }
54+
55+ export async function addUserAuthToken ( userId : number , token : string ) {
56+ if ( await checkUserForAuthToken ( userId , token ) ) {
57+ throw new Error ( "User already has this auth token." ) ;
58+ }
59+
60+ const insertId = await global . db ( "user_auth_tokens" ) . insert ( {
61+ user_id : userId ,
62+ token
63+ } ) ;
64+ return insertId . length == 1 ;
65+ }
66+
4667export default ( ) => global . db < User > ( "users" ) ;
You can’t perform that action at this time.
0 commit comments