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