db/events: don't return `author` unless it exists

This commit is contained in:
Alex Gleason 2023-12-06 13:06:13 -06:00
parent a6947441fc
commit f50a78f978
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
1 changed files with 19 additions and 14 deletions

View File

@ -200,26 +200,31 @@ async function getFilters<K extends number>(
query = query.limit(opts.limit); query = query.limit(opts.limit);
} }
return (await query.execute()).map((row) => ({ return (await query.execute()).map((row) => {
id: row.id, const event: DittoEvent<K> = {
kind: row.kind, id: row.id,
pubkey: row.pubkey, kind: row.kind as K,
content: row.content, pubkey: row.pubkey,
created_at: row.created_at, content: row.content,
tags: JSON.parse(row.tags), created_at: row.created_at,
author: row.author_id tags: JSON.parse(row.tags),
? { sig: row.sig,
};
if (row.author_id) {
event.author = {
id: row.author_id, id: row.author_id,
kind: row.author_kind!, kind: row.author_kind! as 0,
pubkey: row.author_pubkey!, pubkey: row.author_pubkey!,
content: row.author_content!, content: row.author_content!,
created_at: row.author_created_at!, created_at: row.author_created_at!,
tags: JSON.parse(row.author_tags!), tags: JSON.parse(row.author_tags!),
sig: row.author_sig!, sig: row.author_sig!,
} };
: undefined, }
sig: row.sig,
} as DittoEvent<K>)); return event;
});
} }
/** Delete events based on filters from the database. */ /** Delete events based on filters from the database. */