diff --git a/api/src/services/listing.service.ts b/api/src/services/listing.service.ts index d30db6c7d6..fd9b9adf22 100644 --- a/api/src/services/listing.service.ts +++ b/api/src/services/listing.service.ts @@ -982,6 +982,19 @@ export class ListingService implements OnModuleInit { }, }); } else { + // in order to delete the old address we first need to disconnect it from the listing + await this.prisma.listings.update({ + data: { + [field]: { + disconnect: { + id: existingListing[field].id, + }, + }, + }, + where: { + id: existingListing.id, + }, + }); await this.prisma.address.delete({ where: { id: existingListing[field].id, diff --git a/api/test/integration/listing.e2e-spec.ts b/api/test/integration/listing.e2e-spec.ts index 9579bc9ffd..9f9d4ea54e 100644 --- a/api/test/integration/listing.e2e-spec.ts +++ b/api/test/integration/listing.e2e-spec.ts @@ -628,6 +628,7 @@ describe('Listing Controller Tests', () => { }); const val = await constructFullListingData(listing.id, jurisdictionA.id); + val.listingsApplicationMailingAddress = undefined; const res = await request(app.getHttpServer()) .put(`/listings/${listing.id}`) diff --git a/sites/partners/src/components/listings/PaperListingForm/sections/ApplicationAddress.tsx b/sites/partners/src/components/listings/PaperListingForm/sections/ApplicationAddress.tsx index 7adfd3bd42..4817f6c2d3 100644 --- a/sites/partners/src/components/listings/PaperListingForm/sections/ApplicationAddress.tsx +++ b/sites/partners/src/components/listings/PaperListingForm/sections/ApplicationAddress.tsx @@ -373,7 +373,7 @@ const ApplicationAddress = ({ listing }: ApplicationAddressProps) => { ) } inputProps={{ - onChange: () => clearErrors("applicationMailingAddress"), + onChange: () => clearErrors("listingsApplicationMailingAddress"), }} /> diff --git a/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts b/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts index 9ae7c851d4..89f5581002 100644 --- a/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts +++ b/sites/partners/src/lib/listings/AdditionalMetadataFormatter.ts @@ -49,9 +49,9 @@ export default class AdditionalMetadataFormatter extends Formatter { cleanAddress("leasingAgentAddress") cleanAddress("buildingAddress") - cleanAddress("applicationMailingAddress") - cleanAddress("applicationPickUpAddress") - cleanAddress("applicationDropOffAddress") + cleanAddress("listingsApplicationMailingAddress") + cleanAddress("listingsApplicationPickUpAddress") + cleanAddress("listingsApplicationDropOffAddress") this.data.customMapPin = this.metadata.customMapPositionChosen this.data.yearBuilt = this.data.yearBuilt ? Number(this.data.yearBuilt) : null diff --git a/sites/partners/src/lib/listings/BooleansFormatter.ts b/sites/partners/src/lib/listings/BooleansFormatter.ts index 1feb814c8e..2b961a7ce7 100644 --- a/sites/partners/src/lib/listings/BooleansFormatter.ts +++ b/sites/partners/src/lib/listings/BooleansFormatter.ts @@ -23,19 +23,19 @@ export default class BooleansFormatter extends Formatter { addressTypes[this.data.whereApplicationsMailedIn] !== addressTypes.anotherAddress, trueCase: () => addressTypes[this.data.whereApplicationsMailedIn], }) - this.processBoolean("applicationDropOffAddress", { + this.processBoolean("listingsApplicationDropOffAddress", { when: this.data.canApplicationsBeDroppedOff === YesNoEnum.yes && this.data.whereApplicationsDroppedOff === addressTypes.anotherAddress, trueCase: () => this.data.listingsApplicationDropOffAddress, }) - this.processBoolean("applicationPickUpAddress", { + this.processBoolean("listingsApplicationPickUpAddress", { when: this.data.canPaperApplicationsBePickedUp === YesNoEnum.yes && this.data.whereApplicationsPickedUp === addressTypes.anotherAddress, trueCase: () => this.data.listingsApplicationPickUpAddress, }) - this.processBoolean("applicationMailingAddress", { + this.processBoolean("listingsApplicationMailingAddress", { when: this.data.canApplicationsBeMailedIn === YesNoEnum.yes && this.data.whereApplicationsMailedIn === addressTypes.anotherAddress,