diff --git a/server/src/assets/dto/get-asset-filter.dto.ts b/server/src/assets/dto/get-asset-filter.dto.ts deleted file mode 100644 index e0d7fbab..00000000 --- a/server/src/assets/dto/get-asset-filter.dto.ts +++ /dev/null @@ -1,4 +0,0 @@ -import { PartialType } from '@nestjs/mapped-types'; -import { Asset } from '../entities/asset.entity'; - -export class GetAssetsDto extends PartialType(Asset) {} diff --git a/server/src/organizations/dto/get-organization.dto.ts b/server/src/organizations/dto/get-organization.dto.ts new file mode 100644 index 00000000..badd4917 --- /dev/null +++ b/server/src/organizations/dto/get-organization.dto.ts @@ -0,0 +1,12 @@ +import { IsOptional } from 'class-validator'; + +export class GetOrganizationDto { + @IsOptional() + search: string; + + @IsOptional() + limit: number; + + @IsOptional() + offset: number; +} diff --git a/server/src/organizations/entities/organization.entity.ts b/server/src/organizations/entities/organization.entity.ts index 0771dc74..381b703e 100644 --- a/server/src/organizations/entities/organization.entity.ts +++ b/server/src/organizations/entities/organization.entity.ts @@ -47,6 +47,6 @@ export class Organization { ) transactions: Transaction[]; - @Column({ type: 'text', unique: true }) + @Column({ type: 'text', nullable: true }) image_url: string; } diff --git a/server/src/organizations/organizations.controller.ts b/server/src/organizations/organizations.controller.ts index f9723b76..2347147d 100644 --- a/server/src/organizations/organizations.controller.ts +++ b/server/src/organizations/organizations.controller.ts @@ -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'; @@ -34,8 +36,8 @@ export class OrganizationsController { } @Get() - findAll(): Promise { - return this.organizationsService.findAll(); + find(@Query() getOrganizationDto: GetOrganizationDto): Promise { + return this.organizationsService.find(getOrganizationDto); } @Get(':id') diff --git a/server/src/organizations/organizations.service.ts b/server/src/organizations/organizations.service.ts index e59a6906..befec738 100644 --- a/server/src/organizations/organizations.service.ts +++ b/server/src/organizations/organizations.service.ts @@ -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; @@ -53,8 +55,20 @@ export class OrganizationsService { } } - findAll(): Promise { - return this.organizationsRepository.find(); + find(getOrganizationDto: GetOrganizationDto): Promise { + 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 {