From e4952f0c2137ed513e165314c42131f50f800f15 Mon Sep 17 00:00:00 2001 From: "P. Reis" Date: Wed, 8 May 2024 20:10:09 -0300 Subject: [PATCH] feat: create updateListAdminEvent() & updateAdminEvent() --- src/utils/api.ts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/utils/api.ts b/src/utils/api.ts index 72f4c3e5..cba7c663 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -76,6 +76,29 @@ async function createAdminEvent(t: EventStub, c: AppContext): Promise string[][], + c: AppContext, +): Promise { + return updateAdminEvent(filter, (prev) => ({ + kind: filter.kinds[0], + content: prev?.content ?? '', + tags: fn(prev?.tags ?? []), + }), c); +} + +/** Fetch existing event, update it, then publish the new admin event. */ +async function updateAdminEvent( + filter: UpdateEventFilter, + fn: (prev: NostrEvent | undefined) => E, + c: AppContext, +): Promise { + const [prev] = await Storages.db.query([filter], { limit: 1, signal: c.req.raw.signal }); + return createAdminEvent(fn(prev), c); +} + /** Push the event through the pipeline, rethrowing any RelayError. */ async function publishEvent(event: NostrEvent, c: AppContext): Promise { debug('EVENT', event); @@ -185,5 +208,6 @@ export { paginationSchema, parseBody, updateEvent, + updateListAdminEvent, updateListEvent, };