import { SelectQueryBuilder } from 'typeorm';

export class SearchQueryHelper {
  constructor(
    protected baseQuery: SelectQueryBuilder<any>,
    protected moduleName: string,
    protected columnName: string,
    protected value: string,
    protected valueAliases: string,
  ) {}

  getQuery(): SelectQueryBuilder<any> {
    return this.baseQuery.andWhere(
      `${this.moduleName}.${this.columnName} ILIKE :${this.valueAliases}`,
      {
        [this.valueAliases]: `%${this.value}%`,
      },
    );
  }
}
