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

1352/Add flagged and mark as duplicate to CSV export #1500

Merged
merged 6 commits into from
Jul 19, 2021
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file. The format
- Fixed:

- optional fields not being marked as optional in frontend client (missing '?' indicator) ([#1470](https://github.com/bloom-housing/bloom/pull/1470))
- add duplicates to CSV export ([#1352](https://github.com/bloom-housing/bloom/issues/1352))

- Changed:
- User module has been removed and incorporated into Auth module
Expand Down
2 changes: 1 addition & 1 deletion backend/core/src/applications/applications.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ export class ApplicationsController {
@ApiOperation({ summary: "List applications as csv", operationId: "listAsCsv" })
@Header("Content-Type", "text/csv")
async listAsCsv(@Query() queryParams: ApplicationsCsvListQueryParams): Promise<string> {
const applications = await this.applicationsService.list(queryParams)
const applications = await this.applicationsService.listWithFlagged(queryParams)
const listing = await this.listingsService.findOne(queryParams.listingId)
return this.applicationCsvExporter.export(
applications,
Expand Down
33 changes: 33 additions & 0 deletions backend/core/src/applications/applications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,39 @@ export class ApplicationsService {
return result
}

public async listWithFlagged(params: PaginatedApplicationListQueryParams) {
const qb = this._getQb(params)
const result = await qb.getMany()

// Get flagged applications
const flaggedQuery = await this.repository
.createQueryBuilder("applications")
.leftJoin(
"application_flagged_set_applications_applications",
"application_flagged_set_applications_applications",
"application_flagged_set_applications_applications.applications_id = applications.id"
)
.andWhere("applications.listing_id = :lid", { lid: params.listingId })
.select(
"applications.id, count(application_flagged_set_applications_applications.applications_id) > 0 as flagged"
)
.groupBy("applications.id")
.getRawAndEntities()

// Reorganize flagged to object to make it faster to map
const flagged = flaggedQuery.raw.reduce((obj, application) => {
return { ...obj, [application.id]: application.flagged }
}, {})
await Promise.all(
result.map(async (application) => {
// Because TypeOrm can't map extra flagged field we need to map it manually
application.flagged = flagged[application.id]
await this.authorizeUserAction(this.req.user, application, authzActions.read)
})
)
return result
}

async listPaginated(
params: PaginatedApplicationListQueryParams
): Promise<Pagination<Application>> {
Expand Down
6 changes: 6 additions & 0 deletions backend/core/src/applications/entities/application.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,10 @@ export class Application extends AbstractEntity {
@Expose()
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
markedAsDuplicate: boolean

// This is a 'virtual field' needed for CSV export
@Expose()
@IsBoolean({ groups: [ValidationsGroupsEnum.default] })
@IsOptional({ groups: [ValidationsGroupsEnum.partners] })
flagged?: boolean
}
16 changes: 16 additions & 0 deletions backend/core/src/csv/formatting/formatters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -608,3 +608,19 @@ export const formatHOPWAPreference = {
)
},
}

export const formatMarkedAsDuplicate = {
label: "Marked as duplicate",
discriminator: "",
formatter: (application: Application) => {
return booleanFormatter(application.markedAsDuplicate)
},
}

export const formatFlagged = {
label: "Flagged",
discriminator: "",
formatter: (application: Application) => {
return booleanFormatter(application.flagged)
},
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ import {
formatRequestUnitType,
formatVouchersOrSubsidies,
formatWorkPreference,
formatMarkedAsDuplicate,
formatFlagged,
} from "../formatters"

export const basicFormattingMetadata = [
Expand Down Expand Up @@ -92,4 +94,6 @@ export const basicFormattingMetadata = [
formatWorkPreference,
formatHouseholdSize,
formatHoueholdMembers,
formatMarkedAsDuplicate,
formatFlagged,
]
1 change: 1 addition & 0 deletions backend/core/test/applications/applications.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ describe("Applications", () => {
expect(createRes.body).toMatchObject(body)
expect(createRes.body).toHaveProperty("createdAt")
expect(createRes.body).toHaveProperty("updatedAt")
expect(createRes.body).toHaveProperty("flagged")
expect(createRes.body).toHaveProperty("id")
const res = await supertest(app.getHttpServer())
.get(`/applications/csv/?includeHeaders=true&listingId=${listing1Id}`)
Expand Down
9 changes: 9 additions & 0 deletions backend/core/types/src/backend-swagger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,9 @@ export interface Application {

/** */
markedAsDuplicate: boolean;

/** */
flagged?: boolean;
}

export interface ApplicationFlaggedSet {
Expand Down Expand Up @@ -2384,6 +2387,9 @@ export interface ApplicationCreate {

/** */
submissionDate?: Date;

/** */
flagged?: boolean;
}

export interface AddressUpdate {
Expand Down Expand Up @@ -2710,6 +2716,9 @@ export interface ApplicationUpdate {

/** */
submissionDate?: Date;

/** */
flagged?: boolean;
}

export interface AssetCreate {
Expand Down