Skip to content

Commit f793faa

Browse files
authored
17042 followups (#17122)
Followups after @Weiko review on #17042
1 parent 869a0a7 commit f793faa

File tree

4 files changed

+66
-18
lines changed

4 files changed

+66
-18
lines changed

packages/twenty-server/src/engine/metadata-modules/page-layout-tab/controllers/page-layout-tab.controller.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import {
1111
UseGuards,
1212
} from '@nestjs/common';
1313

14-
import { isDefined } from 'twenty-shared/utils';
1514
import { PermissionFlagType } from 'twenty-shared/constants';
15+
import { isDefined } from 'twenty-shared/utils';
1616

17+
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
18+
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
19+
import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard';
20+
import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
21+
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
1722
import { CreatePageLayoutTabInput } from 'src/engine/metadata-modules/page-layout-tab/dtos/inputs/create-page-layout-tab.input';
1823
import { UpdatePageLayoutTabInput } from 'src/engine/metadata-modules/page-layout-tab/dtos/inputs/update-page-layout-tab.input';
1924
import { type PageLayoutTabDTO } from 'src/engine/metadata-modules/page-layout-tab/dtos/page-layout-tab.dto';
@@ -25,11 +30,6 @@ import {
2530
} from 'src/engine/metadata-modules/page-layout-tab/exceptions/page-layout-tab.exception';
2631
import { PageLayoutTabRestApiExceptionFilter } from 'src/engine/metadata-modules/page-layout-tab/filters/page-layout-tab-rest-api-exception.filter';
2732
import { PageLayoutTabService } from 'src/engine/metadata-modules/page-layout-tab/services/page-layout-tab.service';
28-
import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity';
29-
import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator';
30-
import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard';
31-
import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard';
32-
import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard';
3333

3434
@Controller('rest/metadata/pageLayoutTabs')
3535
@UseGuards(WorkspaceAuthGuard)
@@ -98,7 +98,7 @@ export class PageLayoutTabController {
9898

9999
@Delete(':id')
100100
@UseGuards(SettingsPermissionGuard(PermissionFlagType.LAYOUTS))
101-
async delete(
101+
async destroy(
102102
@Param('id') id: string,
103103
@AuthWorkspace() workspace: WorkspaceEntity,
104104
): Promise<boolean> {

packages/twenty-server/src/engine/metadata-modules/page-layout-widget/controllers/page-layout-widget.controller.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export class PageLayoutWidgetController {
100100

101101
@Delete(':id')
102102
@UseGuards(SettingsPermissionGuard(PermissionFlagType.LAYOUTS))
103-
async delete(
103+
async destroy(
104104
@Param('id') id: string,
105105
@AuthWorkspace() workspace: WorkspaceEntity,
106106
): Promise<boolean> {

packages/twenty-server/src/engine/metadata-modules/page-layout/services/page-layout.service.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,57 @@ export class PageLayoutService {
350350
return true;
351351
}
352352

353+
async destroyMany({
354+
ids,
355+
workspaceId,
356+
}: {
357+
ids: string[];
358+
workspaceId: string;
359+
}): Promise<boolean> {
360+
if (ids.length === 0) {
361+
return true;
362+
}
363+
364+
const { flatPageLayoutMaps: existingFlatPageLayoutMaps } =
365+
await this.workspaceManyOrAllFlatEntityMapsCacheService.getOrRecomputeManyOrAllFlatEntityMaps(
366+
{
367+
workspaceId,
368+
flatMapsKeys: ['flatPageLayoutMaps'],
369+
},
370+
);
371+
372+
const flatPageLayoutsToDestroy = ids.map((id) =>
373+
fromDestroyPageLayoutInputToFlatPageLayoutOrThrow({
374+
destroyPageLayoutInput: { id },
375+
flatPageLayoutMaps: existingFlatPageLayoutMaps,
376+
}),
377+
);
378+
379+
const validateAndBuildResult =
380+
await this.workspaceMigrationValidateBuildAndRunService.validateBuildAndRunWorkspaceMigration(
381+
{
382+
allFlatEntityOperationByMetadataName: {
383+
pageLayout: {
384+
flatEntityToCreate: [],
385+
flatEntityToDelete: flatPageLayoutsToDestroy,
386+
flatEntityToUpdate: [],
387+
},
388+
},
389+
workspaceId,
390+
isSystemBuild: false,
391+
},
392+
);
393+
394+
if (isDefined(validateAndBuildResult)) {
395+
throw new WorkspaceMigrationBuilderException(
396+
validateAndBuildResult,
397+
'Multiple validation errors occurred while destroying page layouts',
398+
);
399+
}
400+
401+
return true;
402+
}
403+
353404
private async destroyAssociatedDashboards({
354405
pageLayoutId,
355406
workspaceId,

packages/twenty-server/src/modules/dashboard/services/dashboard-to-page-layout-sync.service.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,14 @@ export class DashboardToPageLayoutSyncService {
6969
withDeleted: true,
7070
});
7171

72-
for (const dashboard of dashboards) {
73-
if (!isDefined(dashboard.pageLayoutId)) {
74-
continue;
75-
}
72+
const pageLayoutIds = dashboards
73+
.map((dashboard) => dashboard.pageLayoutId)
74+
.filter(isDefined);
7675

77-
await this.pageLayoutService.destroy({
78-
id: dashboard.pageLayoutId,
79-
workspaceId,
80-
isLinkedDashboardAlreadyDestroyed: true,
81-
});
82-
}
76+
await this.pageLayoutService.destroyMany({
77+
ids: pageLayoutIds,
78+
workspaceId,
79+
});
8380
},
8481
);
8582
}

0 commit comments

Comments
 (0)