import { getLastNonProxyCheckin , updateCheckin , updateGuest , getCurrentGuest , } from '~lib/db' ; import { QueryClient } from 'react-query' ; import * as db from '../db' ; import * as api from '../api' ; import { encrypt , toCSV } from '../crypto' ; export async function updateCurrentGuest ( queryClient , guest ) { const currentGuest = await getCurrentGuest ( ) ; if ( currentGuest ) { await updateGuest ( guest ) ; } const currentCheckin = await getLastNonProxyCheckin ( ) ; currentCheckin . guest = guest ; const updatedCheckin = await updateCheckin ( currentCheckin ) ; if ( updatedCheckin . k ) { const csv = toCSV ( updatedCheckin . guest ) ; const encryptedData = encrypt ( updatedCheckin . k , csv ) ; await api . patchTicket ( { id : updatedCheckin . id , encryptedData : encryptedData , } ) ; } queryClient . invalidateQueries ( 'checkins' ) ; return updatedCheckin ; }