Explorar el Código

feat: Emit generic model updated/deleted event to backend

Owen Diffey hace 1 año
padre
commit
a7d593646b
Se han modificado 1 ficheros con 7 adiciones y 3 borrados
  1. 7 3
      backend/src/modules/DataModule.ts

+ 7 - 3
backend/src/modules/DataModule.ts

@@ -122,11 +122,15 @@ export class DataModule extends BaseModule {
 					if (!modelId && action !== "created")
 						throw new Error(`Model Id not found for "${event}"`);
 
-					let channel = `model.${modelName}.${action}`;
-
-					if (action !== "created") channel += `.${modelId}`;
+					const channel = `model.${modelName}.${action}`;
 
 					await EventsModule.publish(channel, { doc, oldDoc });
+
+					if (action !== "created")
+						await EventsModule.publish(`${channel}.${modelId}`, {
+							doc,
+							oldDoc
+						});
 				});
 			});
 	}