17 lines
553 B
TypeScript
17 lines
553 B
TypeScript
import { UserModel } from "./user";
|
|
import { appEventBus, USER_UPDATED_EVENT } from "../../utils/eventBus";
|
|
|
|
export function watchUserChanges() {
|
|
const changeStream = UserModel.watch([], { fullDocument: "updateLookup" });
|
|
|
|
changeStream.on("change", (change: any) => {
|
|
if (change.operationType === "update" && change.fullDocument) {
|
|
const updatedUser = change.fullDocument;
|
|
|
|
appEventBus.emit(USER_UPDATED_EVENT, updatedUser);
|
|
}
|
|
});
|
|
|
|
console.log("Watching for changes in the User collection...");
|
|
}
|