chore: add new route to get admin permissons

This commit is contained in:
mahyargdz
2025-04-20 09:51:29 +03:30
parent dc25c19ed8
commit a2088e6176
4 changed files with 21 additions and 4 deletions
+3 -3
View File
@@ -7,13 +7,13 @@ import { ConfigModule } from "@nestjs/config";
import { ThrottlerModule } from "@nestjs/throttler";
import { TypeOrmModule } from "@nestjs/typeorm";
import { MailerModule } from "@nestjs-modules/mailer";
import { TelegrafModule } from "nestjs-telegraf";
// import { TelegrafModule } from "nestjs-telegraf";
import { bullMqConfig } from "./configs/bullmq.config";
import { cacheConfig } from "./configs/cache.config";
import { mailerConfig } from "./configs/mailer.config";
import { rateLimitConfig } from "./configs/rateLimit.config";
import { telegrafConfig } from "./configs/telegraf.config";
// import { telegrafConfig } from "./configs/telegraf.config";
import { databaseConfigs } from "./configs/typeorm.config";
import { HTTPLogger } from "./core/middlewares/logger.middleware";
import { AddressModule } from "./modules/address/address.module";
@@ -42,7 +42,7 @@ import { WalletsModule } from "./modules/wallets/wallets.module";
@Module({
imports: [
TelegrafModule.forRootAsync(telegrafConfig()),
// TelegrafModule.forRootAsync(telegrafConfig()),
MailerModule.forRootAsync(mailerConfig()),
BullModule.forRootAsync(bullMqConfig()),
ThrottlerModule.forRootAsync(rateLimitConfig()),
+1 -1
View File
@@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions {
username: configService.getOrThrow<string>("DB_USER"),
password: configService.getOrThrow<string>("DB_PASS"),
autoLoadEntities: true,
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
synchronize: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : false,
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
migrationsTableName: "typeorm_migrations",
migrationsRun: false,
@@ -86,6 +86,16 @@ export class AdminsService {
}
/************************************************************ */
async getAdminPermissions(userId: string) {
const user = await this.userRepository.findOne({ where: { id: userId }, relations: { roles: { permissions: true } } });
if (!user) throw new BadRequestException(UserMessage.USER_NOT_FOUND);
return {
permissions: user.roles[0].permissions,
};
}
/************************************************************ */
async getRoles(queryDto: SearchRolesQueryDto) {
const { limit, skip } = PaginationUtils(queryDto);
const queryBuilder = this.rolesRepository.createQueryBuilder("role");
+7
View File
@@ -191,6 +191,13 @@ export class UsersController {
return this.adminsService.createAdmin(createDto);
}
@ApiOperation({ summary: "get admin permissions" })
@AuthGuards()
@Get("admin-permissions")
getAdminPermissions(@UserDec("id") userId: string) {
return this.adminsService.getAdminPermissions(userId);
}
@ApiOperation({ summary: "get all permissions ==> admin route" })
@AuthGuards()
@PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)