Refactor account deletion process and improve invitation functionalities

The account deletion process has been refactored to send account deletion emails from the AccountWebhooksService instead of from the deletePersonalAccount service. This has resulted in the addition of the AccountWebhooksService and modification of the seeds.sql file to trigger a webhook after account deletion. Along with this, the account invitation functionalities within the accountInvitations service have been considerably enhanced, making it much clearer and easier to use.
This commit is contained in:
giancarlo
2024-04-09 16:26:50 +08:00
parent 1a3c27326b
commit 5adfb3edac
8 changed files with 193 additions and 96 deletions

View File

@@ -57,64 +57,6 @@ export class DeletePersonalAccountService {
throw new Error('Error deleting user');
}
// Send account deletion email
if (params.userEmail) {
try {
logger.info(
{
name: this.namespace,
userId,
},
`Sending account deletion email...`,
);
await this.sendAccountDeletionEmail({
fromEmail: params.emailSettings.fromEmail,
productName: params.emailSettings.productName,
userDisplayName: params.userEmail,
userEmail: params.userEmail,
});
logger.info(
{
name: this.namespace,
userId,
},
`Account deletion email sent`,
);
} catch (error) {
logger.error(
{
name: this.namespace,
userId,
error,
},
`Error sending account deletion email`,
);
}
}
}
private async sendAccountDeletionEmail(params: {
fromEmail: string;
userEmail: string;
userDisplayName: string;
productName: string;
}) {
const { renderAccountDeleteEmail } = await import('@kit/email-templates');
const { getMailer } = await import('@kit/mailers');
const mailer = await getMailer();
const html = renderAccountDeleteEmail({
userDisplayName: params.userDisplayName,
productName: params.productName,
});
return mailer.sendEmail({
to: params.userEmail,
from: params.fromEmail,
subject: 'Account Deletion Request',
html,
});
logger.info({ name: this.namespace, userId }, 'User deleted successfully');
}
}