nameRequestController: prevent submitting the same name twice

This commit is contained in:
Alex Gleason 2024-06-13 19:11:59 -05:00
parent 75c165371a
commit d06cafd0dd
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 9 additions and 0 deletions

View File

@ -69,8 +69,17 @@ const nameRequestSchema = z.object({
}); });
export const nameRequestController: AppController = async (c) => { export const nameRequestController: AppController = async (c) => {
const store = await Storages.db();
const signer = c.get('signer')!;
const pubkey = await signer.getPublicKey();
const { name, reason } = nameRequestSchema.parse(await c.req.json()); const { name, reason } = nameRequestSchema.parse(await c.req.json());
const [existing] = await store.query([{ kinds: [3036], authors: [pubkey], '#r': [name], limit: 1 }]);
if (existing) {
return c.json({ error: 'Name request already exists' }, 400);
}
const event = await createEvent({ const event = await createEvent({
kind: 3036, kind: 3036,
content: reason, content: reason,