chore: add new route to get admin permissons
This commit is contained in:
+3
-3
@@ -7,13 +7,13 @@ import { ConfigModule } from "@nestjs/config";
|
|||||||
import { ThrottlerModule } from "@nestjs/throttler";
|
import { ThrottlerModule } from "@nestjs/throttler";
|
||||||
import { TypeOrmModule } from "@nestjs/typeorm";
|
import { TypeOrmModule } from "@nestjs/typeorm";
|
||||||
import { MailerModule } from "@nestjs-modules/mailer";
|
import { MailerModule } from "@nestjs-modules/mailer";
|
||||||
import { TelegrafModule } from "nestjs-telegraf";
|
// import { TelegrafModule } from "nestjs-telegraf";
|
||||||
|
|
||||||
import { bullMqConfig } from "./configs/bullmq.config";
|
import { bullMqConfig } from "./configs/bullmq.config";
|
||||||
import { cacheConfig } from "./configs/cache.config";
|
import { cacheConfig } from "./configs/cache.config";
|
||||||
import { mailerConfig } from "./configs/mailer.config";
|
import { mailerConfig } from "./configs/mailer.config";
|
||||||
import { rateLimitConfig } from "./configs/rateLimit.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 { databaseConfigs } from "./configs/typeorm.config";
|
||||||
import { HTTPLogger } from "./core/middlewares/logger.middleware";
|
import { HTTPLogger } from "./core/middlewares/logger.middleware";
|
||||||
import { AddressModule } from "./modules/address/address.module";
|
import { AddressModule } from "./modules/address/address.module";
|
||||||
@@ -42,7 +42,7 @@ import { WalletsModule } from "./modules/wallets/wallets.module";
|
|||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
TelegrafModule.forRootAsync(telegrafConfig()),
|
// TelegrafModule.forRootAsync(telegrafConfig()),
|
||||||
MailerModule.forRootAsync(mailerConfig()),
|
MailerModule.forRootAsync(mailerConfig()),
|
||||||
BullModule.forRootAsync(bullMqConfig()),
|
BullModule.forRootAsync(bullMqConfig()),
|
||||||
ThrottlerModule.forRootAsync(rateLimitConfig()),
|
ThrottlerModule.forRootAsync(rateLimitConfig()),
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function databaseConfigs(): TypeOrmModuleAsyncOptions {
|
|||||||
username: configService.getOrThrow<string>("DB_USER"),
|
username: configService.getOrThrow<string>("DB_USER"),
|
||||||
password: configService.getOrThrow<string>("DB_PASS"),
|
password: configService.getOrThrow<string>("DB_PASS"),
|
||||||
autoLoadEntities: true,
|
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,
|
logging: configService.getOrThrow<string>("NODE_ENV") == "production" ? false : true,
|
||||||
migrationsTableName: "typeorm_migrations",
|
migrationsTableName: "typeorm_migrations",
|
||||||
migrationsRun: false,
|
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) {
|
async getRoles(queryDto: SearchRolesQueryDto) {
|
||||||
const { limit, skip } = PaginationUtils(queryDto);
|
const { limit, skip } = PaginationUtils(queryDto);
|
||||||
const queryBuilder = this.rolesRepository.createQueryBuilder("role");
|
const queryBuilder = this.rolesRepository.createQueryBuilder("role");
|
||||||
|
|||||||
@@ -191,6 +191,13 @@ export class UsersController {
|
|||||||
return this.adminsService.createAdmin(createDto);
|
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" })
|
@ApiOperation({ summary: "get all permissions ==> admin route" })
|
||||||
@AuthGuards()
|
@AuthGuards()
|
||||||
@PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)
|
@PermissionsDec(PermissionEnum.ADMINS, PermissionEnum.CUSTOMERS)
|
||||||
|
|||||||
Reference in New Issue
Block a user