import { SelectQueryBuilder } from 'typeorm';

export class BetweenQueryHelper {
  constructor(
    protected baseQuery: SelectQueryBuilder<any>,
    protected moduleName: string,
    protected columnName: string,
    protected from: any,
    protected to: any,
    protected valueAlias: string,
  ) {}

  getQuery(): SelectQueryBuilder<any> {
    return this.baseQuery.andWhere(
      `${this.moduleName}.${this.columnName} BETWEEN :from${this.valueAlias} AND :to${this.valueAlias}`,
      {
        [`from${this.valueAlias}`]: this.from,
        [`to${this.valueAlias}`]: this.to,
      },
    );
  }
}
