* Gets an entity by it's `id`. If the entity is not found a rejected promise is returned. * * @example * ```ts * try { * const todoItem = await this.service.getById(1); * } catch(e) { * console.error('Unable to find entity with id = 1'); * } * ``` * @param id - The
(id: string, opts?: GetByIdOptions<Entity>)
| 192 | * @param opts - Additional options |
| 193 | */ |
| 194 | async getById(id: string, opts?: GetByIdOptions<Entity>): Promise<Entity> { |
| 195 | const entity = await this.findById(id, opts) |
| 196 | if (!entity) { |
| 197 | throw new NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`) |
| 198 | } |
| 199 | return entity |
| 200 | } |
| 201 | |
| 202 | /** |
| 203 | * Creates a single entity. |