Skip to content

Commit

Permalink
fix: get the correct community type for auto email
Browse files Browse the repository at this point in the history
  • Loading branch information
ludtkemorgan committed Nov 15, 2023
1 parent ac7dd11 commit f349152
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions backend/core/src/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,10 +304,10 @@ export class EmailService {
}
)
const tableRows = []
if (listing.reservedCommunityType) {
if (listing.reservedCommunityType?.name) {
tableRows.push({
label: this.polyglot.t("rentalOpportunity.community"),
value: formatCommunityType[listing.reservedCommunityType?.name],
value: formatCommunityType[listing.reservedCommunityType.name],
})
}
if (listing.applicationDueDate) {
Expand Down
4 changes: 4 additions & 0 deletions backend/core/src/listings/listings.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ import { CsvBuilder } from "../../src/applications/services/csv-builder.service"
import { CachePurgeService } from "./cache-purge.service"
import { EmailModule } from "../../src/email/email.module"
import { JurisdictionsModule } from "../../src/jurisdictions/jurisdictions.module"
import { ReservedCommunityTypesModule } from "../reserved-community-type/reserved-community-types.module"
import { ReservedCommunityTypesService } from "../reserved-community-type/reserved-community-types.service"
import { ReservedCommunityType } from "../reserved-community-type/entities/reserved-community-type.entity"

@Module({
imports: [
Expand All @@ -32,6 +35,7 @@ import { JurisdictionsModule } from "../../src/jurisdictions/jurisdictions.modul
AmiChart,
ListingFeatures,
ListingUtilities,
ReservedCommunityType,
]),
forwardRef(() => AuthModule),
TranslationsModule,
Expand Down
10 changes: 10 additions & 0 deletions backend/core/src/listings/listings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { CombinedListingFilterParams } from "./combined/combined-listing-filter-
import { Compare } from "../shared/dto/filter.dto"
import { CachePurgeService } from "./cache-purge.service"
import { CombinedListingsQueryBuilder } from "./combined/combined-listing-query-builder"
import { ReservedCommunityType } from "../reserved-community-type/entities/reserved-community-type.entity"

type JurisdictionIdToExternalResponse = { [Identifier: string]: Pagination<Listing> }
export type ListingIncludeExternalResponse = {
Expand All @@ -47,6 +48,8 @@ export class ListingsService {
constructor(
@InjectRepository(Listing) private readonly listingRepository: Repository<Listing>,
@InjectRepository(AmiChart) private readonly amiChartsRepository: Repository<AmiChart>,
@InjectRepository(ReservedCommunityType)
private readonly reservedCommunityTypeRepository: Repository<ReservedCommunityType>,
private readonly translationService: TranslationsService,
private readonly authzService: AuthzService,
@InjectRepository(User) private readonly userRepository: Repository<User>,
Expand Down Expand Up @@ -274,10 +277,17 @@ export class ListingsService {
) {
// The email send to gov delivery should not be a blocker from the normal flow so wrapping this in a try catch
try {
// Get the data from the needed joined tables
const units = await this.getUnitsForListing(saveResponse.id)
const communityType = saveResponse.reservedCommunityType
? await this.reservedCommunityTypeRepository.findOne({
where: { id: saveResponse.reservedCommunityType.id },
})
: await Promise.resolve(undefined)
await this.emailService.listingOpportunity({
...saveResponse,
units: units.units,
reservedCommunityType: communityType || undefined,
} as Listing)
} catch (error) {
console.error(`Error: unable to send to govDelivery ${error}`)
Expand Down
9 changes: 9 additions & 0 deletions backend/core/src/listings/tests/listings.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { EmailService } from "../../../src/email/email.service"
import { JurisdictionsService } from "../../../src/jurisdictions/services/jurisdictions.service"
import { ListingStatus } from "../types/listing-status-enum"
import { UserRoleEnum } from "../../../src/auth/enum/user-role-enum"
import { ReservedCommunityType } from "../../reserved-community-type/entities/reserved-community-type.entity"

/* eslint-disable @typescript-eslint/unbound-method */

Expand Down Expand Up @@ -142,6 +143,10 @@ const mockListingsRepo = {
save: jest.fn(),
}

const mockReservedCommunityTypeRepo = {
findOne: jest.fn(),
}

const mockUserRepo = {
findOne: jest.fn(),
save: jest.fn(),
Expand Down Expand Up @@ -176,6 +181,10 @@ describe("ListingsService", () => {
provide: getRepositoryToken(Listing),
useValue: mockListingsRepo,
},
{
provide: getRepositoryToken(ReservedCommunityType),
useValue: mockReservedCommunityTypeRepo,
},
{
provide: getRepositoryToken(User),
useValue: mockUserRepo,
Expand Down

0 comments on commit f349152

Please sign in to comment.