format on save, resolve compile errors, functionality 1. stage

This commit is contained in:
2024-04-23 17:32:21 +02:00
parent 7f0f21b598
commit 9e03620be7
32 changed files with 1506 additions and 1389 deletions

View File

@@ -23,25 +23,25 @@ export class ListingsService {
constructor(@Inject(WINSTON_MODULE_PROVIDER) private readonly logger: Logger,
@Inject(PG_CONNECTION) private conn: NodePgDatabase<typeof schema>,) {
}
private getConditions(criteria: ListingCriteria): any[] {
private getConditions(criteria: ListingCriteria,table: typeof businesses | typeof commercials): any[] {
const conditions = [];
if (criteria.type) {
conditions.push(eq(businesses.type, criteria.type));
conditions.push(eq(table.type, criteria.type));
}
if (criteria.state) {
conditions.push(eq(businesses.state, criteria.state));
conditions.push(eq(table.state, criteria.state));
}
if (criteria.minPrice) {
conditions.push(gte(businesses.price, criteria.minPrice));
conditions.push(gte(table.price, criteria.minPrice));
}
if (criteria.maxPrice) {
conditions.push(lte(businesses.price, criteria.maxPrice));
conditions.push(lte(table.price, criteria.maxPrice));
}
if (criteria.realEstateChecked) {
conditions.push(eq(businesses.realEstateIncluded, true));
}
if (criteria.title) {
conditions.push(ilike(businesses.title, `%${criteria.title}%`));
conditions.push(ilike(table.title, `%${criteria.title}%`));
}
return conditions;
}
@@ -54,7 +54,7 @@ export class ListingsService {
return await this.findListings(table, criteria, start, length)
}
private async findListings(table: typeof businesses | typeof commercials, criteria: ListingCriteria, start = 0, length = 12): Promise<any> {
const conditions = this.getConditions(criteria)
const conditions = this.getConditions(criteria,table)
const [data, total] = await Promise.all([
this.conn.select().from(table).where(and(...conditions)).offset(start).limit(length),
this.conn.select({ count: sql`count(*)` }).from(table).where(and(...conditions)).then((result) => Number(result[0].count)),