Skip to content

Commit

Permalink
make orgs searchable (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
jd2rogers2 authored Oct 24, 2022
1 parent e06d7a4 commit 88c1d10
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 13 deletions.
4 changes: 0 additions & 4 deletions server/src/assets/dto/get-asset-filter.dto.ts

This file was deleted.

12 changes: 12 additions & 0 deletions server/src/organizations/dto/get-organization.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { IsOptional } from 'class-validator';

export class GetOrganizationDto {
@IsOptional()
search: string;

@IsOptional()
limit: number;

@IsOptional()
offset: number;
}
2 changes: 1 addition & 1 deletion server/src/organizations/entities/organization.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,6 @@ export class Organization {
)
transactions: Transaction[];

@Column({ type: 'text', unique: true })
@Column({ type: 'text', nullable: true })
image_url: string;
}
6 changes: 4 additions & 2 deletions server/src/organizations/organizations.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ import {
Delete,
HttpException,
HttpStatus,
Query,
} from '@nestjs/common';
import { OrganizationsService } from './organizations.service';
import { CreateOrganizationDto } from './dto/create-organization.dto';
import { UpdateOrganizationDto } from './dto/update-organization.dto';
import { GetOrganizationDto } from './dto/get-organization.dto';
import { Organization } from './entities/organization.entity';
import { DeleteResult } from 'typeorm';
import { PropublicaOrg } from './organizations.service';
Expand All @@ -34,8 +36,8 @@ export class OrganizationsController {
}

@Get()
findAll(): Promise<Organization[]> {
return this.organizationsService.findAll();
find(@Query() getOrganizationDto: GetOrganizationDto): Promise<Organization[]> {
return this.organizationsService.find(getOrganizationDto);
}

@Get(':id')
Expand Down
26 changes: 20 additions & 6 deletions server/src/organizations/organizations.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { HttpException, HttpStatus, Injectable, NotFoundException } from '@nestjs/common';
import { CreateOrganizationDto } from './dto/create-organization.dto';
import { UpdateOrganizationDto } from './dto/update-organization.dto';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, DeleteResult } from 'typeorm';
import { Organization } from './entities/organization.entity';
import { DeleteResult, Raw, Repository } from 'typeorm';
import fetch from 'node-fetch';

import { Organization } from './entities/organization.entity';
import { CreateOrganizationDto } from './dto/create-organization.dto';
import { UpdateOrganizationDto } from './dto/update-organization.dto';
import { GetOrganizationDto } from './dto/get-organization.dto';

export type PropublicaOrg = {
ein: string;
name: string;
Expand Down Expand Up @@ -53,8 +55,20 @@ export class OrganizationsService {
}
}

findAll(): Promise<Organization[]> {
return this.organizationsRepository.find();
find(getOrganizationDto: GetOrganizationDto): Promise<Organization[]> {
const { limit, offset, search } = getOrganizationDto;
const searches = [
{ name: Raw((alias) => `LOWER(${alias}) LIKE '%${search.toLowerCase()}%'`) },
{ doing_business_as: Raw((alias) => `LOWER(${alias}) LIKE '%${search.toLowerCase()}%'`) },
{ description: Raw((alias) => `LOWER(${alias}) LIKE '%${search.toLowerCase()}%'`) },
];

return this.organizationsRepository.find({
...(search ? { where: searches } : {}),
order: { name: 'ASC' },
skip: offset,
take: limit,
});
}

findOne(id: number): Promise<Organization> {
Expand Down

0 comments on commit 88c1d10

Please sign in to comment.