CloneAttribute

Receives as parameter a key array and a value, returns an array of objects with the same value, is useful for queries find WHERE + OR.

No mapper:

const param = "example";

const example = await this.examplesRepository.findBy(
  { 
    where: [
      { id: param },
      { name: param },
      { description: param },
    ]
  },
  trx,
);

// Find where id = "example" OR name = "example" OR description = "example"

Using mapper:

import { cloneAttribute } from "@utils/mappers";

const param = "example";

const example = await this.examplesRepository.findBy(
  {
    where: cloneAttribute<Example>(param, ['id', 'name', 'description']),
  },
  trx,
);

// Find where id = "example" OR name = "example" OR description = "example"

Last updated

Was this helpful?