import { Kysely } from 'kysely' ; import { Database } from '../database' ; import { RefreshTokenRow , UpdateableRefreshTokenRow , } from './refresh-token.table' ; export async function insertRefreshToken ( db , userId ) { const [ refreshToken ] = await db . insertInto ( 'refresh_token' ) . values ( { user_id : userId , last_refreshed_at : new Date ( ) , } ) . returningAll ( ) . execute ( ) ; return refreshToken ; } export async function findRefreshToken ( db , userId , refreshTokenId ) { const token = await db . selectFrom ( 'refresh_token as rt' ) . selectAll ( 'rt' ) . innerJoin ( 'user as u' , 'rt.user_id' , 'u.user_id' ) . where ( 'u.user_id' , '=' , userId ) . where ( 'rt.refresh_token_id' , '=' , refreshTokenId ) . executeTakeFirst ( ) ; return token ; } export async function updateRefreshToken ( db , refreshTokenId , patch ) { await db . updateTable ( 'refresh_token' ) . set ( patch ) . where ( 'refresh_token_id' , '=' , refreshTokenId ) . execute ( ) ; }