Skip to content

Commit

Permalink
Fix: Set editing version as latest version on imports (ToolJet#4117)
Browse files Browse the repository at this point in the history
* set editing version as latest version on imports

* handle empty versions case
  • Loading branch information
akshaysasidrn authored Sep 27, 2022
1 parent 0740b4c commit 6305207
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions server/src/services/app_import_export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { GroupPermission } from 'src/entities/group_permission.entity';
import { AppGroupPermission } from 'src/entities/app_group_permission.entity';
import { DataSourcesService } from './data_sources.service';
import { dbTransactionWrap } from 'src/helpers/utils.helper';
import { isEmpty } from 'lodash';

@Injectable()
export class AppImportExportService {
Expand Down Expand Up @@ -190,6 +191,17 @@ export class AppImportExportService {
version.definition = this.replaceDataQueryIdWithinDefinitions(version.definition, dataQueryMapping);
await manager.save(version);
}

await this.setEditingVersionAsLatestVersion(manager, appVersionMapping, appVersions);
}

async setEditingVersionAsLatestVersion(manager: EntityManager, appVersionMapping: any, appVersions: Array<any>) {
if (isEmpty(appVersions)) return;

const lastVersionFromImport = appVersions[appVersions.length - 1];
const lastVersionIdToUpdate = appVersionMapping[lastVersionFromImport.id];

await manager.update(AppVersion, { id: lastVersionIdToUpdate }, { updatedAt: new Date() });
}

async createAdminGroupPermissions(manager: EntityManager, app: App) {
Expand Down

0 comments on commit 6305207

Please sign in to comment.