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
Expand Up @@ -3,29 +3,29 @@ import { QueryOrderingEnum } from '../../../../enums/query-ordering.enum.js';
import { IsBoolean, IsEnum, IsOptional } from 'class-validator';

export class CreatePersonalTableSettingsDto {
@ApiProperty({ enumName: 'QueryOrderingEnum', enum: QueryOrderingEnum, description: 'The ordering direction' })
@IsOptional()
@IsEnum(QueryOrderingEnum)
ordering: QueryOrderingEnum;
@ApiProperty({ enumName: 'QueryOrderingEnum', enum: QueryOrderingEnum, description: 'The ordering direction' })
@IsOptional()
@IsEnum(QueryOrderingEnum)
ordering: QueryOrderingEnum;

@ApiProperty({ type: String, description: 'The ordering field' })
@IsOptional()
ordering_field: string;
@ApiProperty({ type: String, description: 'The ordering field' })
@IsOptional()
ordering_field: string;

@ApiProperty({ type: Number, description: 'The number of items per page' })
@IsOptional()
list_per_page: number;
@ApiProperty({ type: Number, description: 'The number of items per page' })
@IsOptional()
list_per_page: number;

@ApiProperty({ isArray: true, type: String, description: 'The columns view' })
@IsOptional()
columns_view: Array<string>;
@ApiProperty({ isArray: true, type: String, description: 'The columns view' })
@IsOptional()
columns_view: Array<string>;

@ApiProperty({ type: [String], description: 'The order of columns' })
@IsOptional()
list_fields: Array<string>;
@ApiProperty({ type: [String], description: 'The order of columns' })
@IsOptional()
list_fields: Array<string>;

@ApiProperty({ type: Boolean, description: 'Whether to use original column names' })
@IsOptional()
@IsBoolean()
original_names: boolean;
@ApiProperty({ type: Boolean, description: 'Whether to use original column names' })
@IsOptional()
@IsBoolean()
original_names: boolean;
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import {
Body,
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Inject,
Injectable,
Put,
UseGuards,
UseInterceptors,
Body,
Controller,
Delete,
Get,
HttpException,
HttpStatus,
Inject,
Injectable,
Put,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiQuery, ApiResponse, ApiTags } from '@nestjs/swagger';
import { SentryInterceptor } from '../../../interceptors/sentry.interceptor.js';
import { UseCaseType } from '../../../common/data-injection.tokens.js';
import {
ICreateUpdatePersonalTableSettings,
IDeletePersonalTableSettings,
IFindPersonalTableSettings,
ICreateUpdatePersonalTableSettings,
IDeletePersonalTableSettings,
IFindPersonalTableSettings,
} from './use-cases/personal-table-settings.use-cases.interface.js';
import { TableReadGuard } from '../../../guards/table-read.guard.js';
import { UserId } from '../../../decorators/user-id.decorator.js';
Expand All @@ -37,123 +37,123 @@ import { CreatePersonalTableSettingsDto } from './dto/create-personal-table-sett
@ApiTags('Personal table settings')
@Injectable()
export class PersonalTableSettingsController {
constructor(
@Inject(UseCaseType.FIND_PERSONAL_TABLE_SETTINGS)
private readonly findPersonalTableSettingsUseCase: IFindPersonalTableSettings,
@Inject(UseCaseType.CREATE_UPDATE_PERSONAL_TABLE_SETTINGS)
private readonly createUpdatePersonalTableSettingsUseCase: ICreateUpdatePersonalTableSettings,
@Inject(UseCaseType.DELETE_PERSONAL_TABLE_SETTINGS)
private readonly deletePersonalTableSettingsUseCase: IDeletePersonalTableSettings,
) {}
constructor(
@Inject(UseCaseType.FIND_PERSONAL_TABLE_SETTINGS)
private readonly findPersonalTableSettingsUseCase: IFindPersonalTableSettings,
@Inject(UseCaseType.CREATE_UPDATE_PERSONAL_TABLE_SETTINGS)
private readonly createUpdatePersonalTableSettingsUseCase: ICreateUpdatePersonalTableSettings,
@Inject(UseCaseType.DELETE_PERSONAL_TABLE_SETTINGS)
private readonly deletePersonalTableSettingsUseCase: IDeletePersonalTableSettings,
) {}

@ApiOperation({ summary: 'Find user personal table settings' })
@ApiResponse({
status: 200,
description: 'Table settings found.',
type: FoundPersonalTableSettingsDto,
})
@ApiParam({ name: 'connectionId', required: true })
@ApiQuery({ name: 'tableName', required: true })
@UseGuards(TableReadGuard)
@Get('/settings/personal/:connectionId')
async findAll(
@SlugUuid('connectionId') connectionId: string,
@QueryTableName() tableName: string,
@MasterPassword() masterPwd: string,
@UserId() userId: string,
): Promise<FoundPersonalTableSettingsDto> {
if (!connectionId) {
throw new HttpException(
{
message: Messages.CONNECTION_ID_MISSING,
},
HttpStatus.BAD_REQUEST,
);
}
const inputData: FindPersonalTableSettingsDs = {
connectionId,
tableName,
userId,
masterPassword: masterPwd,
};
return await this.findPersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF);
}
@ApiOperation({ summary: 'Find user personal table settings' })
@ApiResponse({
status: 200,
description: 'Table settings found.',
type: FoundPersonalTableSettingsDto,
})
@ApiParam({ name: 'connectionId', required: true })
@ApiQuery({ name: 'tableName', required: true })
@UseGuards(TableReadGuard)
@Get('/settings/personal/:connectionId')
async findAll(
@SlugUuid('connectionId') connectionId: string,
@QueryTableName() tableName: string,
@MasterPassword() masterPwd: string,
@UserId() userId: string,
): Promise<FoundPersonalTableSettingsDto> {
if (!connectionId) {
throw new HttpException(
{
message: Messages.CONNECTION_ID_MISSING,
},
HttpStatus.BAD_REQUEST,
);
}
const inputData: FindPersonalTableSettingsDs = {
connectionId,
tableName,
userId,
masterPassword: masterPwd,
};
return await this.findPersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF);
}

