import type { PoolRecord , PoolRecordInDatabase } from '../types' ; import { ITO_PluginID } from '../constants' ; import { createPluginDatabase } from '../../../database/Plugin' ; import { omit } from 'lodash-unified' ; export const PoolDatabase = createPluginDatabase < PoolRecordInDatabase > ( ITO_PluginID ) ; export async function getAllPoolsAsSeller ( ids ) { const records = [ ] ; for await ( const { value : record } of PoolDatabase . iterate ( 'ito-pool' ) ) { if ( ids . includes ( record . payload . pid ) ) records . push ( PoolRecordOutDB ( record ) ) ; } return records ; } export async function getPoolFromDB ( id ) { const record = await PoolDatabase . get ( 'ito-pool' , id ) ; return record ? PoolRecordOutDB ( record ) : undefined ; } export async function addPoolIntoDB ( record ) { if ( await PoolDatabase . has ( 'ito-pool' , record . id ) ) return ; return PoolDatabase . add ( PoolRecordIntoDB ( record ) ) ; } export function removePoolFromDB ( id ) { return PoolDatabase . remove ( 'ito-pool' , id ) ; } function PoolRecordIntoDB ( x ) { const record = x as PoolRecordInDatabase ; record . type = 'ito-pool' ; return record ; } function PoolRecordOutDB ( x ) { const record = x ; return omit ( record , [ 'type' ] ) ; }