@bitwild/rockets-auth
Version:
Rockets Auth - Complete authentication and authorization solution for NestJS with JWT, OAuth, OTP, role-based access control, and more
88 lines • 4.31 kB
JavaScript
;
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);
};
var __param = (this && this.__param) || function (paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
};
var AdminUserRolesController_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdminUserRolesController = void 0;
const nestjs_role_1 = require("@concepta/nestjs-role");
const common_1 = require("@nestjs/common");
const swagger_1 = require("@nestjs/swagger");
const admin_guard_1 = require("../../../guards/admin.guard");
const class_transformer_1 = require("class-transformer");
const class_validator_1 = require("class-validator");
class AdminAssignUserRoleDto {
}
__decorate([
(0, swagger_1.ApiProperty)({
description: 'Role ID to assign to the user',
example: '08a82592-714e-4da0-ace5-45ed3b4eb795',
}),
(0, class_transformer_1.Expose)(),
(0, class_validator_1.IsString)(),
(0, class_validator_1.IsNotEmpty)(),
__metadata("design:type", String)
], AdminAssignUserRoleDto.prototype, "roleId", void 0);
let AdminUserRolesController = AdminUserRolesController_1 = class AdminUserRolesController {
constructor(roleService) {
this.roleService = roleService;
this.logger = new common_1.Logger(AdminUserRolesController_1.name);
}
async list(userId) {
return this.roleService.getAssignedRoles({
assignment: 'user',
assignee: { id: userId },
});
}
async assign(userId, dto) {
await this.roleService.assignRole({
assignment: 'user',
assignee: { id: userId },
role: { id: dto.roleId },
});
this.logger.log(`Role ${dto.roleId} assigned to user ${userId}`);
}
};
exports.AdminUserRolesController = AdminUserRolesController;
__decorate([
(0, swagger_1.ApiOperation)({ summary: 'List roles assigned to a user' }),
(0, swagger_1.ApiParam)({ name: 'userId', required: true }),
(0, swagger_1.ApiOkResponse)({ description: 'Roles for the user' }),
(0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }),
(0, common_1.Get)(''),
__param(0, (0, common_1.Param)('userId')),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String]),
__metadata("design:returntype", Promise)
], AdminUserRolesController.prototype, "list", null);
__decorate([
(0, swagger_1.ApiOperation)({ summary: 'Assign a role to a user' }),
(0, swagger_1.ApiParam)({ name: 'userId', required: true }),
(0, swagger_1.ApiCreatedResponse)({ description: 'Role assigned' }),
(0, swagger_1.ApiBadRequestResponse)({ description: 'Invalid payload' }),
(0, swagger_1.ApiUnauthorizedResponse)({ description: 'Unauthorized' }),
(0, common_1.Post)(''),
__param(0, (0, common_1.Param)('userId')),
__param(1, (0, common_1.Body)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [String, AdminAssignUserRoleDto]),
__metadata("design:returntype", Promise)
], AdminUserRolesController.prototype, "assign", null);
exports.AdminUserRolesController = AdminUserRolesController = AdminUserRolesController_1 = __decorate([
(0, common_1.UseGuards)(admin_guard_1.AdminGuard),
(0, swagger_1.ApiBearerAuth)(),
(0, swagger_1.ApiTags)('admin'),
(0, common_1.Controller)('admin/users/:userId/roles'),
__param(0, (0, common_1.Inject)(nestjs_role_1.RoleService)),
__metadata("design:paramtypes", [nestjs_role_1.RoleService])
], AdminUserRolesController);
//# sourceMappingURL=admin-user-roles.controller.js.map