Spaces:
Build error
Build error
twenty / packages /twenty-server /src /engine /metadata-modules /page-layout /controllers /page-layout.controller.ts
| import { | |
| Body, | |
| Controller, | |
| Delete, | |
| Get, | |
| Param, | |
| Patch, | |
| Post, | |
| Query, | |
| UseFilters, | |
| UseGuards, | |
| } from '@nestjs/common'; | |
| import { PermissionFlagType } from 'twenty-shared/constants'; | |
| import { isDefined } from 'twenty-shared/utils'; | |
| import { WorkspaceEntity } from 'src/engine/core-modules/workspace/workspace.entity'; | |
| import { AuthWorkspace } from 'src/engine/decorators/auth/auth-workspace.decorator'; | |
| import { NoPermissionGuard } from 'src/engine/guards/no-permission.guard'; | |
| import { SettingsPermissionGuard } from 'src/engine/guards/settings-permission.guard'; | |
| import { WorkspaceAuthGuard } from 'src/engine/guards/workspace-auth.guard'; | |
| import { FlatEntityMapsRestApiExceptionFilter } from 'src/engine/metadata-modules/flat-entity/filters/flat-entity-maps-rest-api-exception.filter'; | |
| import { CreatePageLayoutInput } from 'src/engine/metadata-modules/page-layout/dtos/inputs/create-page-layout.input'; | |
| import { UpdatePageLayoutInput } from 'src/engine/metadata-modules/page-layout/dtos/inputs/update-page-layout.input'; | |
| import { type PageLayoutDTO } from 'src/engine/metadata-modules/page-layout/dtos/page-layout.dto'; | |
| import { PageLayoutType } from 'src/engine/metadata-modules/page-layout/enums/page-layout-type.enum'; | |
| import { PageLayoutRestApiExceptionFilter } from 'src/engine/metadata-modules/page-layout/filters/page-layout-rest-api-exception.filter'; | |
| import { PageLayoutService } from 'src/engine/metadata-modules/page-layout/services/page-layout.service'; | |
| import { PermissionsRestApiExceptionFilter } from 'src/engine/metadata-modules/permissions/utils/permissions-rest-api-exception.filter'; | |
| import { WorkspaceMigrationRunnerRestApiExceptionFilter } from 'src/engine/workspace-manager/workspace-migration/filters/workspace-migration-runner-rest-api-exception.filter'; | |
| ('rest/metadata/pageLayouts') | |
| (WorkspaceAuthGuard) | |
| ( | |
| PermissionsRestApiExceptionFilter, | |
| PageLayoutRestApiExceptionFilter, | |
| FlatEntityMapsRestApiExceptionFilter, | |
| WorkspaceMigrationRunnerRestApiExceptionFilter, | |
| ) | |
| export class PageLayoutController { | |
| constructor(private readonly pageLayoutService: PageLayoutService) {} | |
| () | |
| (NoPermissionGuard) | |
| async findMany( | |
| () workspace: WorkspaceEntity, | |
| ('objectMetadataId') objectMetadataId?: string, | |
| ('pageLayoutType') pageLayoutType?: PageLayoutType, | |
| ): Promise<PageLayoutDTO[]> { | |
| if (isDefined(objectMetadataId)) { | |
| return this.pageLayoutService.findBy({ | |
| workspaceId: workspace.id, | |
| filter: { | |
| objectMetadataId, | |
| pageLayoutType, | |
| }, | |
| }); | |
| } | |
| return this.pageLayoutService.findByWorkspaceId(workspace.id); | |
| } | |
| (':id') | |
| (NoPermissionGuard) | |
| async findOne( | |
| ('id') id: string, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<PageLayoutDTO | null> { | |
| return this.pageLayoutService.findByIdOrThrow({ | |
| id, | |
| workspaceId: workspace.id, | |
| }); | |
| } | |
| () | |
| (SettingsPermissionGuard(PermissionFlagType.LAYOUTS)) | |
| async create( | |
| () input: CreatePageLayoutInput, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<PageLayoutDTO> { | |
| return this.pageLayoutService.create({ | |
| createPageLayoutInput: input, | |
| workspaceId: workspace.id, | |
| }); | |
| } | |
| (':id') | |
| (SettingsPermissionGuard(PermissionFlagType.LAYOUTS)) | |
| async update( | |
| ('id') id: string, | |
| () input: UpdatePageLayoutInput, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<PageLayoutDTO> { | |
| const updatedPageLayout = await this.pageLayoutService.update({ | |
| id, | |
| workspaceId: workspace.id, | |
| updateData: input, | |
| }); | |
| return updatedPageLayout; | |
| } | |
| (':id') | |
| (SettingsPermissionGuard(PermissionFlagType.LAYOUTS)) | |
| async destroy( | |
| ('id') id: string, | |
| () workspace: WorkspaceEntity, | |
| ): Promise<boolean> { | |
| return this.pageLayoutService.destroy({ | |
| id, | |
| workspaceId: workspace.id, | |
| }); | |
| } | |
| } | |