- Reorganized admin settings into tabbed interface (General, Security, Payment Methods) - Vertical tabs on desktop, horizontal scrollable on mobile - Moved Payment Methods from separate menu to Settings tab - Fixed admin profile reuse and dashboard blocking - Fixed maintenance mode guard to use AppConfig model - Added admin auto-redirect after login (admins → /admin, users → /) - Reorganized documentation into docs/ folder structure - Created comprehensive README and documentation index - Added PWA and Web Push notifications to to-do list
166 lines
5.6 KiB
JavaScript
166 lines
5.6 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.AdminPaymentsService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const prisma_service_1 = require("../prisma/prisma.service");
|
|
let AdminPaymentsService = class AdminPaymentsService {
|
|
prisma;
|
|
constructor(prisma) {
|
|
this.prisma = prisma;
|
|
}
|
|
async findAll(status) {
|
|
return this.prisma.payment.findMany({
|
|
where: status ? { status } : undefined,
|
|
include: {
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
},
|
|
},
|
|
subscription: {
|
|
include: {
|
|
plan: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
}
|
|
async findOne(id) {
|
|
return this.prisma.payment.findUnique({
|
|
where: { id },
|
|
include: {
|
|
user: {
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
},
|
|
},
|
|
subscription: {
|
|
include: {
|
|
plan: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
async verify(id, adminUserId) {
|
|
const payment = await this.prisma.payment.findUnique({
|
|
where: { id },
|
|
include: { subscription: { include: { plan: true } } },
|
|
});
|
|
if (!payment) {
|
|
throw new Error('Payment not found');
|
|
}
|
|
const updatedPayment = await this.prisma.payment.update({
|
|
where: { id },
|
|
data: {
|
|
status: 'paid',
|
|
verifiedBy: adminUserId,
|
|
verifiedAt: new Date(),
|
|
paidAt: new Date(),
|
|
},
|
|
});
|
|
if (payment.subscriptionId && payment.subscription) {
|
|
const plan = payment.subscription.plan;
|
|
const now = new Date();
|
|
const endDate = new Date(now);
|
|
if (plan.durationDays) {
|
|
endDate.setDate(endDate.getDate() + plan.durationDays);
|
|
}
|
|
await this.prisma.subscription.update({
|
|
where: { id: payment.subscriptionId },
|
|
data: {
|
|
status: 'active',
|
|
startDate: now,
|
|
endDate: plan.durationType === 'lifetime' ? new Date('2099-12-31') : endDate,
|
|
},
|
|
});
|
|
}
|
|
return updatedPayment;
|
|
}
|
|
async reject(id, adminUserId, reason) {
|
|
return this.prisma.payment.update({
|
|
where: { id },
|
|
data: {
|
|
status: 'rejected',
|
|
verifiedBy: adminUserId,
|
|
verifiedAt: new Date(),
|
|
rejectionReason: reason,
|
|
},
|
|
});
|
|
}
|
|
async getPendingCount() {
|
|
return this.prisma.payment.count({
|
|
where: { status: 'pending' },
|
|
});
|
|
}
|
|
async getMonthlyRevenue() {
|
|
const sixMonthsAgo = new Date();
|
|
sixMonthsAgo.setMonth(sixMonthsAgo.getMonth() - 6);
|
|
const payments = await this.prisma.payment.findMany({
|
|
where: {
|
|
status: 'paid',
|
|
paidAt: {
|
|
gte: sixMonthsAgo,
|
|
},
|
|
},
|
|
select: {
|
|
amount: true,
|
|
paidAt: true,
|
|
},
|
|
});
|
|
const monthlyData = {};
|
|
const months = [
|
|
'Jan',
|
|
'Feb',
|
|
'Mar',
|
|
'Apr',
|
|
'May',
|
|
'Jun',
|
|
'Jul',
|
|
'Aug',
|
|
'Sep',
|
|
'Oct',
|
|
'Nov',
|
|
'Dec',
|
|
];
|
|
payments.forEach((payment) => {
|
|
if (payment.paidAt) {
|
|
const date = new Date(payment.paidAt);
|
|
const monthKey = `${months[date.getMonth()]} ${date.getFullYear()}`;
|
|
if (!monthlyData[monthKey]) {
|
|
monthlyData[monthKey] = { revenue: 0, count: 0 };
|
|
}
|
|
monthlyData[monthKey].revenue += Number(payment.amount);
|
|
monthlyData[monthKey].count += 1;
|
|
}
|
|
});
|
|
const result = Object.entries(monthlyData)
|
|
.map(([month, data]) => ({
|
|
month: month.split(' ')[0],
|
|
revenue: data.revenue,
|
|
users: data.count,
|
|
}))
|
|
.slice(-6);
|
|
return result;
|
|
}
|
|
};
|
|
exports.AdminPaymentsService = AdminPaymentsService;
|
|
exports.AdminPaymentsService = AdminPaymentsService = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
|
], AdminPaymentsService);
|
|
//# sourceMappingURL=admin-payments.service.js.map
|