feat: adjustment api get config report

pull/26/head
Firman Ramdhani 2024-07-09 18:44:05 +07:00
parent 56e7d25acd
commit 12543ea00b
2 changed files with 49 additions and 5 deletions

View File

@ -4,11 +4,12 @@ import { ReportService } from './report.service';
import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeOrmModule } from '@nestjs/typeorm';
import { ExportReportHistoryModel } from '../shared/models/export-report-history.model'; import { ExportReportHistoryModel } from '../shared/models/export-report-history.model';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { ReportBookmarkModel } from '../shared/models/report-bookmark.model';
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature( TypeOrmModule.forFeature(
[ExportReportHistoryModel], [ExportReportHistoryModel, ReportBookmarkModel],
CONNECTION_NAME.DEFAULT, CONNECTION_NAME.DEFAULT,
), ),
], ],

View File

@ -3,13 +3,14 @@ import { BaseReportService } from '../shared/services/base-report.service';
import { GetReportConfigDto } from '../shared/dto/report-config.get.dto'; import { GetReportConfigDto } from '../shared/dto/report-config.get.dto';
import { GetReportDataDto } from '../shared/dto/report-data.get.dto'; import { GetReportDataDto } from '../shared/dto/report-data.get.dto';
import { ReportConfigs } from '../shared/configs'; import { ReportConfigs } from '../shared/configs';
import { InjectDataSource } from '@nestjs/typeorm'; import { InjectDataSource, InjectRepository } from '@nestjs/typeorm';
import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants'; import { CONNECTION_NAME } from 'src/core/strings/constants/base.constants';
import { DataSource } from 'typeorm'; import { DataSource, Repository } from 'typeorm';
import { ReportConfigEntity } from '../shared/entities/report-config.entity'; import { ReportConfigEntity } from '../shared/entities/report-config.entity';
import { ReportQueryBuilder } from '../shared/helpers'; import { ReportQueryBuilder } from '../shared/helpers';
import { DATA_FORMAT } from '../shared/constant'; import { DATA_FORMAT, REPORT_BOOKMARK_TYPE } from '../shared/constant';
import { roundingCurrency } from '../shared/helpers'; import { roundingCurrency } from '../shared/helpers';
import { ReportBookmarkModel } from '../shared/models/report-bookmark.model';
@Injectable({ scope: Scope.REQUEST }) @Injectable({ scope: Scope.REQUEST })
export class ReportService extends BaseReportService { export class ReportService extends BaseReportService {
@ -18,6 +19,9 @@ export class ReportService extends BaseReportService {
constructor( constructor(
@InjectDataSource(CONNECTION_NAME.DEFAULT) @InjectDataSource(CONNECTION_NAME.DEFAULT)
private dataSource: DataSource, private dataSource: DataSource,
@InjectRepository(ReportBookmarkModel, CONNECTION_NAME.DEFAULT)
private bookmarkRepo: Repository<ReportBookmarkModel>,
) { ) {
super(); super();
} }
@ -35,8 +39,47 @@ export class ReportService extends BaseReportService {
unique_names.includes(item.unique_name), unique_names.includes(item.unique_name),
); );
} }
const groups = Array.from(new Set(configs?.map((item) => item.group_name)));
const names = Array.from(new Set(configs?.map((item) => item.unique_name)));
return configs; const modelName = ReportBookmarkModel.name;
const creator_id = this.getUser().id;
const bookmarkConfigs = await this.bookmarkRepo
.createQueryBuilder(modelName)
.where((query) => {
if (names.length > 0) {
query.andWhere(`group_name IN (:...groups)`, { groups });
}
if (groups.length > 0) {
query.andWhere(`unique_name IN (:...names)`, { names });
}
query.andWhere(`creator_id = :creator_id`, { creator_id });
query.andWhere(`applied = :applied`, { applied: true });
})
.getMany();
return configs.map((item) => {
const active_filter = bookmarkConfigs.find(
(conf) =>
conf.group_name === item.group_name &&
conf.unique_name === item.unique_name &&
conf.type === REPORT_BOOKMARK_TYPE.FILTER_TABLE,
);
const active_table_config = bookmarkConfigs.find(
(conf) =>
conf.group_name === item.group_name &&
conf.unique_name === item.unique_name &&
conf.type === REPORT_BOOKMARK_TYPE.TABLE_CONFIG,
);
return {
...item,
active_filter: active_filter ?? {},
active_table_config: active_table_config ?? {},
};
});
} }
getReportConfigByUniqueName(group_name, unique_name): ReportConfigEntity { getReportConfigByUniqueName(group_name, unique_name): ReportConfigEntity {