Skip to content

patchMany

Category
Tags
Export size
min 1.18 kB · gzip 0.62 kB
See also

Patches all items matching params with a single patch(null, ...) call.

If the service does not allow multi patching (its multi option, or an explicit multi option), the matching items are fetched with find and patched with one call per item instead - so it works regardless of the service's multi configuration.

The params only select which items are affected: the query is consumed by the find - which only collects the ids - and is not applied again for the per-item calls, except $select.

ts
  import { 
patchMany
} from 'feathers-utils/utils';

Example

ts
import { patchMany } from 'feathers-utils/utils'

// one `patch(null, ...)` call, or one `patch(id, ...)` call per item
const todos = await patchMany(app, 'todos', { userId: null }, {
  query: { userId: 1 },
})

Type declaration

Show Type Declarations
ts
export type PatchManyOptions = {
  /**
   * Whether the service allows patching multiple items in a single call.
   *
   * Defaults to the `multi` option of the service. If multi patching is not
   * allowed, the matching items are fetched and patched with one call per item.
   */
  multi?: Multi
}
/**
 * Patches all items matching `params` with a single `patch(null, ...)` call.
 *
 * If the service does not allow multi patching (its `multi` option, or an
 * explicit `multi` option), the matching items are fetched with `find` and
 * patched with one call per item instead - so it works regardless of the
 * service's `multi` configuration.
 *
 * The `params` only select which items are affected: the query is consumed by
 * the `find` - which only collects the ids - and is not applied again for the
 * per-item calls, except `$select`.
 *
 * @example
 * ```ts
 *
 *
 * // one `patch(null, ...)` call, or one `patch(id, ...)` call per item
 * const todos = await patchMany(app, 'todos', { userId: null }, {
 *   query: { userId: 1 },
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/utils/patch-many.html
 */
export declare function patchMany<
  Services,
  Path extends KeyOf<Services>,
  Service extends Services[Path] = Services[Path],
  P extends Params = InferFindParams<Service>,
  Item = InferFindResultSingle<Service>,
>(
  app: Application<Services>,
  servicePath: Path,
  data: InferPatchData<Service>,
  params?: P,
  options?: PatchManyOptions,
): Promise<Item[]>
ArgumentTypeDescription
appApplication<Services>
servicePathPath
dataInferPatchData<Service>
paramsP
optionsPatchManyOptions

Released under the MIT License.