diff --git a/packages/cqrs/src/event-bus.ts b/packages/cqrs/src/event-bus.ts index d2e68c1ef..8f9dccf13 100644 --- a/packages/cqrs/src/event-bus.ts +++ b/packages/cqrs/src/event-bus.ts @@ -4,7 +4,6 @@ import { Subject } from "rxjs" import type { Class } from "type-fest" import { EVENT_HANDLER_METADATA, EVENT_METADATA } from "./decorators/constants" import { DefaultEventPubSub } from "./default-event-publisher" -import { EventHandlerNotFoundException } from "./exceptions/event-handler-not-found.exception" import { InvalidEventHandlerException } from "./exceptions/invalid-event-handler.exception" export type EventHandlerType = Class> @@ -17,8 +16,11 @@ export class EventBus implements IEventBus #handlers = new Map>() async publish(event: TEvent): Promise { - console.log("publish event", event) const eventId = this.getEventId(event) + if (!eventId) { + return + } + const handler = this.#handlers.get(eventId) if (!handler) { return @@ -57,11 +59,11 @@ export class EventBus implements IEventBus return eventMetadata.id } - private getEventId(event: TEvent): string { + private getEventId(event: TEvent): string | undefined { const { constructor: eventType } = Object.getPrototypeOf(event) const eventMetadata: EventMetadata = Reflect.getMetadata(EVENT_METADATA, eventType) if (!eventMetadata) { - throw new EventHandlerNotFoundException(eventType.name) + return } return eventMetadata.id } diff --git a/packages/table/src/modules/views/view/view-fields/view-fields.vo.ts b/packages/table/src/modules/views/view/view-fields/view-fields.vo.ts index 68c9a293b..efe3efcfe 100644 --- a/packages/table/src/modules/views/view/view-fields/view-fields.vo.ts +++ b/packages/table/src/modules/views/view/view-fields/view-fields.vo.ts @@ -15,16 +15,26 @@ export type IViewFields = z.infer export class ViewFields extends ValueObject { constructor(table: TableDo, props: IViewFields) { - const fields = table.schema.fields.map((field) => { - const exists = props.find((f) => f.fieldId === field.id.value) - if (exists) { - return exists + const fields = props.map((prop) => { + const field = table.schema.getFieldByIdOrName(prop.fieldId) + if (field) { + return prop } return { - fieldId: field.id.value, - hidden: false, + fieldId: prop.fieldId, + hidden: true, } }) + + table.schema.fields.forEach((field) => { + if (!fields.some((f) => f.fieldId === field.id.value)) { + fields.push({ + fieldId: field.id.value, + hidden: false, + }) + } + }) + super(fields) }