feat/privilege #28
|
@ -9,7 +9,7 @@ import {
|
|||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import {
|
||||
GetLabelReportBookmarkDto,
|
||||
|
@ -26,11 +26,13 @@ export class ReportBookmarkController {
|
|||
constructor(private service: ReportBookmarkService) {}
|
||||
|
||||
@Post()
|
||||
@ExcludePrivilege()
|
||||
async create(@Body() body: CreateReportBookmarkDto) {
|
||||
return await this.service.create(body);
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ExcludePrivilege()
|
||||
async getAll(@Query() query: GetReportBookmarkDto) {
|
||||
return await this.service.getAll(query);
|
||||
}
|
||||
|
@ -41,26 +43,31 @@ export class ReportBookmarkController {
|
|||
// }
|
||||
|
||||
@Get('label-history')
|
||||
@ExcludePrivilege()
|
||||
async getAllLabelHistory(@Query() query: GetLabelReportBookmarkDto) {
|
||||
return await this.service.getAllLabelHistory(query);
|
||||
}
|
||||
|
||||
@Get('applied')
|
||||
@ExcludePrivilege()
|
||||
async currentApplied(@Query() query: GetLabelReportBookmarkDto) {
|
||||
return await this.service.getCurrentAppliedBookmark(query);
|
||||
}
|
||||
|
||||
@Put('applied/:id')
|
||||
@ExcludePrivilege()
|
||||
async applied(@Param('id') id: string) {
|
||||
return await this.service.applied(id);
|
||||
}
|
||||
|
||||
@Put('unapplied/:id')
|
||||
@ExcludePrivilege()
|
||||
async unapplied(@Param('id') id: string) {
|
||||
return await this.service.unapplied(id);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ExcludePrivilege()
|
||||
async delete(@Param('id') id: string) {
|
||||
return await this.service.delete(id);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,7 @@ import {
|
|||
Query,
|
||||
} from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { CreateReportExportDto } from '../shared/dto/report-export.create.dto';
|
||||
import {
|
||||
|
@ -26,27 +26,32 @@ export class ReportExportController {
|
|||
constructor(private service: ReportExportService) {}
|
||||
|
||||
@Post()
|
||||
@ExcludePrivilege()
|
||||
async create(@Body() body: CreateReportExportDto) {
|
||||
await this.service.create(body);
|
||||
return { message: 'Processing request export data.' };
|
||||
}
|
||||
|
||||
@Get()
|
||||
@ExcludePrivilege()
|
||||
async getAll(@Query() query: GetReportExportDto) {
|
||||
return await this.service.getAll(query);
|
||||
}
|
||||
|
||||
@Delete(':id')
|
||||
@ExcludePrivilege()
|
||||
async delete(@Param('id') id: string) {
|
||||
return await this.service.delete(id);
|
||||
}
|
||||
|
||||
@Get('processing')
|
||||
@ExcludePrivilege()
|
||||
async getAllProcessing(@Query() query: GetReportExportProcessingDto) {
|
||||
return await this.service.getAllProcessing(query);
|
||||
}
|
||||
|
||||
@Get('filename-history')
|
||||
@ExcludePrivilege()
|
||||
async getListHistoryFileName(@Query() query: GetReportExportFileNameDto) {
|
||||
return await this.service.getListHistoryFileName(query);
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { Body, Controller, Get, Post, Query } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { ReportService } from './report.service';
|
||||
import { GetReportConfigDto } from '../shared/dto/report-config.get.dto';
|
||||
|
@ -13,16 +13,19 @@ import { GetReportDataDto } from '../shared/dto/report-data.get.dto';
|
|||
export class ReportController {
|
||||
constructor(private service: ReportService) {}
|
||||
@Get('config')
|
||||
@ExcludePrivilege()
|
||||
async getReportConfig(@Query() query: GetReportConfigDto) {
|
||||
return await this.service.getReportConfig(query);
|
||||
}
|
||||
|
||||
@Post('data')
|
||||
@ExcludePrivilege()
|
||||
async getReportData(@Body() body: GetReportDataDto) {
|
||||
return await this.service.getReportData(body);
|
||||
}
|
||||
|
||||
@Post('meta')
|
||||
@ExcludePrivilege()
|
||||
async getReportMeta(@Body() body: GetReportDataDto) {
|
||||
return await this.service.getReportMeta(body);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,125 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import { UserPrivilegeConfigurationEntity } from '../../../entities/user-privilege-configuration.entity';
|
||||
import {
|
||||
Param,
|
||||
RelationParam,
|
||||
} from 'src/core/modules/domain/entities/base-filter.entity';
|
||||
import { BaseIndexManager } from 'src/core/modules/domain/usecase/managers/base-index.manager';
|
||||
import { ORDER_TYPE } from 'src/core/strings/constants/base.constants';
|
||||
import { SelectQueryBuilder } from 'typeorm';
|
||||
import { FilterMenuUserPrivilegeConfigurationDto } from 'src/modules/user-related/user-privilege/infrastructure/dto/filter-menu-user-privilege-configuration.dto';
|
||||
import { mod } from 'mathjs';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { UserRole } from 'src/modules/user-related/user/constants';
|
||||
import { UserPrivilegeConfigurationHelper } from '../helpers/generate-user-privilege-configuration.helper';
|
||||
|
||||
@Injectable()
|
||||
export class MenuUserPrivilegeConfigurationManager extends BaseIndexManager<UserPrivilegeConfigurationEntity> {
|
||||
async prepareData(): Promise<void> {
|
||||
Object.assign(this.filterParam, {
|
||||
order_by: `${this.tableName}.index`,
|
||||
order_type: ORDER_TYPE.ASC,
|
||||
limit: 100,
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
async beforeProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
async afterProcess(): Promise<void> {
|
||||
return;
|
||||
}
|
||||
|
||||
get relations(): RelationParam {
|
||||
return {
|
||||
joinRelations: [],
|
||||
selectRelations: [],
|
||||
countRelations: [],
|
||||
};
|
||||
}
|
||||
|
||||
get selects(): string[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
get specificFilter(): Param[] {
|
||||
return [];
|
||||
}
|
||||
|
||||
setQueryFilter(
|
||||
queryBuilder: SelectQueryBuilder<UserPrivilegeConfigurationEntity>,
|
||||
): SelectQueryBuilder<UserPrivilegeConfigurationEntity> {
|
||||
if (this.filterParam.modules) {
|
||||
queryBuilder.andWhere('module In (:...modules)', {
|
||||
modules: this.filterParam.modules,
|
||||
});
|
||||
}
|
||||
|
||||
if (this.filterParam.menus) {
|
||||
queryBuilder.andWhere('menu In (:...menus)', {
|
||||
menus: this.filterParam.menus,
|
||||
});
|
||||
}
|
||||
|
||||
queryBuilder.andWhere('user_privilege_id = :user_privilege_id', {
|
||||
user_privilege_id: this.userProvider.user.user_privilege_id,
|
||||
});
|
||||
|
||||
queryBuilder.andWhere('view = :view', {
|
||||
view: true,
|
||||
});
|
||||
|
||||
return queryBuilder;
|
||||
}
|
||||
|
||||
getMenuSuperAdmin(params: FilterMenuUserPrivilegeConfigurationDto) {
|
||||
const modules = params?.modules ?? [];
|
||||
const menus = params?.menus ?? [];
|
||||
let configs = UserPrivilegeConfigurationHelper.createConfigurations();
|
||||
|
||||
if (modules.length > 0) {
|
||||
configs = configs.filter((item) => modules.includes(item.module));
|
||||
}
|
||||
|
||||
if (menus.length > 0) {
|
||||
configs = configs.filter((item) => menus.includes(item.menu));
|
||||
}
|
||||
|
||||
const newResult = configs.map((item) => {
|
||||
const newItem = item;
|
||||
|
||||
item.actions?.forEach((element) => {
|
||||
item[element] = true;
|
||||
});
|
||||
|
||||
newItem.actions = undefined;
|
||||
|
||||
const cleanData = Object.entries(newItem)
|
||||
.filter(([key, value]) => value !== undefined)
|
||||
.reduce((obj, [key, value]) => {
|
||||
obj[key] = value;
|
||||
return obj;
|
||||
}, {});
|
||||
|
||||
return cleanData;
|
||||
});
|
||||
|
||||
return newResult as any;
|
||||
}
|
||||
|
||||
getResult(): PaginationResponse<UserPrivilegeConfigurationEntity> {
|
||||
const role = this.userProvider.user.role;
|
||||
const isSuperAdmin = role === UserRole.SUPERADMIN;
|
||||
|
||||
if (isSuperAdmin) {
|
||||
return {
|
||||
data: this.getMenuSuperAdmin(this.filterParam),
|
||||
total: 100,
|
||||
};
|
||||
}
|
||||
|
||||
return this.result;
|
||||
}
|
||||
}
|
|
@ -5,12 +5,14 @@ import { UserPrivilegeConfigurationService } from '../../../data/service/user-pr
|
|||
import { IndexUserPrivilegeConfigurationManager } from './managers/index-user-privilege-configuration.manager';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { TABLE_NAME } from 'src/core/strings/constants/table.constants';
|
||||
import { MenuUserPrivilegeConfigurationManager } from './managers/menu-user-privilege-configuration.manager';
|
||||
|
||||
@Injectable()
|
||||
export class UserPrivilegeConfigurationDataOrchestrator {
|
||||
constructor(
|
||||
private updateManager: UpdateUserPrivilegeConfigurationManager,
|
||||
private indexManager: IndexUserPrivilegeConfigurationManager,
|
||||
private privilegeMenuManager: MenuUserPrivilegeConfigurationManager,
|
||||
private serviceData: UserPrivilegeConfigurationService,
|
||||
) {}
|
||||
|
||||
|
@ -35,4 +37,21 @@ export class UserPrivilegeConfigurationDataOrchestrator {
|
|||
await this.indexManager.execute();
|
||||
return this.indexManager.getResult();
|
||||
}
|
||||
|
||||
async privilegeMenu(
|
||||
params,
|
||||
): Promise<PaginationResponse<UserPrivilegeConfigurationEntity>> {
|
||||
this.privilegeMenuManager.setFilterParam({
|
||||
page: 1,
|
||||
limit: 100,
|
||||
...(params ?? {}),
|
||||
});
|
||||
|
||||
this.privilegeMenuManager.setService(
|
||||
this.serviceData,
|
||||
TABLE_NAME.USER_PRIVILEGE_CONFIGURATION,
|
||||
);
|
||||
await this.privilegeMenuManager.execute();
|
||||
return this.privilegeMenuManager.getResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
import { ApiProperty } from '@nestjs/swagger';
|
||||
import { Transform } from 'class-transformer';
|
||||
|
||||
export class FilterMenuUserPrivilegeConfigurationDto {
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
modules: string[];
|
||||
|
||||
@ApiProperty({ type: ['string'], required: false })
|
||||
@Transform((body) => {
|
||||
return Array.isArray(body.value) ? body.value : [body.value];
|
||||
})
|
||||
menus: string[];
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
import { Body, Controller, Get, Param, Put, Query } from '@nestjs/common';
|
||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||
import { Public } from 'src/core/guards';
|
||||
import { ExcludePrivilege, Public } from 'src/core/guards';
|
||||
import { MODULE_NAME } from 'src/core/strings/constants/module.constants';
|
||||
import { UserPrivilegeConfigurationDataOrchestrator } from '../domain/usecases/user-privilege-configuration/user-privilege-configuration-data.orchestrator';
|
||||
import { UserPrivilegeConfigurationDto } from './dto/user-privilege-configuration.dto';
|
||||
|
@ -8,6 +8,7 @@ import { UserPrivilegeConfigurationEntity } from '../domain/entities/user-privil
|
|||
import { FilterUserPrivilegeConfigurationDto } from './dto/filter-user-privilege-configuration.dto';
|
||||
import { PaginationResponse } from 'src/core/response/domain/ok-response.interface';
|
||||
import { Pagination } from 'src/core/response';
|
||||
import { FilterMenuUserPrivilegeConfigurationDto } from './dto/filter-menu-user-privilege-configuration.dto';
|
||||
|
||||
@ApiTags(
|
||||
`${MODULE_NAME.USER_PRIVILEGE_CONFIGURATION.split('-').join(' ')} - data`,
|
||||
|
@ -34,4 +35,12 @@ export class UserPrivilegeConfigurationController {
|
|||
): Promise<PaginationResponse<UserPrivilegeConfigurationEntity>> {
|
||||
return await this.orchestrator.index(params);
|
||||
}
|
||||
|
||||
@Get('/menu')
|
||||
@ExcludePrivilege()
|
||||
async privilegeMenu(
|
||||
@Query() params: FilterMenuUserPrivilegeConfigurationDto,
|
||||
): Promise<UserPrivilegeConfigurationEntity[]> {
|
||||
return (await this.orchestrator.privilegeMenu(params)).data ?? [];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,6 +27,7 @@ import { UserPrivilegeConfigurationController } from './infrastructure/user-priv
|
|||
import { UserPrivilegeConfigurationDataOrchestrator } from './domain/usecases/user-privilege-configuration/user-privilege-configuration-data.orchestrator';
|
||||
import { IndexUserPrivilegeConfigurationManager } from './domain/usecases/user-privilege-configuration/managers/index-user-privilege-configuration.manager';
|
||||
import { UserPrivilegeModels } from './constants';
|
||||
import { MenuUserPrivilegeConfigurationManager } from './domain/usecases/user-privilege-configuration/managers/menu-user-privilege-configuration.manager';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
|
@ -55,6 +56,7 @@ import { UserPrivilegeModels } from './constants';
|
|||
|
||||
IndexUserPrivilegeConfigurationManager,
|
||||
UpdateUserPrivilegeConfigurationManager,
|
||||
MenuUserPrivilegeConfigurationManager,
|
||||
|
||||
UserPrivilegeDataService,
|
||||
UserPrivilegeReadService,
|
||||
|
|
Loading…
Reference in New Issue