Skip to content

Commit af71412

Browse files
committed
Add new parameters to table settings update and controller methods
1 parent 1131cf7 commit af71412

2 files changed

Lines changed: 54 additions & 46 deletions

File tree

backend/src/entities/table-settings/common-table-settings/table-settings.controller.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,10 @@ export class TableSettingsController {
191191
@Body('icon') icon: string,
192192
@Body('allow_csv_export') allow_csv_export: boolean,
193193
@Body('allow_csv_import') allow_csv_import: boolean,
194+
@Body('list_per_page') list_per_page: number,
195+
@Body('list_fields') list_fields: string[],
196+
@Body('ordering') ordering: string,
197+
@Body('ordering_field') ordering_field: string,
194198
@UserId() userId: string,
195199
@MasterPassword() masterPwd: string,
196200
): Promise<FoundTableSettingsDs> {
@@ -215,6 +219,10 @@ export class TableSettingsController {
215219
icon: icon,
216220
allow_csv_export: allow_csv_export,
217221
allow_csv_import: allow_csv_import,
222+
list_fields,
223+
ordering,
224+
ordering_field,
225+
list_per_page,
218226
};
219227

220228
const errors = this.validateParameters(inputData);

backend/src/entities/table-settings/common-table-settings/use-cases/update-table-settings.use.case.ts

Lines changed: 46 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -16,52 +16,52 @@ import { buildValidateTableSettingsDS } from '@rocketadmin/shared-code/dist/src/
1616

1717
@Injectable({ scope: Scope.REQUEST })
1818
export class UpdateTableSettingsUseCase
19-
extends AbstractUseCase<CreateTableSettingsDs, FoundTableSettingsDs>
20-
implements IUpdateTableSettings
19+
extends AbstractUseCase<CreateTableSettingsDs, FoundTableSettingsDs>
20+
implements IUpdateTableSettings
2121
{
22-
constructor(
23-
@Inject(BaseType.GLOBAL_DB_CONTEXT)
24-
protected _dbContext: IGlobalDatabaseContext,
25-
) {
26-
super();
27-
}
22+
constructor(
23+
@Inject(BaseType.GLOBAL_DB_CONTEXT)
24+
protected _dbContext: IGlobalDatabaseContext,
25+
) {
26+
super();
27+
}
2828

29-
protected async implementation(inputData: CreateTableSettingsDs): Promise<FoundTableSettingsDs> {
30-
const { connection_id, masterPwd, table_name } = inputData;
31-
const foundConnection = await this._dbContext.connectionRepository.findAndDecryptConnection(
32-
connection_id,
33-
masterPwd,
34-
);
35-
const dao = getDataAccessObject(foundConnection);
36-
const tableSettingsDs: ValidateTableSettingsDS = buildValidateTableSettingsDS(inputData);
37-
const errors: Array<string> = await dao.validateSettings(tableSettingsDs, table_name, undefined);
38-
if (errors.length > 0) {
39-
throw new HttpException(
40-
{
41-
message: toPrettyErrorsMsg(errors),
42-
},
43-
HttpStatus.BAD_REQUEST,
44-
);
45-
}
46-
const settingsToUpdate = await this._dbContext.tableSettingsRepository.findTableSettings(connection_id, table_name);
47-
if (!settingsToUpdate) {
48-
throw new HttpException(
49-
{
50-
message: Messages.TABLE_SETTINGS_NOT_FOUND,
51-
},
52-
HttpStatus.BAD_REQUEST,
53-
);
54-
}
55-
const updateTableSettings = buildNewTableSettingsEntity(inputData, foundConnection);
56-
for (const key in updateTableSettings) {
57-
// eslint-disable-next-line security/detect-object-injection
58-
if (updateTableSettings[key] === undefined) {
59-
// eslint-disable-next-line security/detect-object-injection
60-
delete updateTableSettings[key];
61-
}
62-
}
63-
const updated = Object.assign(settingsToUpdate, updateTableSettings);
64-
const savedTableSettings = await this._dbContext.tableSettingsRepository.saveNewOrUpdatedSettings(updated);
65-
return buildFoundTableSettingsDs(savedTableSettings);
66-
}
29+
protected async implementation(inputData: CreateTableSettingsDs): Promise<FoundTableSettingsDs> {
30+
const { connection_id, masterPwd, table_name } = inputData;
31+
const foundConnection = await this._dbContext.connectionRepository.findAndDecryptConnection(
32+
connection_id,
33+
masterPwd,
34+
);
35+
const dao = getDataAccessObject(foundConnection);
36+
const tableSettingsDs: ValidateTableSettingsDS = buildValidateTableSettingsDS(inputData);
37+
const errors: Array<string> = await dao.validateSettings(tableSettingsDs, table_name, undefined);
38+
if (errors.length > 0) {
39+
throw new HttpException(
40+
{
41+
message: toPrettyErrorsMsg(errors),
42+
},
43+
HttpStatus.BAD_REQUEST,
44+
);
45+
}
46+
const settingsToUpdate = await this._dbContext.tableSettingsRepository.findTableSettings(connection_id, table_name);
47+
if (!settingsToUpdate) {
48+
throw new HttpException(
49+
{
50+
message: Messages.TABLE_SETTINGS_NOT_FOUND,
51+
},
52+
HttpStatus.BAD_REQUEST,
53+
);
54+
}
55+
const updateTableSettings = buildNewTableSettingsEntity(inputData, foundConnection);
56+
for (const key in updateTableSettings) {
57+
// eslint-disable-next-line security/detect-object-injection
58+
if (updateTableSettings[key] === undefined) {
59+
// eslint-disable-next-line security/detect-object-injection
60+
delete updateTableSettings[key];
61+
}
62+
}
63+
const updated = Object.assign(settingsToUpdate, updateTableSettings);
64+
const savedTableSettings = await this._dbContext.tableSettingsRepository.saveNewOrUpdatedSettings(updated);
65+
return buildFoundTableSettingsDs(savedTableSettings);
66+
}
6767
}

0 commit comments

Comments
 (0)