refactor(updateInstanceController): move async function out of callback

This commit is contained in:
P. Reis 2024-11-15 11:20:10 -03:00
parent 33b36ba0ed
commit d9cc8cc7c2
2 changed files with 5 additions and 4 deletions

View file

@ -311,10 +311,11 @@ export const updateInstanceController: AppController = async (c) => {
return c.json(result.error, 422); return c.json(result.error, 422);
} }
const meta = await getInstanceMetadata(await Storages.db(), c.req.raw.signal);
await updateAdminEvent( await updateAdminEvent(
{ kinds: [0], authors: [pubkey], limit: 1 }, { kinds: [0], authors: [pubkey], limit: 1 },
async (_) => { (_) => {
const meta = await getInstanceMetadata(await Storages.db(), c.req.raw.signal);
const { const {
title, title,
description, description,

View file

@ -111,12 +111,12 @@ function updateListAdminEvent(
/** Fetch existing event, update it, then publish the new admin event. */ /** Fetch existing event, update it, then publish the new admin event. */
async function updateAdminEvent<E extends EventStub>( async function updateAdminEvent<E extends EventStub>(
filter: UpdateEventFilter, filter: UpdateEventFilter,
fn: (prev: NostrEvent | undefined) => E | Promise<E>, fn: (prev: NostrEvent | undefined) => E,
c: AppContext, c: AppContext,
): Promise<NostrEvent> { ): Promise<NostrEvent> {
const store = await Storages.db(); const store = await Storages.db();
const [prev] = await store.query([filter], { limit: 1, signal: c.req.raw.signal }); const [prev] = await store.query([filter], { limit: 1, signal: c.req.raw.signal });
return createAdminEvent(await fn(prev), c); return createAdminEvent(fn(prev), c);
} }
function updateUser(pubkey: string, n: Record<string, boolean>, c: AppContext): Promise<NostrEvent> { function updateUser(pubkey: string, n: Record<string, boolean>, c: AppContext): Promise<NostrEvent> {