"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