delete akun notifikasi email
This commit is contained in:
parent
33c51815df
commit
6c82035724
|
@ -481,7 +481,19 @@ exports.walletData = async (req, res, next) => {
|
|||
exports.deleteAccountAndData = async (req, res, next) => {
|
||||
const uid = req.user.uid;
|
||||
const conn = await db.getConnection();
|
||||
let userRow;
|
||||
|
||||
try {
|
||||
const [rows] = await conn.query(
|
||||
'SELECT uid, first_name, last_name, email, phone_number FROM users WHERE uid = ? LIMIT 1',
|
||||
[uid]
|
||||
);
|
||||
if (!rows.length) {
|
||||
conn.release();
|
||||
return res.status(404).json({ message: 'User tidak ditemukan.' });
|
||||
}
|
||||
userRow = rows[0];
|
||||
|
||||
await conn.beginTransaction();
|
||||
await conn.query('DELETE FROM cifo_deposits WHERE uid = ?', [uid]);
|
||||
await conn.query('DELETE FROM internet_payments WHERE uid = ?', [uid]);
|
||||
|
@ -490,9 +502,32 @@ exports.deleteAccountAndData = async (req, res, next) => {
|
|||
await conn.query('DELETE FROM app_logs WHERE user_uid = ?', [uid]);
|
||||
await conn.query('DELETE FROM users WHERE uid = ?', [uid]);
|
||||
await conn.commit();
|
||||
|
||||
try {
|
||||
await sendEmail(
|
||||
userRow.email,
|
||||
'Konfirmasi Penghapusan Akun - Wallet Cifo',
|
||||
`
|
||||
<p>Halo ${userRow.first_name} ${userRow.last_name},</p>
|
||||
<p>Akun Anda beserta seluruh data terkait telah <strong>berhasil dihapus</strong>.</p>
|
||||
<p>Rincian akun yang dihapus:</p>
|
||||
<ul>
|
||||
<li><strong>UID:</strong> ${userRow.uid}</li>
|
||||
<li><strong>Nama:</strong> ${userRow.first_name} ${userRow.last_name}</li>
|
||||
<li><strong>Email:</strong> ${userRow.email}</li>
|
||||
<li><strong>Nomor HP:</strong> ${userRow.phone_number || '-'}</li>
|
||||
</ul>
|
||||
<p>Jika Anda tidak melakukan tindakan ini, segera hubungi tim dukungan kami.</p>
|
||||
<p>Salam,<br>Tim Wallet Cifo</p>
|
||||
`
|
||||
);
|
||||
} catch (mailErr) {
|
||||
console.error('Gagal mengirim email konfirmasi hapus akun:', mailErr);
|
||||
}
|
||||
|
||||
return res.json({ message: 'Akun dan semua data terkait berhasil dihapus.' });
|
||||
} catch (err) {
|
||||
await conn.rollback();
|
||||
try { await conn.rollback(); } catch (_) {}
|
||||
next(err);
|
||||
} finally {
|
||||
conn.release();
|
||||
|
|
Loading…
Reference in New Issue