feat: complete admin backend controllers and services

- AdminPlansController & Service (CRUD, reorder)
- AdminPaymentMethodsController & Service (CRUD, reorder)
- AdminPaymentsController & Service (verify, reject, pending count)
- AdminUsersController & Service (search, suspend, grant pro access, stats)
- AdminConfigController & Service (dynamic config management)
- Wire all controllers into AdminModule
- Import AdminModule in AppModule

Admin API Routes:
- GET/POST/PUT/DELETE /admin/plans
- GET/POST/PUT/DELETE /admin/payment-methods
- GET /admin/payments (with status filter)
- POST /admin/payments/:id/verify
- POST /admin/payments/:id/reject
- GET /admin/users (with search)
- POST /admin/users/:id/grant-pro
- GET/POST/DELETE /admin/config

All routes protected by AuthGuard + AdminGuard
This commit is contained in:
dwindown
2025-10-11 14:32:45 +07:00
parent 9b789b333f
commit 12850ab12d
53 changed files with 3098 additions and 34 deletions

View File

@@ -0,0 +1,116 @@
"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' },
});
}
};
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