Skip to content

Commit

Permalink
feat: filter flagged duplicate sets (#4097)
Browse files Browse the repository at this point in the history
  • Loading branch information
emilyjablonski authored May 22, 2024
1 parent 24be7e8 commit d5cbc2a
Show file tree
Hide file tree
Showing 14 changed files with 247 additions and 130 deletions.
13 changes: 12 additions & 1 deletion api/src/dtos/application-flagged-sets/afs-query-params.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { Expose } from 'class-transformer';
import { IsEnum, IsUUID } from 'class-validator';
import { IsEnum, IsUUID, IsString, MinLength } from 'class-validator';
import { View } from '../../enums/application-flagged-sets/view';
import { ValidationsGroupsEnum } from '../../enums/shared/validation-groups-enum';
import { PaginationAllowsAllQueryParams } from '../shared/pagination.dto';
Expand All @@ -19,4 +19,15 @@ export class AfsQueryParams extends PaginationAllowsAllQueryParams {
})
@IsEnum(View, { groups: [ValidationsGroupsEnum.default] })
view?: View;

@Expose()
@ApiPropertyOptional({
example: 'search',
})
@IsString({ groups: [ValidationsGroupsEnum.default] })
@MinLength(3, {
message: 'Search must be at least 3 characters',
groups: [ValidationsGroupsEnum.default],
})
search?: string;
}
25 changes: 25 additions & 0 deletions api/src/services/application-flagged-set.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,31 @@ export class ApplicationFlaggedSetService implements OnModuleInit {
}
}

if (params.search) {
filters.push({
applications: {
some: {
applicant: {
OR: [
{
firstName: {
contains: params.search,
mode: Prisma.QueryMode.insensitive,
},
},
{
lastName: {
contains: params.search,
mode: Prisma.QueryMode.insensitive,
},
},
],
},
},
},
});
}

return {
AND: filters,
};
Expand Down
41 changes: 41 additions & 0 deletions api/test/unit/services/application-flagged-set.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,47 @@ describe('Testing application flagged set service', () => {
});
});

it('should build where clause with listingId and view of pending with search', async () => {
expect(
await service.buildWhere({
listingId: 'example id',
view: View.pending,
search: 'simple search',
}),
).toEqual({
AND: [
{
listingId: 'example id',
},
{
status: FlaggedSetStatusEnum.pending,
},
{
applications: {
some: {
applicant: {
OR: [
{
firstName: {
contains: 'simple search',
mode: 'insensitive',
},
},
{
lastName: {
contains: 'simple search',
mode: 'insensitive',
},
},
],
},
},
},
},
],
});
});

it('should build where clause with listingId and view of pendingNameAndDoB', async () => {
expect(
await service.buildWhere({
Expand Down
6 changes: 6 additions & 0 deletions shared-helpers/src/types/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ export class ApplicationFlaggedSetsService {
listingId: string
/** */
view?: AfsView
/** */
search?: string
} = {} as any,
options: IRequestOptions = {}
): Promise<PaginatedAfs> {
Expand All @@ -394,6 +396,7 @@ export class ApplicationFlaggedSetsService {
limit: params["limit"],
listingId: params["listingId"],
view: params["view"],
search: params["search"],
}

/** 适配ios13,get请求不允许带body */
Expand All @@ -414,6 +417,8 @@ export class ApplicationFlaggedSetsService {
listingId: string
/** */
view?: AfsView
/** */
search?: string
} = {} as any,
options: IRequestOptions = {}
): Promise<AfsMeta> {
Expand All @@ -426,6 +431,7 @@ export class ApplicationFlaggedSetsService {
limit: params["limit"],
listingId: params["listingId"],
view: params["view"],
search: params["search"],
}

/** 适配ios13,get请求不允许带body */
Expand Down
26 changes: 26 additions & 0 deletions sites/partners/__tests__/lib/helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { Application } from "@bloom-housing/shared-helpers/src/types/backend-swagger"
import { mergeApplicationNames } from "../../src/lib/helpers"

describe("helpers", () => {
describe("mergeApplicationNames", () => {
it("should merge names for one application", () => {
expect(
mergeApplicationNames([
{ applicant: { firstName: "FirstA", lastName: "LastA" } } as Application,
])
).toEqual("FirstA LastA")
})
it("should merge names for multiple applications", () => {
expect(
mergeApplicationNames([
{ applicant: { firstName: "FirstA", lastName: "LastA" } } as Application,
{ applicant: { firstName: "FirstB", lastName: "LastB" } } as Application,
{ applicant: { firstName: "FirstC", lastName: "LastC" } } as Application,
])
).toEqual("FirstA LastA, FirstB LastB, FirstC LastC")
})
it("should merge names for no application", () => {
expect(mergeApplicationNames([])).toEqual("")
})
})
})
3 changes: 2 additions & 1 deletion sites/partners/page_content/locale_overrides/general.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"application.details.householdSize": "Household Size",
"application.details.language": "Application Language",
"application.details.monthlyIncome": "Monthly Income",
"application.details.number": "Application Number",
"application.details.number": "Confirmation Code",
"application.details.preferences": "Application Preferences",
"application.details.preferredContact": "Preferred Contact",
"application.details.preferredUnitSizes": "Preferred Unit Sizes",
Expand Down Expand Up @@ -69,6 +69,7 @@
"applications.pendingReview": "Pending Review",
"applications.scanForDuplicates": "Scan for duplicates",
"applications.table.additionalPhoneType": "Additional Phone Type",
"applications.table.additionalPhoneTypeShortened": "Addtl. Phone Type",
"applications.table.altContactAgency": "Alt Contact Agency",
"applications.table.altContactCity": "Alt Contact City",
"applications.table.altContactEmail": "Alt Contact Email",
Expand Down
Loading

0 comments on commit d5cbc2a

Please sign in to comment.