From 2038f0a74fbfbf943e5a267b4cba14dc517b68fc Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Mon, 8 Jul 2024 13:43:22 +0700 Subject: [PATCH 1/3] feat: add condition on create bookmark --- .../reports/report-bookmark/report-bookmark.service.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/modules/reports/report-bookmark/report-bookmark.service.ts b/src/modules/reports/report-bookmark/report-bookmark.service.ts index ccf8cb6..5043619 100644 --- a/src/modules/reports/report-bookmark/report-bookmark.service.ts +++ b/src/modules/reports/report-bookmark/report-bookmark.service.ts @@ -25,7 +25,11 @@ export class ReportBookmarkService extends BaseReportService { async create(body: CreateReportBookmarkDto) { const newPayload = this.injectDefaultColumnCreate(body); - return await this.repo.save(newPayload); + const result = await this.repo.save(newPayload); + if (body.applied) { + await this.appliedFalseBookmark(result.id); + } + return result; } async getAll(query: GetReportBookmarkDto) { -- 2.40.1 From 32ae6481e6c3f724a17502d1a8e3747fd81d709a Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:22:55 +0700 Subject: [PATCH 2/3] feat: get current applied bookmark --- .../report-bookmark.controller.ts | 13 ++++++--- .../report-bookmark.service.ts | 29 +++++++++++++++++++ 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/src/modules/reports/report-bookmark/report-bookmark.controller.ts b/src/modules/reports/report-bookmark/report-bookmark.controller.ts index dfb067b..48a2acd 100644 --- a/src/modules/reports/report-bookmark/report-bookmark.controller.ts +++ b/src/modules/reports/report-bookmark/report-bookmark.controller.ts @@ -35,16 +35,21 @@ export class ReportBookmarkController { return await this.service.getAll(query); } - @Get('id') - async get(@Param('id') id: string) { - return await this.service.getOne(id); - } + // @Get(':id') + // async get(@Param('id') id: string) { + // return await this.service.getOne(id); + // } @Get('label-history') async getAllLabelHistory(@Query() query: GetLabelReportBookmarkDto) { return await this.service.getAllLabelHistory(query); } + @Get('applied') + async currentApplied(@Query() query: GetLabelReportBookmarkDto) { + return await this.service.getCurrentAppliedBookmark(query); + } + @Put('applied/:id') async applied(@Param('id') id: string) { return await this.service.applied(id); diff --git a/src/modules/reports/report-bookmark/report-bookmark.service.ts b/src/modules/reports/report-bookmark/report-bookmark.service.ts index 5043619..7bd7823 100644 --- a/src/modules/reports/report-bookmark/report-bookmark.service.ts +++ b/src/modules/reports/report-bookmark/report-bookmark.service.ts @@ -96,6 +96,35 @@ export class ReportBookmarkService extends BaseReportService { return newData.map((el) => el.ReportBookmarkModel_label); } + async getCurrentAppliedBookmark(query: GetLabelReportBookmarkDto) { + const modelName = ReportBookmarkModel.name; + + const creator_id = this.getUser().id; + const unique_names = query.unique_names; + const group_names = query.group_names; + const types = query.types; + const qb = this.repo + .createQueryBuilder(modelName) + .where((query) => { + if (unique_names) { + query.andWhere(`unique_name IN (:...unique_names)`, { unique_names }); + } + if (group_names) { + query.andWhere(`group_name IN (:...group_names)`, { group_names }); + } + + if (types) { + query.andWhere(`type IN (:...types)`, { types }); + } + + query.andWhere(`creator_id = :creator_id`, { creator_id }); + query.andWhere(`applied = :applied`, { applied: true }); + }) + .orderBy(`${modelName}.created_at`, 'DESC'); + + return await qb.getMany(); + } + async applied(id: string) { await this.repo .createQueryBuilder() -- 2.40.1 From 677732d511447965cd4e48a868199fc7079693be Mon Sep 17 00:00:00 2001 From: Firman Ramdhani <33869609+firmanramdhani@users.noreply.github.com> Date: Mon, 8 Jul 2024 16:52:23 +0700 Subject: [PATCH 3/3] feat: adjustment dto create export --- src/modules/reports/shared/dto/report-export.create.dto.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/reports/shared/dto/report-export.create.dto.ts b/src/modules/reports/shared/dto/report-export.create.dto.ts index 973dd6a..087c2e2 100644 --- a/src/modules/reports/shared/dto/report-export.create.dto.ts +++ b/src/modules/reports/shared/dto/report-export.create.dto.ts @@ -8,8 +8,9 @@ export class CreateReportExportDto extends GetReportDataDto { @IsString() time_zone: string; - @ApiProperty({ name: 'file_name', required: true }) + @ApiProperty({ name: 'file_name', required: false }) @IsString() + @IsOptional() file_name?: string; @ApiProperty({ -- 2.40.1