Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,16 +1,4 @@
import sjson from 'secure-json-parse';
import {
AfterLoad,
BeforeInsert,
BeforeUpdate,
Column,
Entity,
JoinColumn,
ManyToOne,
PrimaryGeneratedColumn,
Relation,
} from 'typeorm';
import { DashboardWidgetTypeEnum } from '../../../enums/dashboard-widget-type.enum.js';
import { Column, Entity, JoinColumn, ManyToOne, PrimaryGeneratedColumn, Relation } from 'typeorm';
import { DashboardEntity } from '../dashboard/dashboard.entity.js';
import { SavedDbQueryEntity } from '../saved-db-query/saved-db-query.entity.js';

Expand All @@ -19,18 +7,6 @@ export class DashboardWidgetEntity {
@PrimaryGeneratedColumn('uuid')
id: string;

@Column({ type: 'varchar' })
widget_type: DashboardWidgetTypeEnum;

@Column({ type: 'varchar', default: null, nullable: true })
chart_type: string | null;

@Column({ default: null, nullable: true })
name: string | null;

@Column({ type: 'text', default: null, nullable: true })
description: string | null;

@Column({ type: 'int', default: 0 })
position_x: number;

Expand All @@ -43,9 +19,6 @@ export class DashboardWidgetEntity {
@Column({ type: 'int', default: 3 })
height: number;

@Column('json', { default: null, nullable: true })
widget_options: string | null;

@Column({ type: 'uuid' })
dashboard_id: string;

Expand All @@ -63,40 +36,4 @@ export class DashboardWidgetEntity {
@ManyToOne(() => SavedDbQueryEntity, { onDelete: 'SET NULL', nullable: true })
@JoinColumn({ name: 'query_id' })
query: Relation<SavedDbQueryEntity> | null;

@BeforeUpdate()
stringifyOptionsOnUpdate(): void {
try {
if (this.widget_options && typeof this.widget_options === 'object') {
this.widget_options = JSON.stringify(this.widget_options);
}
} catch (e) {
console.error('-> Error widget options stringify ' + e.message);
}
}

@BeforeInsert()
stringifyOptions(): void {
try {
if (this.widget_options && typeof this.widget_options === 'object') {
this.widget_options = JSON.stringify(this.widget_options);
}
} catch (e) {
console.error('-> Error widget options stringify ' + e.message);
}
}

@AfterLoad()
parseOptions(): void {
try {
if (this.widget_options && typeof this.widget_options === 'string') {
this.widget_options = sjson.parse(this.widget_options, null, {
protoAction: 'remove',
constructorAction: 'remove',
});
}
} catch (e) {
console.error('-> Error widget options parse ' + e.message);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,11 @@ export class DashboardWidgetController {
connectionId,
masterPassword: masterPwd,
userId,
widget_type: createDto.widget_type,
chart_type: createDto.chart_type,
name: createDto.name,
description: createDto.description,
query_id: createDto.query_id,
position_x: createDto.position_x,
position_y: createDto.position_y,
width: createDto.width,
height: createDto.height,
widget_options: createDto.widget_options,
query_id: createDto.query_id,
};
return await this.createDashboardWidgetUseCase.execute(inputData, InTransactionEnum.ON);
}
Expand Down Expand Up @@ -110,16 +105,11 @@ export class DashboardWidgetController {
connectionId,
masterPassword: masterPwd,
userId,
widget_type: updateDto.widget_type,
chart_type: updateDto.chart_type,
name: updateDto.name,
description: updateDto.description,
query_id: updateDto.query_id,
position_x: updateDto.position_x,
position_y: updateDto.position_y,
width: updateDto.width,
height: updateDto.height,
widget_options: updateDto.widget_options,
query_id: updateDto.query_id,
};
return await this.updateDashboardWidgetUseCase.execute(inputData, InTransactionEnum.ON);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';

export class CreateDashboardWidgetDs {
dashboardId: string;
connectionId: string;
masterPassword: string;
userId: string;
widget_type: DashboardWidgetTypeEnum;
chart_type?: string;
name?: string;
description?: string;
query_id?: string;
position_x?: number;
position_y?: number;
width?: number;
height?: number;
widget_options?: Record<string, unknown>;
query_id?: string;
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,12 @@
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';

export class UpdateDashboardWidgetDs {
widgetId: string;
dashboardId: string;
connectionId: string;
masterPassword: string;
userId: string;
widget_type?: DashboardWidgetTypeEnum;
chart_type?: string;
name?: string;
description?: string;
query_id?: string;
position_x?: number;
position_y?: number;
width?: number;
height?: number;
widget_options?: Record<string, unknown>;
query_id?: string;
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsInt, IsNotEmpty, IsOptional, IsString, IsUUID, Max, Min } from 'class-validator';
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsInt, IsOptional, IsUUID, Max, Min } from 'class-validator';

export class CreateDashboardWidgetDto {
@ApiProperty({ description: 'Widget type', enum: DashboardWidgetTypeEnum })
@IsNotEmpty()
@IsEnum(DashboardWidgetTypeEnum)
widget_type: DashboardWidgetTypeEnum;

@ApiPropertyOptional({ description: 'Chart type for chart widgets' })
@IsOptional()
@IsString()
chart_type?: string;

@ApiPropertyOptional({ description: 'Widget name' })
@IsOptional()
@IsString()
name?: string;

@ApiPropertyOptional({ description: 'Widget description' })
@ApiPropertyOptional({ description: 'Associated saved query ID' })
@IsOptional()
@IsString()
description?: string;
@IsUUID()
query_id?: string;

@ApiPropertyOptional({ description: 'Position X in grid', default: 0 })
@IsOptional()
Expand All @@ -48,13 +32,4 @@ export class CreateDashboardWidgetDto {
@Min(1)
@Max(12)
height?: number;

@ApiPropertyOptional({ description: 'Visualization options as JSON' })
@IsOptional()
widget_options?: Record<string, unknown>;

@ApiPropertyOptional({ description: 'Associated saved query ID' })
@IsOptional()
@IsUUID()
query_id?: string;
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';

export class FoundDashboardWidgetDto {
@ApiProperty({ description: 'Widget ID' })
id: string;

@ApiProperty({ description: 'Widget type', enum: DashboardWidgetTypeEnum })
widget_type: DashboardWidgetTypeEnum;

@ApiPropertyOptional({ description: 'Chart type for chart widgets' })
chart_type: string | null;

@ApiPropertyOptional({ description: 'Widget name' })
name: string | null;

@ApiPropertyOptional({ description: 'Widget description' })
description: string | null;

@ApiProperty({ description: 'Position X in grid' })
position_x: number;

Expand All @@ -29,9 +16,6 @@ export class FoundDashboardWidgetDto {
@ApiProperty({ description: 'Widget height in grid units' })
height: number;

@ApiPropertyOptional({ description: 'Visualization options' })
widget_options: Record<string, unknown> | null;

@ApiProperty({ description: 'Dashboard ID' })
dashboard_id: string;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,11 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsEnum, IsInt, IsOptional, IsString, IsUUID, Max, Min } from 'class-validator';
import { DashboardWidgetTypeEnum } from '../../../../enums/dashboard-widget-type.enum.js';
import { IsInt, IsOptional, IsUUID, Max, Min } from 'class-validator';

export class UpdateDashboardWidgetDto {
@ApiPropertyOptional({ description: 'Widget type', enum: DashboardWidgetTypeEnum })
@IsOptional()
@IsEnum(DashboardWidgetTypeEnum)
widget_type?: DashboardWidgetTypeEnum;

@ApiPropertyOptional({ description: 'Chart type for chart widgets' })
@IsOptional()
@IsString()
chart_type?: string;

@ApiPropertyOptional({ description: 'Widget name' })
@IsOptional()
@IsString()
name?: string;

@ApiPropertyOptional({ description: 'Widget description' })
@ApiPropertyOptional({ description: 'Associated saved query ID' })
@IsOptional()
@IsString()
description?: string;
@IsUUID()
query_id?: string;

@ApiPropertyOptional({ description: 'Position X in grid' })
@IsOptional()
Expand All @@ -48,13 +32,4 @@ export class UpdateDashboardWidgetDto {
@Min(1)
@Max(12)
height?: number;

@ApiPropertyOptional({ description: 'Visualization options as JSON' })
@IsOptional()
widget_options?: Record<string, unknown>;

@ApiPropertyOptional({ description: 'Associated saved query ID' })
@IsOptional()
@IsUUID()
query_id?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,7 @@ export class CreateDashboardWidgetUseCase
}

public async implementation(inputData: CreateDashboardWidgetDs): Promise<FoundDashboardWidgetDto> {
const {
dashboardId,
connectionId,
masterPassword,
widget_type,
chart_type,
name,
description,
position_x,
position_y,
width,
height,
widget_options,
query_id,
} = inputData;
const { dashboardId, connectionId, masterPassword, query_id, position_x, position_y, width, height } = inputData;

const foundConnection = await this._dbContext.connectionRepository.findAndDecryptConnection(
connectionId,
Expand Down Expand Up @@ -68,15 +54,10 @@ export class CreateDashboardWidgetUseCase
}

const newWidget = new DashboardWidgetEntity();
newWidget.widget_type = widget_type;
newWidget.chart_type = chart_type || null;
newWidget.name = name || null;
newWidget.description = description || null;
newWidget.position_x = position_x ?? 0;
newWidget.position_y = position_y ?? 0;
newWidget.width = width ?? 4;
newWidget.height = height ?? 3;
newWidget.widget_options = widget_options ? JSON.stringify(widget_options) : null;
newWidget.dashboard_id = dashboardId;
newWidget.query_id = query_id || null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,8 @@ export class UpdateDashboardWidgetUseCase
}

public async implementation(inputData: UpdateDashboardWidgetDs): Promise<FoundDashboardWidgetDto> {
const {
widgetId,
dashboardId,
connectionId,
masterPassword,
widget_type,
chart_type,
name,
description,
position_x,
position_y,
width,
height,
widget_options,
query_id,
} = inputData;
const { widgetId, dashboardId, connectionId, masterPassword, query_id, position_x, position_y, width, height } =
inputData;

const foundConnection = await this._dbContext.connectionRepository.findAndDecryptConnection(
connectionId,
Expand Down Expand Up @@ -74,20 +60,9 @@ export class UpdateDashboardWidgetUseCase
if (!foundQuery) {
throw new BadRequestException(Messages.SAVED_QUERY_NOT_FOUND);
}
foundWidget.query_id = query_id;
}

if (widget_type !== undefined) {
foundWidget.widget_type = widget_type;
}
if (chart_type !== undefined) {
foundWidget.chart_type = chart_type;
}
if (name !== undefined) {
foundWidget.name = name;
}
if (description !== undefined) {
foundWidget.description = description;
}
if (position_x !== undefined) {
foundWidget.position_x = position_x;
}
Expand All @@ -100,12 +75,6 @@ export class UpdateDashboardWidgetUseCase
if (height !== undefined) {
foundWidget.height = height;
}
if (widget_options !== undefined) {
foundWidget.widget_options = widget_options ? JSON.stringify(widget_options) : null;
}
if (query_id !== undefined) {
foundWidget.query_id = query_id;
}

const savedWidget = await this._dbContext.dashboardWidgetRepository.saveWidget(foundWidget);
return buildFoundDashboardWidgetDto(savedWidget);
Expand Down
Loading
Loading