Add items.read filter hook (#10284)

* Add items.read filter hook

* Fix issue cause by query being wrongly modified

Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
This commit is contained in:
Oreille
2021-12-03 19:36:49 +01:00
committed by GitHub
parent ebbbdf6a5c
commit 52deb28fc2

View File

@@ -292,6 +292,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
`${this.eventScope}.read`,
records,
{
query,
collection: this.collection,
},
{
@@ -325,7 +326,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
const primaryKeyField = this.schema.collections[this.collection].primary;
const filterWithKey = assign({}, query.filter, { [primaryKeyField]: { _eq: key } });
const queryWithKey = assign(query, { filter: filterWithKey });
const queryWithKey = assign({}, query, { filter: filterWithKey });
const results = await this.readByQuery(queryWithKey, opts);
@@ -343,7 +344,7 @@ export class ItemsService<Item extends AnyItem = AnyItem> implements AbstractSer
const primaryKeyField = this.schema.collections[this.collection].primary;
const filterWithKey = { _and: [{ [primaryKeyField]: { _in: keys } }, query.filter ?? {}] };
const queryWithKey = assign(query, { filter: filterWithKey });
const queryWithKey = assign({}, query, { filter: filterWithKey });
const results = await this.readByQuery(queryWithKey, opts);