MCPcopy Create free account
hub / github.com/directus/directus / getKeysByQuery

Method getKeysByQuery

api/src/services/items.ts:107–122  ·  view source on GitHub ↗
(query: Query)

Source from the content-addressed store, hash-verified

105 }
106
107 async getKeysByQuery(query: Query): Promise<PrimaryKey[]> {
108 const primaryKeyField = this.schema.collections[this.collection]!.primary;
109 const readQuery = cloneDeep(query);
110 readQuery.fields = [primaryKeyField];
111
112 // Allow unauthenticated access
113 const itemsService = new ItemsService(this.collection, {
114 knex: this.knex,
115 schema: this.schema,
116 });
117
118 // We read the IDs of the items based on the query, and then run `updateMany`. `updateMany` does it's own
119 // permissions check for the keys, so we don't have to make this an authenticated read
120 const items = await itemsService.readByQuery(readQuery);
121 return items.map((item: AnyItem) => item[primaryKeyField]).filter((pk) => pk);
122 }
123
124 /**
125 * Create a single new item.

Callers 2

updateByQueryMethod · 0.95
deleteByQueryMethod · 0.95

Calls 1

readByQueryMethod · 0.95

Tested by

no test coverage detected