Feature: add createCustomField resolver (#1698)

* Feature: add createCustomField resolver

* update mocks

* fix import

* invalidate workspace datasource cache after migration

* fix typo
This commit is contained in:
Weiko
2023-09-21 21:59:11 +02:00
committed by GitHub
parent a59f5acd5e
commit 189bf4a627
17 changed files with 456 additions and 63 deletions

View File

@ -4,6 +4,7 @@ import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { FieldMetadata } from './field-metadata.entity';
import { generateColumnName } from './field-metadata.util';
@Injectable()
export class FieldMetadataService {
@ -11,4 +12,29 @@ export class FieldMetadataService {
@InjectRepository(FieldMetadata, 'metadata')
private readonly fieldMetadataRepository: Repository<FieldMetadata>,
) {}
public async createFieldMetadata(
name: string,
type: string,
objectId: string,
workspaceId: string,
): Promise<FieldMetadata> {
return await this.fieldMetadataRepository.save({
displayName: name,
type,
objectId,
isCustom: true,
targetColumnName: generateColumnName(name),
workspaceId,
});
}
public async getFieldMetadataByNameAndObjectId(
name: string,
objectId: string,
): Promise<FieldMetadata | null> {
return await this.fieldMetadataRepository.findOne({
where: { displayName: name, objectId },
});
}
}

View File

@ -0,0 +1,9 @@
/**
* Generate a column name from a field name removing unsupported characters.
*
* @param name string
* @returns string
*/
export function generateColumnName(name: string): string {
return name.toLowerCase().replace(/ /g, '_');
}