mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
refactor: change zapSplitSchema to z.record())
This commit is contained in:
parent
85806f7ea8
commit
f94ae7606c
1 changed files with 14 additions and 7 deletions
|
|
@ -153,11 +153,13 @@ export const nameRequestsController: AppController = async (c) => {
|
||||||
return paginated(c, orig, nameRequests);
|
return paginated(c, orig, nameRequests);
|
||||||
};
|
};
|
||||||
|
|
||||||
const zapSplitSchema = z.array(z.object({
|
const zapSplitSchema = z.record(
|
||||||
pubkey: n.id(),
|
n.id(),
|
||||||
|
z.object({
|
||||||
amount: z.number().int().min(1).max(100),
|
amount: z.number().int().min(1).max(100),
|
||||||
message: z.string().max(500),
|
message: z.string().max(500),
|
||||||
})).min(1);
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
export const updateZapSplitsController: AppController = async (c) => {
|
export const updateZapSplitsController: AppController = async (c) => {
|
||||||
const body = await parseBody(c.req.raw);
|
const body = await parseBody(c.req.raw);
|
||||||
|
|
@ -174,12 +176,17 @@ export const updateZapSplitsController: AppController = async (c) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const { data } = result;
|
const { data } = result;
|
||||||
|
const pubkeys = Object.keys(data);
|
||||||
|
|
||||||
|
if (pubkeys.length < 1) {
|
||||||
|
return c.json(200);
|
||||||
|
}
|
||||||
|
|
||||||
await updateListAdminEvent(
|
await updateListAdminEvent(
|
||||||
{ kinds: [30078], authors: [Conf.pubkey], '#d': ['pub.ditto.zapSplits'], limit: 1 },
|
{ kinds: [30078], authors: [Conf.pubkey], '#d': ['pub.ditto.zapSplits'], limit: 1 },
|
||||||
(tags) =>
|
(tags) =>
|
||||||
data.reduce((accumulator, currentValue) => {
|
pubkeys.reduce((accumulator, pubkey) => {
|
||||||
return addTag(accumulator, ['p', currentValue.pubkey, currentValue.amount.toString(), currentValue.message]);
|
return addTag(accumulator, ['p', pubkey, data[pubkey].amount.toString(), data[pubkey].message]);
|
||||||
}, tags),
|
}, tags),
|
||||||
c,
|
c,
|
||||||
);
|
);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue