- 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
252 lines
8.4 KiB
JavaScript
252 lines
8.4 KiB
JavaScript
"use strict";
|
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
}
|
|
Object.defineProperty(o, k2, desc);
|
|
}) : (function(o, m, k, k2) {
|
|
if (k2 === undefined) k2 = k;
|
|
o[k2] = m[k];
|
|
}));
|
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
}) : function(o, v) {
|
|
o["default"] = v;
|
|
});
|
|
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 __importStar = (this && this.__importStar) || (function () {
|
|
var ownKeys = function(o) {
|
|
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
var ar = [];
|
|
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
return ar;
|
|
};
|
|
return ownKeys(o);
|
|
};
|
|
return function (mod) {
|
|
if (mod && mod.__esModule) return mod;
|
|
var result = {};
|
|
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
__setModuleDefault(result, mod);
|
|
return result;
|
|
};
|
|
})();
|
|
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.AdminUsersService = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const prisma_service_1 = require("../prisma/prisma.service");
|
|
const bcrypt = __importStar(require("bcrypt"));
|
|
let AdminUsersService = class AdminUsersService {
|
|
prisma;
|
|
constructor(prisma) {
|
|
this.prisma = prisma;
|
|
}
|
|
async findAll(search) {
|
|
return this.prisma.user.findMany({
|
|
where: search
|
|
? {
|
|
OR: [
|
|
{ email: { contains: search, mode: 'insensitive' } },
|
|
{ name: { contains: search, mode: 'insensitive' } },
|
|
],
|
|
}
|
|
: undefined,
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
role: true,
|
|
emailVerified: true,
|
|
createdAt: true,
|
|
lastLoginAt: true,
|
|
suspendedAt: true,
|
|
_count: {
|
|
select: {
|
|
wallets: true,
|
|
transactions: true,
|
|
},
|
|
},
|
|
},
|
|
orderBy: { createdAt: 'desc' },
|
|
});
|
|
}
|
|
async findOne(id) {
|
|
return this.prisma.user.findUnique({
|
|
where: { id },
|
|
include: {
|
|
subscriptions: {
|
|
include: {
|
|
plan: true,
|
|
},
|
|
},
|
|
_count: {
|
|
select: {
|
|
wallets: true,
|
|
transactions: true,
|
|
payments: true,
|
|
},
|
|
},
|
|
},
|
|
});
|
|
}
|
|
async updateRole(id, role) {
|
|
return this.prisma.user.update({
|
|
where: { id },
|
|
data: { role },
|
|
});
|
|
}
|
|
async suspend(id, reason) {
|
|
return this.prisma.user.update({
|
|
where: { id },
|
|
data: {
|
|
suspendedAt: new Date(),
|
|
suspendedReason: reason,
|
|
},
|
|
});
|
|
}
|
|
async unsuspend(id) {
|
|
return this.prisma.user.update({
|
|
where: { id },
|
|
data: {
|
|
suspendedAt: null,
|
|
suspendedReason: null,
|
|
},
|
|
});
|
|
}
|
|
async grantProAccess(userId, planSlug, durationDays) {
|
|
const plan = await this.prisma.plan.findUnique({
|
|
where: { slug: planSlug },
|
|
});
|
|
if (!plan) {
|
|
throw new Error('Plan not found');
|
|
}
|
|
const now = new Date();
|
|
const endDate = new Date(now);
|
|
endDate.setDate(endDate.getDate() + durationDays);
|
|
const existing = await this.prisma.subscription.findUnique({
|
|
where: { userId },
|
|
});
|
|
if (existing) {
|
|
return this.prisma.subscription.update({
|
|
where: { userId },
|
|
data: {
|
|
planId: plan.id,
|
|
status: 'active',
|
|
startDate: now,
|
|
endDate,
|
|
},
|
|
});
|
|
}
|
|
else {
|
|
return this.prisma.subscription.create({
|
|
data: {
|
|
userId,
|
|
planId: plan.id,
|
|
status: 'active',
|
|
startDate: now,
|
|
endDate,
|
|
},
|
|
});
|
|
}
|
|
}
|
|
async getStats() {
|
|
const totalUsers = await this.prisma.user.count();
|
|
const activeSubscriptions = await this.prisma.subscription.count({
|
|
where: { status: 'active' },
|
|
});
|
|
const suspendedUsers = await this.prisma.user.count({
|
|
where: { suspendedAt: { not: null } },
|
|
});
|
|
return {
|
|
totalUsers,
|
|
activeSubscriptions,
|
|
suspendedUsers,
|
|
};
|
|
}
|
|
async create(data) {
|
|
const existing = await this.prisma.user.findUnique({
|
|
where: { email: data.email },
|
|
});
|
|
if (existing) {
|
|
throw new common_1.ConflictException('User with this email already exists');
|
|
}
|
|
const hashedPassword = await bcrypt.hash(data.password, 10);
|
|
return this.prisma.user.create({
|
|
data: {
|
|
email: data.email,
|
|
passwordHash: hashedPassword,
|
|
name: data.name || null,
|
|
role: data.role || 'user',
|
|
emailVerified: true,
|
|
},
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
role: true,
|
|
emailVerified: true,
|
|
createdAt: true,
|
|
},
|
|
});
|
|
}
|
|
async update(id, data) {
|
|
const user = await this.prisma.user.findUnique({
|
|
where: { id },
|
|
});
|
|
if (!user) {
|
|
throw new common_1.NotFoundException('User not found');
|
|
}
|
|
if (data.email && data.email !== user.email) {
|
|
const existing = await this.prisma.user.findUnique({
|
|
where: { email: data.email },
|
|
});
|
|
if (existing) {
|
|
throw new common_1.ConflictException('Email already in use');
|
|
}
|
|
}
|
|
return this.prisma.user.update({
|
|
where: { id },
|
|
data: {
|
|
...(data.email && { email: data.email }),
|
|
...(data.name !== undefined && { name: data.name }),
|
|
...(data.role && { role: data.role }),
|
|
},
|
|
select: {
|
|
id: true,
|
|
email: true,
|
|
name: true,
|
|
role: true,
|
|
emailVerified: true,
|
|
createdAt: true,
|
|
},
|
|
});
|
|
}
|
|
async delete(id) {
|
|
const user = await this.prisma.user.findUnique({
|
|
where: { id },
|
|
});
|
|
if (!user) {
|
|
throw new common_1.NotFoundException('User not found');
|
|
}
|
|
await this.prisma.user.delete({
|
|
where: { id },
|
|
});
|
|
return { message: 'User deleted successfully' };
|
|
}
|
|
};
|
|
exports.AdminUsersService = AdminUsersService;
|
|
exports.AdminUsersService = AdminUsersService = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__metadata("design:paramtypes", [prisma_service_1.PrismaService])
|
|
], AdminUsersService);
|
|
//# sourceMappingURL=admin-users.service.js.map
|