EventsDB: fix the tag queries bug, DVM: remove unnecessary conditional

This commit is contained in:
Alex Gleason 2024-03-26 21:42:17 -05:00
parent 29a63f262f
commit 0fde577149
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
2 changed files with 8 additions and 10 deletions

View File

@ -7,10 +7,6 @@ import { eventsDB } from '@/storages.ts';
export class DVM {
static async event(event: NostrEvent): Promise<void> {
if (event.kind < 5000 || event.kind > 5999) {
throw new Error('Unsupported event kind');
}
switch (event.kind) {
case 5950:
await DVM.nameRegistration(event);

View File

@ -181,13 +181,15 @@ class EventsDB implements NStore {
query = query.limit(filter.limit!);
break;
}
}
if (key.startsWith('#')) {
const tag = key.replace(/^#/, '');
const value = filter[key as `#${string}`] as string[];
query = query
.leftJoin('tags', 'tags.event_id', 'events.id')
.where('tags.tag', '=', tag)
const joinedQuery = query.leftJoin('tags', 'tags.event_id', 'events.id');
for (const [key, value] of Object.entries(filter)) {
if (key.startsWith('#') && Array.isArray(value)) {
const name = key.replace(/^#/, '');
query = joinedQuery
.where('tags.tag', '=', name)
.where('tags.value', 'in', value);
}
}