* Update an entity. * * @example * ```ts * const updatedEntity = await this.service.updateOne(1, { completed: true }); * ``` * @param id - The `id` of the record. * @param update - A `Partial` of the entity with fields to update. * @param opts - Additional options
(
id: string,
update: U,
opts?: UpdateOneOptions<Entity>,
)
| 242 | * @param opts - Additional options |
| 243 | */ |
| 244 | async updateOne<U extends DeepPartial<Entity>>( |
| 245 | id: string, |
| 246 | update: U, |
| 247 | opts?: UpdateOneOptions<Entity>, |
| 248 | ): Promise<Entity> { |
| 249 | this.ensureIdIsNotPresent(update) |
| 250 | const doc = await this.Model.findOneAndUpdate( |
| 251 | this.mergeFilterWithId(id, opts?.filter), |
| 252 | update as UpdateQuery<new () => Entity>, |
| 253 | { new: true }, |
| 254 | ) |
| 255 | if (doc) { |
| 256 | return doc.toObject(this.documentToObjectOptions) as Entity |
| 257 | } |
| 258 | throw new NotFoundException(`Unable to find ${this.Model.modelName} with id: ${id}`) |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * Update multiple entities with a `@ptc-org/nestjs-query-core` Filter. |
no test coverage detected