* Get single item by primary key. * * Uses `this.readByQuery` under the hood.
(key: PrimaryKey, query: Query = {}, opts?: QueryOptions)
| 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. |
no test coverage detected