core: publish database updated event on relations unlink

This commit is contained in:
Abdullah Atta
2024-03-14 09:55:01 +05:00
parent 90e48cbc16
commit 9dff23bdd5

View File

@@ -19,13 +19,20 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
import { makeId } from "../utils/id";
import { ICollection } from "./collection";
import { Relation, ItemMap, ItemReference, ValueOf, ItemType } from "../types";
import {
Relation,
ItemMap,
ItemReference,
ItemReferences,
ValueOf,
UnlinkEvent
} from "../types";
import Database from "../api";
import { FilteredSelector, SQLCollection } from "../database/sql-collection";
import { DatabaseSchema, isFalse } from "../database";
import { SelectQueryBuilder } from "kysely";
import { EVENTS } from "../common";
type ItemReferences = { type: ItemType; ids: string[] };
export class Relations implements ICollection {
name = "relations";
readonly collection: SQLCollection<"relations", Relation>;
@@ -167,6 +174,21 @@ export class Relations implements ICollection {
])
)
.execute();
this.db.eventManager.publish(EVENTS.databaseUpdated, <UnlinkEvent>{
collection: "relations",
type: "unlink",
reference: { type: type, ids: ids || [] },
direction: "from",
types: Object.keys(TABLE_MAP)
});
this.db.eventManager.publish(EVENTS.databaseUpdated, <UnlinkEvent>{
collection: "relations",
type: "unlink",
reference: { type: type, ids: ids || [] },
direction: "to",
types: Object.keys(TABLE_MAP)
});
}
}
@@ -257,6 +279,14 @@ class RelationsArray<TType extends keyof RelatableTable> {
])
)
.execute();
this.db.eventManager.publish(EVENTS.databaseUpdated, <UnlinkEvent>{
collection: "relations",
type: "unlink",
reference: this.reference,
direction: this.direction,
types: this.types
});
}
async get() {