MCPcopy
hub / github.com/directus/directus / readOne

Method readOne

api/src/services/items.ts:613–628  ·  view source on GitHub ↗

* Get single item by primary key. * * Uses `this.readByQuery` under the hood.

(key: PrimaryKey, query: Query = {}, opts?: QueryOptions)

Source from the content-addressed store, hash-verified

611 * Uses `this.readByQuery` under the hood.
612 */
613 async readOne(key: PrimaryKey, query: Query = {}, opts?: QueryOptions): Promise<Item> {
614 const primaryKeyField = this.schema.collections[this.collection]!.primary;
615
616 validateKeys(this.schema, this.collection, primaryKeyField, key);
617
618 const filterWithKey = assign({}, query.filter, { [primaryKeyField]: { _eq: key } });
619 const queryWithKey = assign({}, query, { filter: filterWithKey });
620
621 const results: Item[] = await this.readByQuery(queryWithKey, { ...opts, key });
622
623 if (results.length === 0) {
624 throw new ForbiddenError();
625 }
626
627 return results[0]!;
628 }
629
630 /**
631 * Get multiple items by primary keys.

Callers 5

collectionsCallbackFunction · 0.95
getMainItemMethod · 0.95
writeMethod · 0.95
onUploadFinishFunction · 0.95
onMessageMethod · 0.95

Calls 2

readByQueryMethod · 0.95
validateKeysFunction · 0.85

Tested by

no test coverage detected