Skip to content

Commit

Permalink
Fix: delete BAN address on edit and show 'Non renseigné' when BAN fie…
Browse files Browse the repository at this point in the history
…ld is empty
  • Loading branch information
loicguillois committed Feb 24, 2025
1 parent ff478d0 commit 4ba1dc1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/Campaign/CampaignRecipients.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ function CampaignRecipients(props: Props) {
<>
{housing.owner.banAddress
? formatAddress(housing.owner.banAddress)
: null}
{!isBanEligible(housing.owner.banAddress) && (
: 'Non renseigné'}
{housing.owner.banAddress && !isBanEligible(housing.owner.banAddress) && (
<Badge severity="info" small>
Adresse améliorable
</Badge>
Expand Down
2 changes: 1 addition & 1 deletion server/src/controllers/ownerController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ async function update(
'updated_at'
]
}),
banAddress ? banAddressesRepository.save(banAddress) : Promise.resolve(),
banAddress ? banAddressesRepository.save(banAddress) : banAddressesRepository.remove(existingOwner.id, AddressKinds.Owner),
hasIdentityChanges(existingOwner, owner)
? eventRepository.insertOwnerEvent({
id: uuidv4(),
Expand Down
17 changes: 17 additions & 0 deletions server/src/repositories/banAddressesRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,25 @@ export const formatAddressApi = (address: AddressApi): AddressDBO => ({
: undefined
});

export const remove = async (
refId: string,
addressKind: AddressKinds
) => {
logger.debug('Get ban adresse with ref id', {
ref: refId,
addressKind
});
await db(banAddressesTable)
.where('ref_id', refId)
.andWhere('address_kind', addressKind)
.delete();

logger.debug(`Deleted ${addressKind} refId=${refId} address.`);
};

export default {
save,
saveMany,
getByRefId,
remove,
};

0 comments on commit 4ba1dc1

Please sign in to comment.