tiers controller acid missing

Signed-off-by: Kenneth Obsequio <k80308392@gmail.com>
This commit is contained in:
2026-08-31 11:00:29 +08:00
parent 53ae20a2cc
commit 1d2c6f1ad8
+13 -5
View File
@@ -10,6 +10,9 @@
***********************************************************************************************************************************************************************/
const { Op, ForeignKeyConstraintError } = require('sequelize');
const sequelize = require('../../config/db.config');
const { withTransactionRetry } = require('../../utils/withTransactionRetry.util');
const mdl_TierCategories = require('../../models/tiers/tier_categories.mdl');
const mdl_TierPlans = require('../../models/tiers/tier_plans.mdl');
const mdl_UserTiers = require('../../models/tiers/user_tiers.mdl');
@@ -348,9 +351,12 @@ exports.permanentlyDeletePlan = async (req, res) => {
// by default) — a plan can't be force-destroyed while payment rows still
// reference it, so those rows are force-destroyed first. This permanently
// erases that plan's payment/billing history; there is no undo.
const deleted_payment_count = await mdl_Payments.destroy({ where: { plan_id: plan.plan_id }, force: true });
const deleted_payment_count = await withTransactionRetry(sequelize, async (t) => {
const count = await mdl_Payments.destroy({ where: { plan_id: plan.plan_id }, force: true, transaction: t });
await plan.destroy({ force: true, transaction: t });
return count;
});
await plan.destroy({ force: true });
logActivity(req.user?.user_id, 'permanently_delete_tier_plan', { entityType: 'tier_plan', details: { label: plan.label, deleted_payment_count, revoked_user_count } });
return R.success(res, 'Plan permanently deleted.', { deleted_payment_count, revoked_user_count });
} catch (err) {
@@ -387,9 +393,11 @@ exports.bulkPermanentlyDeletePlans = async (req, res) => {
// by default) — plans can't be force-destroyed while payment rows still
// reference them, so those rows are force-destroyed first. This permanently
// erases these plans' payment/billing history; there is no undo.
const deleted_payment_count = await mdl_Payments.destroy({ where: { plan_id: archivedIds }, force: true });
await mdl_TierPlans.destroy({ where: { plan_id: archivedIds }, force: true });
const deleted_payment_count = await withTransactionRetry(sequelize, async (t) => {
const count = await mdl_Payments.destroy({ where: { plan_id: archivedIds }, force: true, transaction: t });
await mdl_TierPlans.destroy({ where: { plan_id: archivedIds }, force: true, transaction: t });
return count;
});
logActivity(req.user?.user_id, 'bulk_permanently_delete_tier_plans', { entityType: 'tier_plan', details: { ids: archivedIds, count: archivedIds.length, deleted_payment_count, revoked_user_count } });
return R.success(res, `${archivedIds.length} plan(s) permanently deleted.`, {