fix(updateInstanceController): use updateAdminEvent() function

This commit is contained in:
P. Reis 2024-11-15 11:08:47 -03:00
parent 1baab0f868
commit 33b36ba0ed
2 changed files with 4 additions and 4 deletions

View file

@ -5,7 +5,7 @@ import { AppController } from '@/app.ts';
import { Conf } from '@/config.ts'; import { Conf } from '@/config.ts';
import { addTag } from '@/utils/tags.ts'; import { addTag } from '@/utils/tags.ts';
import { getAuthor } from '@/queries.ts'; import { getAuthor } from '@/queries.ts';
import { createEvent, paginated, parseBody, updateEvent } from '@/utils/api.ts'; import { createEvent, paginated, parseBody, updateAdminEvent } from '@/utils/api.ts';
import { getInstanceMetadata } from '@/utils/instance.ts'; import { getInstanceMetadata } from '@/utils/instance.ts';
import { deleteTag } from '@/utils/tags.ts'; import { deleteTag } from '@/utils/tags.ts';
import { DittoEvent } from '@/interfaces/DittoEvent.ts'; import { DittoEvent } from '@/interfaces/DittoEvent.ts';
@ -311,7 +311,7 @@ export const updateInstanceController: AppController = async (c) => {
return c.json(result.error, 422); return c.json(result.error, 422);
} }
await updateEvent( await updateAdminEvent(
{ kinds: [0], authors: [pubkey], limit: 1 }, { kinds: [0], authors: [pubkey], limit: 1 },
async (_) => { async (_) => {
const meta = await getInstanceMetadata(await Storages.db(), c.req.raw.signal); const meta = await getInstanceMetadata(await Storages.db(), c.req.raw.signal);

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, fn: (prev: NostrEvent | undefined) => E | Promise<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(fn(prev), c); return createAdminEvent(await 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> {