- 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
71 lines
3.0 KiB
JavaScript
71 lines
3.0 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.MaintenanceGuard = void 0;
|
|
const common_1 = require("@nestjs/common");
|
|
const core_1 = require("@nestjs/core");
|
|
const prisma_service_1 = require("../../prisma/prisma.service");
|
|
const jwt_1 = require("@nestjs/jwt");
|
|
let MaintenanceGuard = class MaintenanceGuard {
|
|
reflector;
|
|
prisma;
|
|
jwtService;
|
|
constructor(reflector, prisma, jwtService) {
|
|
this.reflector = reflector;
|
|
this.prisma = prisma;
|
|
this.jwtService = jwtService;
|
|
}
|
|
async canActivate(context) {
|
|
const isExempt = this.reflector.get('skipMaintenance', context.getHandler());
|
|
const isControllerExempt = this.reflector.get('skipMaintenance', context.getClass());
|
|
if (isExempt || isControllerExempt) {
|
|
return true;
|
|
}
|
|
const maintenanceConfig = await this.prisma.appConfig.findUnique({
|
|
where: { key: 'maintenance_mode' },
|
|
});
|
|
const isMaintenanceMode = maintenanceConfig?.value === 'true';
|
|
if (!isMaintenanceMode) {
|
|
return true;
|
|
}
|
|
const request = context.switchToHttp().getRequest();
|
|
const authHeader = request.headers.authorization;
|
|
if (authHeader && authHeader.startsWith('Bearer ')) {
|
|
try {
|
|
const token = authHeader.substring(7);
|
|
const payload = this.jwtService.verify(token);
|
|
if (payload.role === 'admin') {
|
|
return true;
|
|
}
|
|
}
|
|
catch (error) {
|
|
}
|
|
}
|
|
const messageConfig = await this.prisma.appConfig.findUnique({
|
|
where: { key: 'maintenance_message' },
|
|
});
|
|
const message = messageConfig?.value ||
|
|
'System is under maintenance. Please try again later.';
|
|
throw new common_1.ServiceUnavailableException({
|
|
statusCode: 503,
|
|
message: message,
|
|
maintenanceMode: true,
|
|
});
|
|
}
|
|
};
|
|
exports.MaintenanceGuard = MaintenanceGuard;
|
|
exports.MaintenanceGuard = MaintenanceGuard = __decorate([
|
|
(0, common_1.Injectable)(),
|
|
__metadata("design:paramtypes", [core_1.Reflector,
|
|
prisma_service_1.PrismaService,
|
|
jwt_1.JwtService])
|
|
], MaintenanceGuard);
|
|
//# sourceMappingURL=maintenance.guard.js.map
|