MCPcopy Create free account
hub / github.com/cameri/nostream / upsertVanishState

Method upsertVanishState

src/repositories/user-repository.ts:75–102  ·  view source on GitHub ↗
(pubkey: Pubkey, isVanished: boolean, client: DatabaseClient)

Source from the content-addressed store, hash-verified

73 }
74
75 private upsertVanishState(pubkey: Pubkey, isVanished: boolean, client: DatabaseClient): Promise<number> {
76 logger('upsert vanish state for %s: %o', pubkey, isVanished)
77 const date = new Date()
78
79 const query = client<DBUser>('users')
80 .insert({
81 pubkey: toBuffer(pubkey),
82 is_admitted: false,
83 balance: 0n,
84 is_vanished: isVanished,
85 created_at: date,
86 updated_at: date,
87 })
88 .onConflict('pubkey')
89 .merge({
90 is_vanished: isVanished,
91 updated_at: date,
92 })
93
94 return {
95 then: <T1, T2>(
96 onfulfilled: (value: number) => T1 | PromiseLike<T1>,
97 onrejected: (reason: any) => T2 | PromiseLike<T2>,
98 ) => query.then(prop('rowCount') as () => number).then(onfulfilled, onrejected),
99 catch: <T>(onrejected: (reason: any) => T | PromiseLike<T>) => query.catch(onrejected),
100 toString: (): string => query.toString(),
101 } as Promise<number>
102 }
103
104 public async getBalanceByPubkey(pubkey: Pubkey, client: DatabaseClient = this.dbClient): Promise<bigint> {
105 logger('get balance for pubkey: %s', pubkey)

Callers 2

isVanishedMethod · 0.95
setVanishedMethod · 0.95

Calls 3

toBufferFunction · 0.90
insertMethod · 0.80
toStringMethod · 0.80

Tested by

no test coverage detected