CloneAttribute

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

No mapper:

const param: FindOptionsWhere<Example> = {
  key: "example",
};

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

// Find where id = key OR name = key OR description = key

Using mapper:

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

const param: FindOptionsWhere<Example> = {
  key: "example",
};

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

// Find where id = key OR name = key OR description = key