nameRequestController: prevent submitting the same name twice
This commit is contained in:
parent
75c165371a
commit
d06cafd0dd
|
@ -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,
|
||||||
|
|
Loading…
Reference in New Issue