CloneAttribute

Recebe como parâmetro uma matriz de chave e um valor, retorna uma matriz de objetos com o mesmo valor, é útil para consultas localizar ONDE + OU.

Sem mapeador:

const param = "example";

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

// Busca onde id = "example" OU name = "example" OU description = "example"

Usando mapeador:

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

const param = "example";

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

// Busca onde id = "example" OU name = "example" OU description = "example"

Last updated

Was this helpful?