MCPcopy
hub / github.com/directus/directus / readByQuery

Method readByQuery

api/src/services/collections.ts:324–409  ·  view source on GitHub ↗

* Read all collections. Currently doesn't support any query.

()

Source from the content-addressed store, hash-verified

322 * Read all collections. Currently doesn't support any query.
323 */
324 async readByQuery(): Promise<Collection[]> {
325 const env = useEnv();
326
327 const collectionsItemsService = new ItemsService('directus_collections', {
328 knex: this.knex,
329 schema: this.schema,
330 accountability: this.accountability,
331 });
332
333 let tablesInDatabase = await this.schemaInspector.tableInfo();
334
335 let meta = (await collectionsItemsService.readByQuery({
336 limit: -1,
337 })) as BaseCollectionMeta[];
338
339 meta.push(...systemCollectionRows);
340
341 if (this.accountability && this.accountability.admin !== true) {
342 const collectionsGroups: { [key: string]: string } = meta.reduce(
343 (meta, item) => ({
344 ...meta,
345 [item.collection]: item.group,
346 }),
347 {},
348 );
349
350 let collectionsYouHavePermissionToRead = await fetchAllowedCollections(
351 {
352 accountability: this.accountability,
353 action: 'read',
354 },
355 {
356 knex: this.knex,
357 schema: this.schema,
358 },
359 );
360
361 for (const collection of collectionsYouHavePermissionToRead) {
362 const group = collectionsGroups[collection];
363 if (group) collectionsYouHavePermissionToRead.push(group);
364 delete collectionsGroups[collection];
365 }
366
367 collectionsYouHavePermissionToRead = [...new Set([...collectionsYouHavePermissionToRead])];
368
369 tablesInDatabase = tablesInDatabase.filter((table) => {
370 return collectionsYouHavePermissionToRead.includes(table.name);
371 });
372
373 meta = meta.filter((collectionMeta) => {
374 return collectionsYouHavePermissionToRead.includes(collectionMeta.collection);
375 });
376 }
377
378 const collections: Collection[] = [];
379
380 for (const collectionMeta of meta) {
381 const collection: Collection = {

Callers 8

getSnapshotFunction · 0.95
getActiveCollectionsFunction · 0.95
handlerFunction · 0.95
handlerFunction · 0.95
readManyMethod · 0.95
deleteOneMethod · 0.95
injectSystemResolversFunction · 0.95
getCollectionPayloadFunction · 0.95

Calls 4

readByQueryMethod · 0.95
useEnvFunction · 0.90
fetchAllowedCollectionsFunction · 0.85
tableInfoMethod · 0.65

Tested by

no test coverage detected