mirror of
https://github.com/aljazceru/ditto.git
synced 2026-01-16 11:54:28 +01:00
feat: create deleteZapSplitsController
This commit is contained in:
@@ -12,6 +12,7 @@ import { renderNameRequest } from '@/views/ditto.ts';
|
||||
import { getZapSplits } from '@/utils/zap_split.ts';
|
||||
import { updateListAdminEvent } from '@/utils/api.ts';
|
||||
import { addTag } from '@/utils/tags.ts';
|
||||
import { deleteTag } from '@/utils/tags.ts';
|
||||
|
||||
const markerSchema = z.enum(['read', 'write']);
|
||||
|
||||
@@ -181,3 +182,33 @@ export const updateZapSplitsController: AppController = async (c) => {
|
||||
|
||||
return c.json(200);
|
||||
};
|
||||
|
||||
const deleteZapSplitSchema = z.array(n.id()).min(1);
|
||||
|
||||
export const deleteZapSplitsController: AppController = async (c) => {
|
||||
const body = await parseBody(c.req.raw);
|
||||
const result = deleteZapSplitSchema.safeParse(body);
|
||||
const store = c.get('store');
|
||||
|
||||
if (!result.success) {
|
||||
return c.json({ error: result.error }, 400);
|
||||
}
|
||||
|
||||
const zap_split = await getZapSplits(store, Conf.pubkey);
|
||||
if (!zap_split) {
|
||||
return c.json({ error: 'Zap split not activated, visit `/api/v1/instance` to activate it.' }, 404);
|
||||
}
|
||||
|
||||
const { data } = result;
|
||||
|
||||
await updateListAdminEvent(
|
||||
{ kinds: [30078], authors: [Conf.pubkey], '#d': ['pub.ditto.zapSplits'], limit: 1 },
|
||||
(tags) =>
|
||||
data.reduce((accumulator, currentValue) => {
|
||||
return deleteTag(accumulator, ['p', currentValue]);
|
||||
}, tags),
|
||||
c,
|
||||
);
|
||||
|
||||
return c.json(200);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user