Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make orgs searchable #229

Merged
merged 1 commit into from
Oct 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed unique true because it was causing errors with seeding (because we use the same hardcoded img for multiple orgs)

added nullable true because we shouldn't require a profile img

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