feat: conditional schema based on column map instead of column field (#1978)
* feat: wip conditional schema based on column map instead of column field * feat: conditionalSchema columnMap and singular plural * fix: remove uuid fix * feat: add name and label (singular/plural) drop old tableColumnName
This commit is contained in:
@ -4,21 +4,25 @@ import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
@InputType()
|
||||
export class CreateObjectInput {
|
||||
// Deprecated
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
displayName: string;
|
||||
nameSingular: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
displayNameSingular?: string;
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
namePlural: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
displayNamePlural?: string;
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
labelSingular: string;
|
||||
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Field()
|
||||
labelPlural: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
|
||||
@ -4,21 +4,25 @@ import { IsBoolean, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
@InputType()
|
||||
export class UpdateObjectInput {
|
||||
// Deprecated
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
displayName: string;
|
||||
@Field()
|
||||
nameSingular: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
displayNameSingular?: string;
|
||||
@Field()
|
||||
namePlural: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field({ nullable: true })
|
||||
displayNamePlural?: string;
|
||||
@Field()
|
||||
labelSingular: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
@Field()
|
||||
labelPlural: string;
|
||||
|
||||
@IsString()
|
||||
@IsOptional()
|
||||
|
||||
@ -30,7 +30,7 @@ export class BeforeCreateOneObject<T extends ObjectMetadata>
|
||||
);
|
||||
|
||||
instance.input.dataSourceId = lastDataSourceMetadata.id;
|
||||
instance.input.targetTableName = instance.input.displayName;
|
||||
instance.input.targetTableName = instance.input.nameSingular;
|
||||
instance.input.workspaceId = workspaceId;
|
||||
instance.input.isActive = false;
|
||||
instance.input.isCustom = true;
|
||||
|
||||
@ -40,21 +40,25 @@ export class ObjectMetadata {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id: string;
|
||||
|
||||
@Field()
|
||||
@Column({ nullable: false, name: 'data_source_id' })
|
||||
dataSourceId: string;
|
||||
|
||||
// Deprecated
|
||||
@Field()
|
||||
@Column({ nullable: false, name: 'display_name' })
|
||||
displayName: string;
|
||||
@Column({ nullable: false, name: 'name_singular', unique: true })
|
||||
nameSingular: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
@Column({ nullable: true, name: 'display_name_singular' })
|
||||
displayNameSingular: string;
|
||||
@Field()
|
||||
@Column({ nullable: false, name: 'name_plural', unique: true })
|
||||
namePlural: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
@Column({ nullable: true, name: 'display_name_plural' })
|
||||
displayNamePlural: string;
|
||||
@Field()
|
||||
@Column({ nullable: false, name: 'label_singular' })
|
||||
labelSingular: string;
|
||||
|
||||
@Field()
|
||||
@Column({ nullable: false, name: 'label_plural' })
|
||||
labelPlural: string;
|
||||
|
||||
@Field({ nullable: true })
|
||||
@Column({ nullable: true, name: 'description', type: 'text' })
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { ConflictException, Injectable } from '@nestjs/common';
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { Repository } from 'typeorm';
|
||||
@ -22,17 +22,6 @@ export class ObjectMetadataService extends TypeOrmQueryService<ObjectMetadata> {
|
||||
}
|
||||
|
||||
override async createOne(record: ObjectMetadata): Promise<ObjectMetadata> {
|
||||
const objectAlreadyExists = await this.objectMetadataRepository.findOne({
|
||||
where: {
|
||||
displayName: record.displayName, // deprecated, use singular and plural
|
||||
workspaceId: record.workspaceId,
|
||||
},
|
||||
});
|
||||
|
||||
if (objectAlreadyExists) {
|
||||
throw new ConflictException('Object already exists');
|
||||
}
|
||||
|
||||
const createdObjectMetadata = await super.createOne(record);
|
||||
|
||||
await this.tenantMigrationService.createMigration(
|
||||
|
||||
Reference in New Issue
Block a user