Skip to content

Commit

Permalink
Merge pull request #143 from amosproj/132-frontend-module-add-task_id…
Browse files Browse the repository at this point in the history
…-in-the-backup-table

132 frontend module add task id in the backup table
  • Loading branch information
chrisklg authored Dec 8, 2024
2 parents 28d7662 + 1ed5a40 commit 006ca94
Show file tree
Hide file tree
Showing 10 changed files with 94 additions and 56 deletions.
12 changes: 6 additions & 6 deletions apps/backend/src/app/backupData/backupData.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import {
ApiTags,
} from '@nestjs/swagger';
import { BackupDataService } from './backupData.service';
import { BackupDataDto } from './dto/backupData.dto';
import { CreateBackupDataDto } from './dto/createBackupData.dto';
import { PaginationDto } from '../utils/pagination/PaginationDto';
import { PaginationOptionsDto } from '../utils/pagination/PaginationOptionsDto';
import { BackupDataFilterDto } from './dto/backupDataFilter.dto';
import { BackupDataOrderOptionsDto } from './dto/backupDataOrderOptions.dto';
import { BackupDataEntity } from './entity/backupData.entity';
import { BackupDataFilterByTaskIdsDto } from './dto/backupDataFilterByTaskIds.dto';

@ApiTags('Backup Data')
Expand All @@ -33,8 +33,8 @@ export class BackupDataController {

@Get(':id')
@ApiOperation({ summary: 'Returns the backupData Object with the given id.' })
@ApiOkResponse({ type: BackupDataDto })
async getById(@Param('id') id: string): Promise<BackupDataDto> {
@ApiOkResponse({ type: BackupDataEntity })
async getById(@Param('id') id: string): Promise<BackupDataEntity> {
const entity = await this.backupDataService.findOneById(id);
if (!entity) {
throw new NotFoundException();
Expand All @@ -55,7 +55,7 @@ export class BackupDataController {
@Query() backupDataFilterDto: BackupDataFilterDto,
@Query() backupDataOrderOptionsDto: BackupDataOrderOptionsDto,
@Body() backupDataFilterByTaskIdsDto?: BackupDataFilterByTaskIdsDto
): Promise<PaginationDto<BackupDataDto>> {
): Promise<PaginationDto<BackupDataEntity>> {
return this.backupDataService.findAll(
paginationOptionsDto,
backupDataOrderOptionsDto,
Expand All @@ -67,12 +67,12 @@ export class BackupDataController {
@Post()
@ApiOperation({ summary: 'Creates a new backupData Object.' })
@ApiCreatedResponse({
type: BackupDataDto,
type: BackupDataEntity,
description: 'The created Backup Data Object.',
})
async create(
@Body() createBackupDataDto: CreateBackupDataDto
): Promise<BackupDataDto> {
): Promise<BackupDataEntity> {
return this.backupDataService.create(createBackupDataDto);
}

Expand Down
26 changes: 20 additions & 6 deletions apps/backend/src/app/backupData/backupData.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import { InjectRepository } from '@nestjs/typeorm';
import {
Between,
FindOptionsOrder,
FindOptionsWhere,
ILike,
LessThanOrEqual,
Expand All @@ -17,10 +18,13 @@ import { CreateBackupDataDto } from './dto/createBackupData.dto';
import { PaginationOptionsDto } from '../utils/pagination/PaginationOptionsDto';
import { PaginationDto } from '../utils/pagination/PaginationDto';
import { PaginationService } from '../utils/pagination/paginationService';
import { BackupDataDto } from './dto/backupData.dto';
import { BackupDataFilterDto } from './dto/backupDataFilter.dto';
import { BackupDataOrderOptionsDto } from './dto/backupDataOrderOptions.dto';
import {
BackupDataOrderByOptions,
BackupDataOrderOptionsDto,
} from './dto/backupDataOrderOptions.dto';
import { BackupType } from './dto/backupType';
import { SortOrder } from '../utils/pagination/SortOrder';
import { TasksService } from '../tasks/tasks.service';
import { BackupDataFilterByTaskIdsDto } from './dto/backupDataFilterByTaskIds.dto';
import { TaskEntity } from '../tasks/entity/task.entity';
Expand Down Expand Up @@ -51,15 +55,14 @@ export class BackupDataService extends PaginationService {
backupDataOrderOptionsDto: BackupDataOrderOptionsDto,
backupDataFilterDto: BackupDataFilterDto,
backupDataFilterByTaskIdsDto?: BackupDataFilterByTaskIdsDto
): Promise<PaginationDto<BackupDataDto>> {
): Promise<PaginationDto<BackupDataEntity>> {
return await this.paginate<BackupDataEntity>(
this.backupDataRepository,
this.createOrderClause(backupDataOrderOptionsDto),
this.createWhereClause(backupDataFilterDto, backupDataFilterByTaskIdsDto),
paginationOptionsDto
);
}

/**
* Create a new backup data entity.
* @param createBackupDataDto
Expand Down Expand Up @@ -197,10 +200,21 @@ export class BackupDataService extends PaginationService {
* Create order clause.
* @param backupDataOrderOptionsDto
*/
createOrderClause(backupDataOrderOptionsDto: BackupDataOrderOptionsDto) {
createOrderClause(
backupDataOrderOptionsDto: BackupDataOrderOptionsDto
): FindOptionsOrder<BackupDataEntity> {
if (
backupDataOrderOptionsDto.orderBy === BackupDataOrderByOptions.TASK_NAME
) {
return {
taskId: {
displayName: backupDataOrderOptionsDto.sortOrder ?? SortOrder.DESC,
},
};
}
return {
[backupDataOrderOptionsDto.orderBy ?? 'creationDate']:
backupDataOrderOptionsDto.sortOrder ?? 'DESC',
backupDataOrderOptionsDto.sortOrder ?? SortOrder.DESC,
};
}
}
37 changes: 0 additions & 37 deletions apps/backend/src/app/backupData/dto/backupData.dto.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export enum BackupDataOrderByOptions {
ID = 'id',
SIZE = 'sizeMB',
BACKUP_DATE = 'creationDate',
TASK_NAME = 'taskName'
}

export class BackupDataOrderOptionsDto {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,20 @@ export class CustomFilter implements ClrDatagridFilterInterface<Backup> {
fromSizeMB: number | null;
toSizeMB: number | null;
id: string | null;
taskName: string | null;
} = {
fromDate: null,
toDate: null,
fromSizeMB: null,
toSizeMB: null,
id: null,
taskName: null,
};

public changes = new Subject<any>();
public filterType: 'date' | 'size' | 'id';
public filterType: 'date' | 'size' | 'id' | 'taskName';

constructor(filterType: 'date' | 'size' | 'id') {
constructor(filterType: 'date' | 'size' | 'id' | 'taskName') {
this.filterType = filterType;
}

Expand All @@ -29,6 +31,8 @@ export class CustomFilter implements ClrDatagridFilterInterface<Backup> {
return !!(this.ranges.fromDate || this.ranges.toDate);
} else if (this.filterType === 'size') {
return !!(this.ranges.fromSizeMB || this.ranges.toSizeMB);
} else if (this.filterType === 'taskName') {
return !!this.ranges.taskName;
} else {
return !!this.ranges.id;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,13 @@ <h3>All Backups:</h3>
clrInput
type="string"
[(ngModel)]="backupIdFilter.ranges.id"
(ngModelChange)="backupSizeFilter.updateRanges({ id: $event })"
(ngModelChange)="backupIdFilter.updateRanges({ id: $event })"
/>
</clr-input-container>
</clr-dg-filter> </ng-container
></clr-dg-column>
</clr-dg-filter>
</ng-container
>
</clr-dg-column>
<clr-dg-column [clrDgField]="'sizeMB'">
<ng-container *clrDgHideableColumn>
Size (MB)
Expand Down Expand Up @@ -117,6 +119,24 @@ <h3>All Backups:</h3>
</ng-container>
</clr-dg-column>

<clr-dg-column [clrDgField]="'taskName'">
<ng-container *clrDgHideableColumn>
Task
<clr-dg-filter [clrDgFilter]="taskFilter">
<clr-input-container>
<label>Task:</label>
<input
clrInput
type="string"
[(ngModel)]="taskFilter.ranges.taskName"
(ngModelChange)="taskFilter.updateRanges({ taskName: $event })"
/>
</clr-input-container>
</clr-dg-filter>
</ng-container
>
</clr-dg-column>

<clr-dg-column
[clrDgField]="'creationDate'"
[clrDgSortOrder]="ClrDatagridSortOrder.DESC"
Expand Down Expand Up @@ -154,6 +174,7 @@ <h3>All Backups:</h3>
<clr-dg-row *ngFor="let backup of backups.data" [clrDgItem]="backup">
<clr-dg-cell>{{ backup.id }}</clr-dg-cell>
<clr-dg-cell>{{ backup.sizeMB }}</clr-dg-cell>
<clr-dg-cell>{{ backup.taskId?.displayName ?? '' }}</clr-dg-cell>
<clr-dg-cell>{{ backup.creationDate | date }}</clr-dg-cell>
<clr-dg-action-overflow>
<button class="action-item">More Details</button>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';
import { TestBed } from '@angular/core/testing';
import { of } from 'rxjs';

Expand Down Expand Up @@ -126,6 +126,7 @@ describe('BackupsComponent', () => {
id: null,
fromSizeMB: null,
toSizeMB: null,
taskName: null,
};
(dateFilter.ranges as any)['_isActive'] = true;

Expand All @@ -145,6 +146,7 @@ describe('BackupsComponent', () => {
fromSizeMB: 100,
toSizeMB: 500,
id: null,
taskName: null,
};
(sizeFilter.ranges as any)['_isActive'] = true;

Expand All @@ -164,6 +166,7 @@ describe('BackupsComponent', () => {
fromSizeMB: null,
toSizeMB: null,
id: '000d88',
taskName: null,
};
(idFilter.ranges as any)['_isActive'] = true;

Expand All @@ -173,6 +176,25 @@ describe('BackupsComponent', () => {

expect(params.id).toBe(idFilter.ranges.id);
});

it('should build filter params with active task filter', () => {
const taskFilter = new CustomFilter('taskName');
taskFilter.ranges = {
fromDate: null,
toDate: null,
fromSizeMB: null,
toSizeMB: null,
id: null,
taskName: 'test',
};
(taskFilter.ranges as any)['_isActive'] = true;

component['taskFilter'] = taskFilter;

const params = component['buildFilterParams']();

expect(params.taskName).toBe(taskFilter.ranges.taskName);
});
});

describe('Lifecycle Hooks', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ export class BackupsComponent implements AfterViewInit, OnDestroy, OnInit {
map((config) => config.range)
);

loading: boolean = false;
loading = false;
pageSize = 10;
backupSizeFilter: CustomFilter;
backupDateFilter: CustomFilter;
backupIdFilter: CustomFilter;
taskFilter: CustomFilter;

readonly backups$: Observable<APIResponse<Backup>>;
readonly chartBackups$: Observable<APIResponse<Backup>>;
Expand All @@ -67,6 +68,7 @@ export class BackupsComponent implements AfterViewInit, OnDestroy, OnInit {
this.backupSizeFilter = new CustomFilter('size');
this.backupDateFilter = new CustomFilter('date');
this.backupIdFilter = new CustomFilter('id');
this.taskFilter = new CustomFilter('taskName');

this.backups$ = this.filterOptions$.pipe(
switchMap((params) => this.backupService.getAllBackups(params)),
Expand Down Expand Up @@ -111,6 +113,7 @@ export class BackupsComponent implements AfterViewInit, OnDestroy, OnInit {
this.backupDateFilter.changes.pipe(startWith(null)),
this.backupSizeFilter.changes.pipe(startWith(null)),
this.backupIdFilter.changes.pipe(startWith(null)),
this.taskFilter.changes.pipe(startWith(null)),
])
.pipe(
map(() => this.buildFilterParams()),
Expand Down Expand Up @@ -176,6 +179,10 @@ export class BackupsComponent implements AfterViewInit, OnDestroy, OnInit {
params.id = this.backupIdFilter.ranges.id;
}

if (this.taskFilter.isActive()) {
params.taskName = this.taskFilter.ranges.taskName;
}

return params;
}

Expand Down
2 changes: 2 additions & 0 deletions apps/frontend/src/app/shared/types/backup-filter-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,6 @@ export type BackupFilterParams = {
fromSizeMB?: number | null;
toSizeMB?: number | null;
id?: string | null;
taskId?: string | null;
taskName?: string | null;
};
4 changes: 4 additions & 0 deletions apps/frontend/src/app/shared/types/backup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,8 @@ export interface Backup {
id: string;
sizeMB: number;
creationDate: Date;
taskId?: {
id: string;
displayName: string;
};
}

0 comments on commit 006ca94

Please sign in to comment.