- Install sonner package and create Toaster component - Add toast notifications to all admin dashboard operations: * AdminPlans: create, update, delete, reorder, toggle visibility * AdminPaymentMethods: create, update, delete, reorder, toggle active * AdminUsers: suspend, unsuspend, grant pro access * AdminPayments: verify, reject * AdminSettings: save settings - Add toast notifications to all member dashboard operations: * Wallets: create, update, delete * Transactions: create, update, delete * Profile: update name, avatar, phone, password, delete account * OTP: enable/disable email, WhatsApp, authenticator - Replace all alert() calls with toast.success/error/warning - Add proper success/error messages in Bahasa Indonesia - Implement smart plan deletion (permanent if no subscriptions, soft delete if has subscriptions) - Fix admin redirect after login (admin goes to /admin, users to /) - Exclude admin accounts from subscription distribution chart - Show inactive plans with visual indicators - Add real revenue data to admin dashboard charts - Use formatLargeNumber for consistent number formatting
97 lines
3.4 KiB
JavaScript
97 lines
3.4 KiB
JavaScript
"use strict";
|
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
};
|
|
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
};
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
exports.AdminPlansService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const prisma_service_1 = require("../prisma/prisma.service");
|
|
let AdminPlansService = class AdminPlansService {
|
|
prisma;
|
|
constructor(prisma) {
|
|
this.prisma = prisma;
|
|
}
|
|
async findAll() {
|
|
return this.prisma.plan.findMany({
|
|
orderBy: { sortOrder: 'asc' },
|
|
include: {
|
|
_count: {
|
|
select: { subscriptions: true },
|
|
},
|
|
},
|
|
});
|
|
}
|
|
async findOne(id) {
|
|
return this.prisma.plan.findUnique({
|
|
where: { id },
|
|
include: {
|
|
_count: {
|
|
select: { subscriptions: true },
|
|
},
|
|
},
|
|
});
|
|
}
|
|
async create(data) {
|
|
return this.prisma.plan.create({
|
|
data,
|
|
});
|
|
}
|
|
async update(id, data) {
|
|
return this.prisma.plan.update({
|
|
where: { id },
|
|
data,
|
|
});
|
|
}
|
|
async delete(id) {
|
|
const plan = await this.prisma.plan.findUnique({
|
|
where: { id },
|
|
include: {
|
|
_count: {
|
|
select: { subscriptions: true },
|
|
},
|
|
},
|
|
});
|
|
if (!plan) {
|
|
throw new Error('Plan not found');
|
|
}
|
|
if (plan._count.subscriptions > 0) {
|
|
return {
|
|
success: false,
|
|
message: `Cannot delete plan. There are ${plan._count.subscriptions} active subscription(s) associated with this plan. The plan has been deactivated instead.`,
|
|
action: 'deactivated',
|
|
plan: await this.prisma.plan.update({
|
|
where: { id },
|
|
data: { isActive: false, isVisible: false },
|
|
}),
|
|
};
|
|
}
|
|
await this.prisma.plan.delete({
|
|
where: { id },
|
|
});
|
|
return {
|
|
success: true,
|
|
message: 'Plan permanently deleted',
|
|
action: 'deleted',
|
|
};
|
|
}
|
|
async reorder(planIds) {
|
|
const updates = planIds.map((id, index) => this.prisma.plan.update({
|
|
where: { id },
|
|
data: { sortOrder: index + 1 },
|
|
}));
|
|
await this.prisma.$transaction(updates);
|
|
return { success: true };
|
|
}
|
|
};
|
|
exports.AdminPlansService = AdminPlansService;
|
|
exports.AdminPlansService = AdminPlansService = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
|
], AdminPlansService);
|
|
//# sourceMappingURL=admin-plans.service.js.map
|