MCPcopy Create free account
hub / github.com/chainjet/platform / updateOne

Method updateOne

libs/common/src/TypegooseQueryService.ts:244–259  ·  view source on GitHub ↗

* 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>,
  )

Source from the content-addressed store, hash-verified

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.

Callers 7

runMethod · 0.45
completeActionMethod · 0.45
createOrUpdateOneFunction · 0.45
updateOneFunction · 0.45
updateOneNativeFunction · 0.45

Calls 2

ensureIdIsNotPresentMethod · 0.95
mergeFilterWithIdMethod · 0.95

Tested by

no test coverage detected