@@ -16,52 +16,52 @@ import { buildValidateTableSettingsDS } from '@rocketadmin/shared-code/dist/src/
1616
1717@Injectable ( { scope : Scope . REQUEST } )
1818export 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