Spaces:
Build error
Build error
twenty / packages /twenty-server /src /engine /metadata-modules /flat-command-menu-item /services /workspace-flat-command-menu-item-map-cache.service.ts
| import { Injectable } from '@nestjs/common'; | |
| import { InjectRepository } from '@nestjs/typeorm'; | |
| import { Repository } from 'typeorm'; | |
| import { WorkspaceCacheProvider } from 'src/engine/workspace-cache/interfaces/workspace-cache-provider.service'; | |
| import { ApplicationEntity } from 'src/engine/core-modules/application/application.entity'; | |
| import { CommandMenuItemEntity } from 'src/engine/metadata-modules/command-menu-item/entities/command-menu-item.entity'; | |
| import { type FlatCommandMenuItemMaps } from 'src/engine/metadata-modules/flat-command-menu-item/types/flat-command-menu-item-maps.type'; | |
| import { fromCommandMenuItemEntityToFlatCommandMenuItem } from 'src/engine/metadata-modules/flat-command-menu-item/utils/from-command-menu-item-entity-to-flat-command-menu-item.util'; | |
| import { createEmptyFlatEntityMaps } from 'src/engine/metadata-modules/flat-entity/constant/create-empty-flat-entity-maps.constant'; | |
| import { FrontComponentEntity } from 'src/engine/metadata-modules/front-component/entities/front-component.entity'; | |
| import { ObjectMetadataEntity } from 'src/engine/metadata-modules/object-metadata/object-metadata.entity'; | |
| import { PageLayoutEntity } from 'src/engine/metadata-modules/page-layout/entities/page-layout.entity'; | |
| import { InjectWorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/inject-workspace-scoped-repository.decorator'; | |
| import { WorkspaceScopedRepository } from 'src/engine/twenty-orm/workspace-scoped-repository/workspace-scoped-repository'; | |
| import { WorkspaceCache } from 'src/engine/workspace-cache/decorators/workspace-cache.decorator'; | |
| import { createIdToUniversalIdentifierMap } from 'src/engine/workspace-cache/utils/create-id-to-universal-identifier-map.util'; | |
| import { addFlatEntityToFlatEntityMapsThroughMutationOrThrow } from 'src/engine/workspace-manager/workspace-migration/utils/add-flat-entity-to-flat-entity-maps-through-mutation-or-throw.util'; | |
| () | |
| ('flatCommandMenuItemMaps') | |
| export class WorkspaceFlatCommandMenuItemMapCacheService extends WorkspaceCacheProvider<FlatCommandMenuItemMaps> { | |
| constructor( | |
| (CommandMenuItemEntity) | |
| private readonly commandMenuItemRepository: WorkspaceScopedRepository<CommandMenuItemEntity>, | |
| (ApplicationEntity) | |
| private readonly applicationRepository: Repository<ApplicationEntity>, | |
| (ObjectMetadataEntity) | |
| private readonly objectMetadataRepository: Repository<ObjectMetadataEntity>, | |
| (FrontComponentEntity) | |
| private readonly frontComponentRepository: Repository<FrontComponentEntity>, | |
| (PageLayoutEntity) | |
| private readonly pageLayoutRepository: WorkspaceScopedRepository<PageLayoutEntity>, | |
| ) { | |
| super(); | |
| } | |
| async computeForCache(workspaceId: string): Promise<FlatCommandMenuItemMaps> { | |
| const [ | |
| commandMenuItems, | |
| applications, | |
| objectMetadatas, | |
| frontComponents, | |
| pageLayouts, | |
| ] = await Promise.all([ | |
| this.commandMenuItemRepository.find(workspaceId, { | |
| withDeleted: true, | |
| }), | |
| this.applicationRepository.find({ | |
| where: { workspaceId }, | |
| select: ['id', 'universalIdentifier'], | |
| withDeleted: true, | |
| }), | |
| this.objectMetadataRepository.find({ | |
| where: { workspaceId }, | |
| select: ['id', 'universalIdentifier'], | |
| withDeleted: true, | |
| }), | |
| this.frontComponentRepository.find({ | |
| where: { workspaceId }, | |
| select: ['id', 'universalIdentifier'], | |
| withDeleted: true, | |
| }), | |
| this.pageLayoutRepository.find(workspaceId, { | |
| select: ['id', 'universalIdentifier'], | |
| withDeleted: true, | |
| }), | |
| ]); | |
| const applicationIdToUniversalIdentifierMap = | |
| createIdToUniversalIdentifierMap(applications); | |
| const objectMetadataIdToUniversalIdentifierMap = | |
| createIdToUniversalIdentifierMap(objectMetadatas); | |
| const frontComponentIdToUniversalIdentifierMap = | |
| createIdToUniversalIdentifierMap(frontComponents); | |
| const pageLayoutIdToUniversalIdentifierMap = | |
| createIdToUniversalIdentifierMap(pageLayouts); | |
| const flatCommandMenuItemMaps = createEmptyFlatEntityMaps(); | |
| for (const commandMenuItemEntity of commandMenuItems) { | |
| const flatCommandMenuItem = | |
| fromCommandMenuItemEntityToFlatCommandMenuItem({ | |
| entity: commandMenuItemEntity, | |
| applicationIdToUniversalIdentifierMap, | |
| objectMetadataIdToUniversalIdentifierMap, | |
| frontComponentIdToUniversalIdentifierMap, | |
| pageLayoutIdToUniversalIdentifierMap, | |
| }); | |
| addFlatEntityToFlatEntityMapsThroughMutationOrThrow({ | |
| flatEntity: flatCommandMenuItem, | |
| flatEntityMapsToMutate: flatCommandMenuItemMaps, | |
| }); | |
| } | |
| return flatCommandMenuItemMaps; | |
| } | |
| } | |