Skip to content

Commit 1676045

Browse files
committed
feat(api): send notification email for route DELETE /api/users/me
1 parent 3371d46 commit 1676045

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

api/src/identity-access-management/application/user/user.controller.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,11 @@ const rememberUserHasSeenLastDataProtectionPolicyInformation = async function (
203203
return dependencies.userSerializer.serialize(updatedUser);
204204
};
205205

206-
const selfDeleteUserAccount = async function (request, h) {
206+
const selfDeleteUserAccount = async function (request, h, dependencies = { requestResponseUtils }) {
207207
const authenticatedUserId = request.auth.credentials.userId;
208+
const localeFromHeader = dependencies.requestResponseUtils.extractLocaleFromRequest(request);
208209

209-
await usecases.selfDeleteUserAccount({ userId: authenticatedUserId });
210+
await usecases.selfDeleteUserAccount({ userId: authenticatedUserId, localeFromHeader });
210211

211212
return h.response().code(204);
212213
};

api/src/identity-access-management/domain/usecases/self-delete-user-account.usecase.js

+18-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ForbiddenAccess } from '../../../shared/domain/errors.js';
2+
import { createSelfDeleteUserAccountEmail } from '../emails/create-self-delete-user-account.email.js';
23

34
/**
45
* @typedef {import('../../infrastructure/repositories/privacy-users-api.repository.js')} PrivacyUsersApiRepository
@@ -10,15 +11,31 @@ import { ForbiddenAccess } from '../../../shared/domain/errors.js';
1011
* @param{PrivacyUsersApiRepository} privacyUsersApiRepository
1112
* @returns {Promise<boolean>}
1213
*/
13-
export const selfDeleteUserAccount = async function ({ userId, privacyUsersApiRepository }) {
14+
export const selfDeleteUserAccount = async function ({
15+
userId,
16+
localeFromHeader,
17+
userRepository,
18+
privacyUsersApiRepository,
19+
emailRepository,
20+
}) {
1421
const canSelfDeleteAccount = await privacyUsersApiRepository.canSelfDeleteAccount({ userId });
1522

1623
if (!canSelfDeleteAccount) {
1724
throw new ForbiddenAccess();
1825
}
1926

27+
const user = await userRepository.get(userId);
28+
2029
const anonymizedByUserId = userId;
2130
const anonymizedByUserRole = 'USER';
2231
const client = 'PIX_APP';
2332
await privacyUsersApiRepository.anonymizeUser({ userId, anonymizedByUserId, anonymizedByUserRole, client });
33+
34+
await emailRepository.sendEmailAsync(
35+
createSelfDeleteUserAccountEmail({
36+
locale: localeFromHeader,
37+
email: user.email,
38+
firstName: user.firstName,
39+
}),
40+
);
2441
};

api/tests/identity-access-management/integration/domain/usecases/self-delete-user-account.usecase.test.js

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ describe('Integration | Identity Access Management | Domain | UseCase | self-del
1414

1515
// when & then
1616
await expect(usecases.selfDeleteUserAccount({ userId })).to.not.be.rejectedWith(ForbiddenAccess);
17+
18+
await expect('SendEmailJob').to.have.been.performed.withJobsCount(1);
1719
});
1820
});
1921

0 commit comments

Comments
 (0)