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);
}
return (await query.execute()).map((row) => ({
return (await query.execute()).map((row) => {
const event: DittoEvent<K> = {
id: row.id,
kind: row.kind,
kind: row.kind as K,
pubkey: row.pubkey,
content: row.content,
created_at: row.created_at,
tags: JSON.parse(row.tags),
author: row.author_id
? {
sig: row.sig,
};
if (row.author_id) {
event.author = {
id: row.author_id,
kind: row.author_kind!,
kind: row.author_kind! as 0,
pubkey: row.author_pubkey!,
content: row.author_content!,
created_at: row.author_created_at!,
tags: JSON.parse(row.author_tags!),
sig: row.author_sig!,
};
}
: undefined,
sig: row.sig,
} as DittoEvent<K>));
return event;
});
}
/** Delete events based on filters from the database. */