@ApiOperation({ summary: 'Create or update user personal table settings' })
@ApiResponse({
status: 200,
description: 'Table settings crated/updated.',
type: FoundPersonalTableSettingsDto,
})
@ApiBody({ type: CreatePersonalTableSettingsDto })
@ApiParam({ name: 'connectionId', required: true })
@ApiQuery({ name: 'tableName', required: true })
@UseGuards(TableReadGuard)
@Put('/settings/personal/:connectionId')
async createOrUpdate(
@SlugUuid('connectionId') connectionId: string,
@QueryTableName() tableName: string,
@MasterPassword() masterPwd: string,
@UserId() userId: string,
@Body() personalSettingsData: CreatePersonalTableSettingsDto,
): Promise<FoundPersonalTableSettingsDto> {
if (!connectionId) {
throw new HttpException(
{
message: Messages.CONNECTION_ID_MISSING,
},
HttpStatus.BAD_REQUEST,
);
}
const inputData: CreatePersonalTableSettingsDs = {
table_settings_metadata: {
connection_id: connectionId,
table_name: tableName,
user_id: userId,
master_password: masterPwd,
},
table_settings_data: {
columns_view: personalSettingsData.columns_view || null,
list_fields: personalSettingsData.list_fields || null,
list_per_page: personalSettingsData.list_per_page || null,
ordering: personalSettingsData.ordering || null,
ordering_field: personalSettingsData.ordering_field || null,
original_names: personalSettingsData.original_names || null,
},
};
return await this.createUpdatePersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF);
}
@ApiOperation({ summary: 'Create or update user personal table settings' })
@ApiResponse({
status: 200,
description: 'Table settings crated/updated.',
type: FoundPersonalTableSettingsDto,
})
@ApiBody({ type: CreatePersonalTableSettingsDto })
@ApiParam({ name: 'connectionId', required: true })
@ApiQuery({ name: 'tableName', required: true })
@UseGuards(TableReadGuard)
@Put('/settings/personal/:connectionId')
async createOrUpdate(
@SlugUuid('connectionId') connectionId: string,
@QueryTableName() tableName: string,
@MasterPassword() masterPwd: string,
@UserId() userId: string,
@Body() personalSettingsData: CreatePersonalTableSettingsDto,
): Promise<FoundPersonalTableSettingsDto> {
if (!connectionId) {
throw new HttpException(
{
message: Messages.CONNECTION_ID_MISSING,
},
HttpStatus.BAD_REQUEST,
);
}
const inputData: CreatePersonalTableSettingsDs = {
table_settings_metadata: {
connection_id: connectionId,
table_name: tableName,
user_id: userId,
master_password: masterPwd,
},
table_settings_data: {
columns_view: personalSettingsData.columns_view || null,
list_fields: personalSettingsData.list_fields || null,
list_per_page: personalSettingsData.list_per_page || null,
ordering: personalSettingsData.ordering || null,
ordering_field: personalSettingsData.ordering_field || null,
original_names: personalSettingsData.original_names || null,
},
};
return await this.createUpdatePersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF);
}

@ApiOperation({ summary: 'Clear user personal table settings' })
@ApiResponse({
status: 200,
description: 'Table settings removed.',
type: FoundPersonalTableSettingsDto,
})
@ApiParam({ name: 'connectionId', required: true })
@ApiQuery({ name: 'tableName', required: true })
@UseGuards(TableReadGuard)
@Delete('/settings/personal/:connectionId')
async clearTableSettings(
@SlugUuid('connectionId') connectionId: string,
@QueryTableName() tableName: string,
@MasterPassword() masterPwd: string,
@UserId() userId: string,
): Promise<FoundPersonalTableSettingsDto> {
if (!connectionId) {
throw new HttpException(
{
message: Messages.CONNECTION_ID_MISSING,
},
HttpStatus.BAD_REQUEST,
);
}
const inputData: FindPersonalTableSettingsDs = {
connectionId,
tableName,
userId,
masterPassword: masterPwd,
};
return await this.deletePersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF);
}
@ApiOperation({ summary: 'Clear user personal table settings' })
@ApiResponse({
status: 200,
description: 'Table settings removed.',
type: FoundPersonalTableSettingsDto,
})
@ApiParam({ name: 'connectionId', required: true })
@ApiQuery({ name: 'tableName', required: true })
@UseGuards(TableReadGuard)
@Delete('/settings/personal/:connectionId')
async clearTableSettings(
@SlugUuid('connectionId') connectionId: string,
@QueryTableName() tableName: string,
@MasterPassword() masterPwd: string,
@UserId() userId: string,
): Promise<FoundPersonalTableSettingsDto> {
if (!connectionId) {
throw new HttpException(
{
message: Messages.CONNECTION_ID_MISSING,
},
HttpStatus.BAD_REQUEST,
);
}
const inputData: FindPersonalTableSettingsDs = {
connectionId,
tableName,
userId,
masterPassword: masterPwd,
};
return await this.deletePersonalTableSettingsUseCase.execute(inputData, InTransactionEnum.OFF);
}
}
Loading
Loading