diff --git a/backend/core/src/email/email.service.spec.ts b/backend/core/src/email/email.service.spec.ts index 38d930be27..97c049917d 100644 --- a/backend/core/src/email/email.service.spec.ts +++ b/backend/core/src/email/email.service.spec.ts @@ -210,7 +210,11 @@ describe("EmailService", () => { }, { provide: JurisdictionsService, - useValue: {}, + useValue: { + findOne: () => ({ + emailFromAddress: "myeamil@from", + }), + }, }, { provide: JurisdictionResolverService, @@ -330,7 +334,7 @@ describe("EmailService", () => { const service = await module.resolve(EmailService) await service.requestApproval( user, - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction?.id }, emailArr, "http://localhost:3001" ) @@ -373,7 +377,7 @@ describe("EmailService", () => { const service = await module.resolve(EmailService) await service.changesRequested( user, - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction?.id }, emailArr, "http://localhost:3001" ) @@ -420,7 +424,7 @@ describe("EmailService", () => { const service = await module.resolve(EmailService) await service.listingApproved( user, - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction?.id }, emailArr, "http://localhost:3000" ) diff --git a/backend/core/src/email/email.service.ts b/backend/core/src/email/email.service.ts index 187965572e..e444e35ddb 100644 --- a/backend/core/src/email/email.service.ts +++ b/backend/core/src/email/email.service.ts @@ -18,7 +18,6 @@ import { Jurisdiction } from "../jurisdictions/entities/jurisdiction.entity" import { Language } from "../shared/types/language-enum" import { JurisdictionsService } from "../jurisdictions/services/jurisdictions.service" import { Translation } from "../translations/entities/translation.entity" -import { IdName } from "../../types" import { formatLocalDate } from "../shared/utils/format-local-date" type EmailAttachmentData = { @@ -27,6 +26,12 @@ type EmailAttachmentData = { type: string } +type listingInfo = { + id: string + name: string + juris: string +} + @Injectable({ scope: Scope.REQUEST }) export class EmailService { polyglot: Polyglot @@ -371,9 +376,20 @@ export class EmailService { ) } - public async requestApproval(user: User, listingInfo: IdName, emails: string[], appUrl: string) { + public async requestApproval( + user: User, + listingInfo: listingInfo, + emails: string[], + appUrl: string + ) { try { - const jurisdiction = await this.getUserJurisdiction(user) + const jurisdiction = listingInfo.juris + ? await this.jurisdictionService.findOne({ + where: { + id: listingInfo.juris, + }, + }) + : await this.getUserJurisdiction(user) void (await this.loadTranslations(jurisdiction, Language.en)) await this.send( emails, @@ -391,9 +407,20 @@ export class EmailService { } } - public async changesRequested(user: User, listingInfo: IdName, emails: string[], appUrl: string) { + public async changesRequested( + user: User, + listingInfo: listingInfo, + emails: string[], + appUrl: string + ) { try { - const jurisdiction = await this.getUserJurisdiction(user) + const jurisdiction = listingInfo.juris + ? await this.jurisdictionService.findOne({ + where: { + id: listingInfo.juris, + }, + }) + : await this.getUserJurisdiction(user) void (await this.loadTranslations(jurisdiction, Language.en)) await this.send( emails, @@ -413,12 +440,18 @@ export class EmailService { public async listingApproved( user: User, - listingInfo: IdName, + listingInfo: listingInfo, emails: string[], publicUrl: string ) { try { - const jurisdiction = await this.getUserJurisdiction(user) + const jurisdiction = listingInfo.juris + ? await this.jurisdictionService.findOne({ + where: { + id: listingInfo.juris, + }, + }) + : await this.getUserJurisdiction(user) void (await this.loadTranslations(jurisdiction, Language.en)) await this.send( emails, diff --git a/backend/core/src/listings/listings.service.ts b/backend/core/src/listings/listings.service.ts index df3a27af91..d717da6005 100644 --- a/backend/core/src/listings/listings.service.ts +++ b/backend/core/src/listings/listings.service.ts @@ -324,7 +324,7 @@ export class ListingsService { ) await this.emailService.requestApproval( params.user, - { id: params.listingInfo.id, name: params.listingInfo.name }, + { id: params.listingInfo.id, name: params.listingInfo.name, juris: params.jurisId }, userInfo.emails, this.configService.get("PARTNERS_PORTAL_URL") ) @@ -338,7 +338,7 @@ export class ListingsService { ) await this.emailService.changesRequested( params.user, - { id: params.listingInfo.id, name: params.listingInfo.name }, + { id: params.listingInfo.id, name: params.listingInfo.name, juris: params.jurisId }, userInfo.emails, this.configService.get("PARTNERS_PORTAL_URL") ) @@ -359,7 +359,7 @@ export class ListingsService { ) await this.emailService.listingApproved( params.user, - { id: params.listingInfo.id, name: params.listingInfo.name }, + { id: params.listingInfo.id, name: params.listingInfo.name, juris: params.jurisId }, userInfo.emails, userInfo.publicUrl ) diff --git a/backend/core/test/listings/listings.e2e-spec.ts b/backend/core/test/listings/listings.e2e-spec.ts index 7b453d9f8e..e9ca472917 100644 --- a/backend/core/test/listings/listings.e2e-spec.ts +++ b/backend/core/test/listings/listings.e2e-spec.ts @@ -507,7 +507,7 @@ describe("Listings", () => { expect.objectContaining({ id: adminId, }), - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction.id }, expect.arrayContaining(["admin@example.com", "mfauser@bloom.com"]), process.env.PARTNERS_PORTAL_URL ) @@ -533,7 +533,7 @@ describe("Listings", () => { expect.objectContaining({ id: adminId, }), - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction.id }, expect.arrayContaining(["leasing-agent-2@example.com", "alameda-admin@example.com"]), process.env.PARTNERS_PORTAL_URL ) @@ -555,7 +555,7 @@ describe("Listings", () => { expect.objectContaining({ id: adminId, }), - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction.id }, expect.arrayContaining(["leasing-agent-2@example.com", "alameda-admin@example.com"]), alameda.publicUrl ) @@ -598,7 +598,11 @@ describe("Listings", () => { expect.objectContaining({ id: adminId, }), - { id: listingResponse.body.id, name: listingResponse.body.name }, + { + id: listingResponse.body.id, + name: listingResponse.body.name, + juris: listingResponse.body.jurisdiction.id, + }, expect.arrayContaining(["admin@example.com", "mfauser@bloom.com"]), process.env.PARTNERS_PORTAL_URL ) @@ -631,7 +635,7 @@ describe("Listings", () => { expect.objectContaining({ id: adminId, }), - { id: listing.id, name: listing.name }, + { id: listing.id, name: listing.name, juris: listing.jurisdiction.id }, expect.arrayContaining([ "admin@example.com", "mfauser@bloom.com",