Skip to content

Commit

Permalink
fix: listingName, approval email from listingJuris (#3700)
Browse files Browse the repository at this point in the history
  • Loading branch information
YazeedLoonat authored Nov 3, 2023
1 parent f283ebb commit 9569d0b
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 19 deletions.
12 changes: 8 additions & 4 deletions backend/core/src/email/email.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ describe("EmailService", () => {
},
{
provide: JurisdictionsService,
useValue: {},
useValue: {
findOne: () => ({
emailFromAddress: "myeamil@from",
}),
},
},
{
provide: JurisdictionResolverService,
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down Expand Up @@ -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"
)
Expand Down
47 changes: 40 additions & 7 deletions backend/core/src/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions backend/core/src/listings/listings.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)
Expand All @@ -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")
)
Expand All @@ -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
)
Expand Down
14 changes: 9 additions & 5 deletions backend/core/test/listings/listings.e2e-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(["[email protected]", "[email protected]"]),
process.env.PARTNERS_PORTAL_URL
)
Expand All @@ -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(["[email protected]", "[email protected]"]),
process.env.PARTNERS_PORTAL_URL
)
Expand All @@ -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(["[email protected]", "[email protected]"]),
alameda.publicUrl
)
Expand Down Expand Up @@ -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(["[email protected]", "[email protected]"]),
process.env.PARTNERS_PORTAL_URL
)
Expand Down Expand Up @@ -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([
"[email protected]",
"[email protected]",
Expand Down

0 comments on commit 9569d0b

Please sign in to comment.