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

fix: listingName, approval email from listingJuris (#3700) #650

Merged
merged 1 commit into from
Nov 3, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@ -362,7 +362,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 @@ -376,7 +376,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 @@ -397,7 +397,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 @@ -519,7 +519,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 @@ -545,7 +545,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 @@ -567,7 +567,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 @@ -610,7 +610,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 @@ -643,7 +647,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
Loading