mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: address review
This commit is contained in:
parent
de13301a54
commit
ca633b52fb
@ -13,7 +13,7 @@ import { AttachmentRepository } from '@/attachment/repositories/attachment.repos
|
||||
import { AttachmentModel } from '@/attachment/schemas/attachment.schema';
|
||||
import { AttachmentService } from '@/attachment/services/attachment.service';
|
||||
import { BlockService } from '@/chat/services/block.service';
|
||||
import { ContentTypeType } from '@/setting/schemas/types';
|
||||
import { FieldType } from '@/setting/schemas/types';
|
||||
import { NOT_FOUND_ID } from '@/utils/constants/mock';
|
||||
import { getUpdateOneError } from '@/utils/test/errors/messages';
|
||||
import { installContentFixtures } from '@/utils/test/fixtures/content';
|
||||
@ -101,27 +101,27 @@ describe('ContentTypeController', () => {
|
||||
{
|
||||
name: 'address',
|
||||
label: 'Address',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
label: 'Image',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
label: 'Description',
|
||||
type: ContentTypeType.html,
|
||||
type: FieldType.html,
|
||||
},
|
||||
{
|
||||
name: 'rooms',
|
||||
label: 'Rooms',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
{
|
||||
name: 'price',
|
||||
label: 'Price',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@ -19,12 +19,12 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
|
||||
import { ContentTypeType } from '@/setting/schemas/types';
|
||||
import { FieldType } from '@/setting/schemas/types';
|
||||
import { DtoConfig } from '@/utils/types/dto.types';
|
||||
|
||||
import { ValidateRequiredFields } from '../validators/validate-required-fields.validator';
|
||||
|
||||
export class FieldType {
|
||||
export class ContentField {
|
||||
@IsString()
|
||||
@IsNotEmpty()
|
||||
@Matches(/^[a-z][a-z_0-9]*$/)
|
||||
@ -35,11 +35,11 @@ export class FieldType {
|
||||
label: string;
|
||||
|
||||
@IsString()
|
||||
@IsEnum(ContentTypeType, {
|
||||
@IsEnum(FieldType, {
|
||||
message:
|
||||
"type must be one of the following values: 'text', 'url', 'textarea', 'checkbox', 'file', 'html'",
|
||||
})
|
||||
type: ContentTypeType;
|
||||
type: FieldType;
|
||||
}
|
||||
|
||||
export class ContentTypeCreateDto {
|
||||
@ -48,13 +48,16 @@ export class ContentTypeCreateDto {
|
||||
@IsNotEmpty()
|
||||
name: string;
|
||||
|
||||
@ApiPropertyOptional({ description: 'Content type fields', type: FieldType })
|
||||
@ApiPropertyOptional({
|
||||
description: 'Content type fields',
|
||||
type: ContentField,
|
||||
})
|
||||
@IsOptional()
|
||||
@IsArray()
|
||||
@ValidateNested({ each: true })
|
||||
@Validate(ValidateRequiredFields)
|
||||
@Type(() => FieldType)
|
||||
fields?: FieldType[];
|
||||
@Type(() => ContentField)
|
||||
fields?: ContentField[];
|
||||
}
|
||||
|
||||
export class ContentTypeUpdateDto extends PartialType(ContentTypeCreateDto) {}
|
||||
|
||||
@ -12,7 +12,7 @@ import mongoose from 'mongoose';
|
||||
import { BaseSchema } from '@/utils/generics/base-schema';
|
||||
import { LifecycleHookManager } from '@/utils/generics/lifecycle-hook-manager';
|
||||
|
||||
import { FieldType } from '../dto/contentType.dto';
|
||||
import { ContentField } from '../dto/contentType.dto';
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class ContentType extends BaseSchema {
|
||||
@ -41,7 +41,7 @@ export class ContentType extends BaseSchema {
|
||||
},
|
||||
],
|
||||
})
|
||||
fields: FieldType[];
|
||||
fields: ContentField[];
|
||||
}
|
||||
|
||||
export const ContentTypeModel: ModelDefinition = LifecycleHookManager.attach({
|
||||
|
||||
@ -12,26 +12,26 @@ import {
|
||||
ValidatorConstraintInterface,
|
||||
} from 'class-validator';
|
||||
|
||||
import { ContentTypeType } from '@/setting/schemas/types';
|
||||
import { FieldType } from '@/setting/schemas/types';
|
||||
|
||||
import { FieldType } from '../dto/contentType.dto';
|
||||
import { ContentField } from '../dto/contentType.dto';
|
||||
|
||||
@ValidatorConstraint({ name: 'validateRequiredFields', async: false })
|
||||
export class ValidateRequiredFields implements ValidatorConstraintInterface {
|
||||
private readonly REQUIRED_FIELDS: FieldType[] = [
|
||||
private readonly REQUIRED_FIELDS: ContentField[] = [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: ContentTypeType.checkbox,
|
||||
type: FieldType.checkbox,
|
||||
},
|
||||
];
|
||||
|
||||
validate(fields: FieldType[]): boolean {
|
||||
validate(fields: ContentField[]): boolean {
|
||||
const errors: string[] = [];
|
||||
|
||||
this.REQUIRED_FIELDS.forEach((requiredField, index) => {
|
||||
|
||||
@ -20,7 +20,7 @@ export enum SettingType {
|
||||
multiple_attachment = 'multiple_attachment',
|
||||
}
|
||||
|
||||
export enum ContentTypeType {
|
||||
export enum FieldType {
|
||||
text = 'text',
|
||||
url = 'url',
|
||||
textarea = 'textarea',
|
||||
|
||||
32
api/src/utils/test/fixtures/contenttype.ts
vendored
32
api/src/utils/test/fixtures/contenttype.ts
vendored
@ -13,7 +13,7 @@ import {
|
||||
ContentType,
|
||||
ContentTypeModel,
|
||||
} from '@/cms/schemas/content-type.schema';
|
||||
import { ContentTypeType } from '@/setting/schemas/types';
|
||||
import { FieldType } from '@/setting/schemas/types';
|
||||
|
||||
import { getFixturesWithDefaultValues } from '../defaultValues';
|
||||
import { FixturesTypeBuilder } from '../types';
|
||||
@ -28,12 +28,12 @@ export const contentTypeDefaultValues: TContentTypeFixtures['defaultValues'] = {
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: ContentTypeType.checkbox,
|
||||
type: FieldType.checkbox,
|
||||
},
|
||||
],
|
||||
};
|
||||
@ -45,27 +45,27 @@ const contentTypes: TContentTypeFixtures['values'][] = [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: ContentTypeType.checkbox,
|
||||
type: FieldType.checkbox,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
label: 'Description',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
label: 'Image',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
{
|
||||
name: 'subtitle',
|
||||
label: 'Image',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -75,22 +75,22 @@ const contentTypes: TContentTypeFixtures['values'][] = [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: ContentTypeType.checkbox,
|
||||
type: FieldType.checkbox,
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
label: 'Address',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
label: 'Image',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
],
|
||||
},
|
||||
@ -100,22 +100,22 @@ const contentTypes: TContentTypeFixtures['values'][] = [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: ContentTypeType.checkbox,
|
||||
type: FieldType.checkbox,
|
||||
},
|
||||
{
|
||||
name: 'address',
|
||||
label: 'Address',
|
||||
type: ContentTypeType.text,
|
||||
type: FieldType.text,
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
label: 'Image',
|
||||
type: ContentTypeType.file,
|
||||
type: FieldType.file,
|
||||
},
|
||||
],
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user