Skip to content

Commit

Permalink
WIP: approach to use ilike any for project name partial match
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeh committed Nov 7, 2024
1 parent be3b977 commit 16f963d
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions api/src/modules/projects/projects.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import { Project } from '@shared/entities/projects.entity';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, SelectQueryBuilder } from 'typeorm';
import { FetchSpecification } from 'nestjs-base-service';
import { z } from 'zod';
import { ProjectGeoPropertiesSchema } from '@shared/schemas/geometries/projects';
import { projectsQuerySchema } from '@shared/contracts/projects.contract';

export type ProjectFetchSpecificacion = z.infer<typeof projectsQuerySchema>;

@Injectable()
export class ProjectsService extends AppBaseService<
Expand All @@ -21,14 +26,18 @@ export class ProjectsService extends AppBaseService<

async extendFindAllQuery(
query: SelectQueryBuilder<Project>,
fetchSpecification: FetchSpecification,
fetchSpecification: ProjectFetchSpecificacion,
): Promise<SelectQueryBuilder<Project>> {
const filter = fetchSpecification.filter.projectName
.map((name) => `'%${name}%'`)
.join(',');
// Filter by project name
if (fetchSpecification?.filter?.projectName) {
query = query.andWhere('project_name ILIKE :projectName', {
projectName: `%${fetchSpecification.filter.projectName}%`,
query = query.andWhere('project_name ILIKE ANY(ARRAY[:projectName])', {
projectName: filter,
});
}
console.log('query', query.getQueryAndParameters());
return query;
}
}

0 comments on commit 16f963d

Please sign in to comment.