add new @WorkspaceIsSearchable decorator + updates services + add migration command (#10507)

closes https://github.com/twentyhq/core-team-issues/issues/345
This commit is contained in:
Etienne
2025-02-27 13:57:07 +01:00
committed by GitHub
parent 17dbb634ca
commit 39543872e6
54 changed files with 297 additions and 145 deletions

View File

@ -7,22 +7,22 @@ import { Command } from 'nest-commander';
import { Repository } from 'typeorm';
import {
ActiveWorkspacesMigrationCommandOptions,
ActiveWorkspacesMigrationCommandRunner,
} from 'src/database/commands/migration-command/active-workspaces-migration-command.runner';
MaintainedWorkspacesMigrationCommandOptions,
MaintainedWorkspacesMigrationCommandRunner,
} from 'src/database/commands/migration-command/maintained-workspaces-migration-command.runner';
import { BillingCustomer } from 'src/engine/core-modules/billing/entities/billing-customer.entity';
import { StripeSubscriptionService } from 'src/engine/core-modules/billing/stripe/services/stripe-subscription.service';
import { Workspace } from 'src/engine/core-modules/workspace/workspace.entity';
import { TwentyORMGlobalManager } from 'src/engine/twenty-orm/twenty-orm-global.manager';
interface SyncCustomerDataCommandOptions
extends ActiveWorkspacesMigrationCommandOptions {}
extends MaintainedWorkspacesMigrationCommandOptions {}
@Command({
name: 'billing:sync-customer-data',
description: 'Sync customer data from Stripe for all active workspaces',
})
export class BillingSyncCustomerDataCommand extends ActiveWorkspacesMigrationCommandRunner {
export class BillingSyncCustomerDataCommand extends MaintainedWorkspacesMigrationCommandRunner {
constructor(
@InjectRepository(Workspace, 'core')
protected readonly workspaceRepository: Repository<Workspace>,
@ -34,7 +34,7 @@ export class BillingSyncCustomerDataCommand extends ActiveWorkspacesMigrationCom
super(workspaceRepository, twentyORMGlobalManager);
}
async runMigrationCommandOnActiveWorkspaces(
async runMigrationCommandOnMaintainedWorkspaces(
_passedParam: string[],
options: SyncCustomerDataCommandOptions,
workspaceIds: string[],

View File

@ -20,6 +20,7 @@ const mockObjectMetadata: ObjectMetadataInterface = {
isActive: true,
isRemote: false,
isAuditLogged: true,
isSearchable: true,
};
describe('objectRecordChangedValues', () => {

View File

@ -18,6 +18,7 @@ export const mockObjectMetadataItemsWithFieldMaps: ObjectMetadataItemWithFieldMa
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
fromRelations: [],
toRelations: [],
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
@ -76,6 +77,7 @@ export const mockObjectMetadataItemsWithFieldMaps: ObjectMetadataItemWithFieldMa
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
fromRelations: [],
toRelations: [],
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
@ -153,6 +155,7 @@ export const mockObjectMetadataItemsWithFieldMaps: ObjectMetadataItemWithFieldMa
isActive: true,
isSystem: false,
isAuditLogged: true,
isSearchable: true,
fromRelations: [],
toRelations: [],
labelIdentifierFieldMetadataId: 'nameFieldMetadataId',
@ -230,6 +233,7 @@ export const mockObjectMetadataItemsWithFieldMaps: ObjectMetadataItemWithFieldMa
isActive: true,
isSystem: true,
isAuditLogged: true,
isSearchable: false,
fromRelations: [],
toRelations: [],
labelIdentifierFieldMetadataId: '',

View File

@ -19,7 +19,7 @@ describe('GlobalSearchService', () => {
});
describe('filterObjectMetadataItems', () => {
it('should return searchable object metadata items -- TODO isSearchable only', () => {
it('should return searchable object metadata items', () => {
const objectMetadataItems = service.filterObjectMetadataItems(
mockObjectMetadataItemsWithFieldMaps,
[],

View File

@ -22,20 +22,9 @@ export class GlobalSearchService {
excludedObjectNameSingulars: string[] | undefined,
) {
return objectMetadataItemWithFieldMaps.filter(
({ nameSingular, isSystem, isRemote, isCustom }) => {
if (excludedObjectNameSingulars?.includes(nameSingular)) {
return false;
}
//TODO - #345 issue - IsSearchable decorator
if (isSystem || isRemote) {
return false;
}
({ nameSingular, isSearchable }) => {
return (
isCustom ||
['company', 'person', 'opportunity', 'note', 'task'].includes(
nameSingular,
)
!excludedObjectNameSingulars?.includes(nameSingular) && isSearchable
);
},
);