Refactored and improved seeds (#8695)
- Added a new Seeder service to help with custom object seeds - Added RichTextFieldInput to edit a rich text field directly on the table, but deactivated it for now.
This commit is contained in:
@ -1,7 +1,19 @@
|
||||
import { IsString, IsNumber, IsOptional, IsNotEmpty } from 'class-validator';
|
||||
import { IsNotEmpty, IsNumber, IsOptional, IsString } from 'class-validator';
|
||||
|
||||
import { IsValidGraphQLEnumName } from 'src/engine/metadata-modules/field-metadata/validators/is-valid-graphql-enum-name.validator';
|
||||
|
||||
export type TagColor =
|
||||
| 'green'
|
||||
| 'turquoise'
|
||||
| 'sky'
|
||||
| 'blue'
|
||||
| 'purple'
|
||||
| 'pink'
|
||||
| 'red'
|
||||
| 'orange'
|
||||
| 'yellow'
|
||||
| 'gray';
|
||||
|
||||
export class FieldMetadataDefaultOption {
|
||||
@IsOptional()
|
||||
@IsString()
|
||||
@ -22,5 +34,5 @@ export class FieldMetadataDefaultOption {
|
||||
export class FieldMetadataComplexOption extends FieldMetadataDefaultOption {
|
||||
@IsNotEmpty()
|
||||
@IsString()
|
||||
color: string;
|
||||
color: TagColor;
|
||||
}
|
||||
|
||||
@ -752,7 +752,7 @@ export class FieldMetadataService extends TypeOrmQueryService<FieldMetadataEntit
|
||||
);
|
||||
} else if (error instanceof NameNotAvailableException) {
|
||||
throw new FieldMetadataException(
|
||||
`Name "${fieldMetadataInput.name}" is not available`,
|
||||
`Name "${fieldMetadataInput.name}" is not available, check that it is not duplicating another field's name.`,
|
||||
FieldMetadataExceptionCode.INVALID_FIELD_INPUT,
|
||||
);
|
||||
} else {
|
||||
|
||||
@ -6,25 +6,27 @@ export enum NumberDataType {
|
||||
BIGINT = 'bigint',
|
||||
}
|
||||
|
||||
type FieldMetadataDefaultSettings = {
|
||||
export type FieldMetadataDefaultSettings = {
|
||||
isForeignKey?: boolean;
|
||||
};
|
||||
|
||||
type FieldMetadataNumberSettings = {
|
||||
export type FieldNumberVariant = 'number' | 'percentage';
|
||||
|
||||
export type FieldMetadataNumberSettings = {
|
||||
dataType: NumberDataType;
|
||||
decimals?: number;
|
||||
type?: string;
|
||||
type?: FieldNumberVariant;
|
||||
};
|
||||
|
||||
type FieldMetadataTextSettings = {
|
||||
export type FieldMetadataTextSettings = {
|
||||
displayedMaxRows?: number;
|
||||
};
|
||||
|
||||
type FieldMetadataDateSettings = {
|
||||
export type FieldMetadataDateSettings = {
|
||||
displayAsRelativeDate?: boolean;
|
||||
};
|
||||
|
||||
type FieldMetadataDateTimeSettings = {
|
||||
export type FieldMetadataDateTimeSettings = {
|
||||
displayAsRelativeDate?: boolean;
|
||||
};
|
||||
|
||||
|
||||
@ -1,20 +1,21 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import {
|
||||
ValidationArguments,
|
||||
ValidatorConstraint,
|
||||
ValidatorConstraintInterface,
|
||||
} from 'class-validator';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { FieldMetadataDefaultValue } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-default-value.interface';
|
||||
|
||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
||||
import { LoggerService } from 'src/engine/core-modules/logger/logger.service';
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
FieldMetadataType,
|
||||
} from 'src/engine/metadata-modules/field-metadata/field-metadata.entity';
|
||||
import { validateDefaultValueForType } from 'src/engine/metadata-modules/field-metadata/utils/validate-default-value-for-type.util';
|
||||
import { LoggerService } from 'src/engine/core-modules/logger/logger.service';
|
||||
|
||||
@Injectable()
|
||||
@ValidatorConstraint({ name: 'isFieldMetadataDefaultValue', async: true })
|
||||
@ -22,7 +23,8 @@ export class IsFieldMetadataDefaultValue
|
||||
implements ValidatorConstraintInterface
|
||||
{
|
||||
constructor(
|
||||
private readonly fieldMetadataService: FieldMetadataService,
|
||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
private readonly loggerService: LoggerService,
|
||||
) {}
|
||||
|
||||
@ -44,7 +46,11 @@ export class IsFieldMetadataDefaultValue
|
||||
let fieldMetadata: FieldMetadataEntity;
|
||||
|
||||
try {
|
||||
fieldMetadata = await this.fieldMetadataService.findOneOrFail(id);
|
||||
fieldMetadata = await this.fieldMetadataRepository.findOneOrFail({
|
||||
where: {
|
||||
id,
|
||||
},
|
||||
});
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -1,10 +1,11 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import { ValidationArguments, ValidatorConstraint } from 'class-validator';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { FieldMetadataOptions } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata-options.interface';
|
||||
|
||||
import { FieldMetadataService } from 'src/engine/metadata-modules/field-metadata/field-metadata.service';
|
||||
import {
|
||||
FieldMetadataEntity,
|
||||
FieldMetadataType,
|
||||
@ -16,7 +17,10 @@ import { validateOptionsForType } from 'src/engine/metadata-modules/field-metada
|
||||
export class IsFieldMetadataOptions {
|
||||
private validationErrors: string[] = [];
|
||||
|
||||
constructor(private readonly fieldMetadataService: FieldMetadataService) {}
|
||||
constructor(
|
||||
@InjectRepository(FieldMetadataEntity, 'metadata')
|
||||
private readonly fieldMetadataRepository: Repository<FieldMetadataEntity>,
|
||||
) {}
|
||||
|
||||
async validate(
|
||||
value: FieldMetadataOptions,
|
||||
@ -36,7 +40,9 @@ export class IsFieldMetadataOptions {
|
||||
let fieldMetadata: FieldMetadataEntity;
|
||||
|
||||
try {
|
||||
fieldMetadata = await this.fieldMetadataService.findOneOrFail(id);
|
||||
fieldMetadata = await this.fieldMetadataRepository.findOneOrFail({
|
||||
where: { id },
|
||||
});
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -3,17 +3,22 @@ import {
|
||||
Injectable,
|
||||
UnauthorizedException,
|
||||
} from '@nestjs/common';
|
||||
import { InjectRepository } from '@nestjs/typeorm';
|
||||
|
||||
import {
|
||||
BeforeDeleteOneHook,
|
||||
DeleteOneInputType,
|
||||
} from '@ptc-org/nestjs-query-graphql';
|
||||
import { Repository } from 'typeorm';
|
||||
|
||||
import { RelationMetadataService } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.service';
|
||||
import { RelationMetadataEntity } from 'src/engine/metadata-modules/relation-metadata/relation-metadata.entity';
|
||||
|
||||
@Injectable()
|
||||
export class BeforeDeleteOneRelation implements BeforeDeleteOneHook {
|
||||
constructor(readonly relationMetadataService: RelationMetadataService) {}
|
||||
constructor(
|
||||
@InjectRepository(RelationMetadataEntity, 'metadata')
|
||||
private readonly relationMetadataRepository: Repository<RelationMetadataEntity>,
|
||||
) {}
|
||||
|
||||
async run(
|
||||
instance: DeleteOneInputType,
|
||||
@ -25,12 +30,13 @@ export class BeforeDeleteOneRelation implements BeforeDeleteOneHook {
|
||||
throw new UnauthorizedException();
|
||||
}
|
||||
|
||||
const relationMetadata =
|
||||
await this.relationMetadataService.findOneWithinWorkspace(workspaceId, {
|
||||
where: {
|
||||
id: instance.id.toString(),
|
||||
},
|
||||
});
|
||||
const relationMetadata = await this.relationMetadataRepository.findOne({
|
||||
where: {
|
||||
workspaceId,
|
||||
id: instance.id.toString(),
|
||||
},
|
||||
relations: ['fromFieldMetafata', 'toFieldMetadata'],
|
||||
});
|
||||
|
||||
if (!relationMetadata) {
|
||||
throw new BadRequestException('Relation does not exist');
|
||||
|
||||
Reference in New Issue
Block a user