mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
fix: define a type for fields in ContentType schema
This commit is contained in:
@@ -13,6 +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 { NOT_FOUND_ID } from '@/utils/constants/mock';
|
||||
import { getUpdateOneError } from '@/utils/test/errors/messages';
|
||||
import { installContentFixtures } from '@/utils/test/fixtures/content';
|
||||
@@ -100,27 +101,27 @@ describe('ContentTypeController', () => {
|
||||
{
|
||||
name: 'address',
|
||||
label: 'Address',
|
||||
type: 'text',
|
||||
type: ContentTypeType.text,
|
||||
},
|
||||
{
|
||||
name: 'image',
|
||||
label: 'Image',
|
||||
type: 'file',
|
||||
type: ContentTypeType.file,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
label: 'Description',
|
||||
type: 'html',
|
||||
type: ContentTypeType.html,
|
||||
},
|
||||
{
|
||||
name: 'rooms',
|
||||
label: 'Rooms',
|
||||
type: 'file',
|
||||
type: ContentTypeType.file,
|
||||
},
|
||||
{
|
||||
name: 'price',
|
||||
label: 'Price',
|
||||
type: 'file',
|
||||
type: ContentTypeType.file,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Hexastack. All rights reserved.
|
||||
* Copyright © 2025 Hexastack. All rights reserved.
|
||||
*
|
||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||
@@ -19,6 +19,7 @@ import {
|
||||
ValidateNested,
|
||||
} from 'class-validator';
|
||||
|
||||
import { ContentTypeType } from '@/setting/schemas/types';
|
||||
import { DtoConfig } from '@/utils/types/dto.types';
|
||||
|
||||
import { ValidateRequiredFields } from '../validators/validate-required-fields.validator';
|
||||
@@ -34,11 +35,11 @@ export class FieldType {
|
||||
label: string;
|
||||
|
||||
@IsString()
|
||||
@IsEnum(['text', 'url', 'textarea', 'checkbox', 'file', 'html'], {
|
||||
@IsEnum(ContentTypeType, {
|
||||
message:
|
||||
"type must be one of the following values: 'text', 'url', 'textarea', 'checkbox', 'file', 'html'",
|
||||
})
|
||||
type: string;
|
||||
type: ContentTypeType;
|
||||
}
|
||||
|
||||
export class ContentTypeCreateDto {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Hexastack. All rights reserved.
|
||||
* Copyright © 2025 Hexastack. All rights reserved.
|
||||
*
|
||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||
@@ -12,6 +12,8 @@ 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';
|
||||
|
||||
@Schema({ timestamps: true })
|
||||
export class ContentType extends BaseSchema {
|
||||
/**
|
||||
@@ -39,11 +41,7 @@ export class ContentType extends BaseSchema {
|
||||
},
|
||||
],
|
||||
})
|
||||
fields: {
|
||||
name: string;
|
||||
label: string;
|
||||
type: string;
|
||||
}[];
|
||||
fields: FieldType[];
|
||||
}
|
||||
|
||||
export const ContentTypeModel: ModelDefinition = LifecycleHookManager.attach({
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright © 2024 Hexastack. All rights reserved.
|
||||
* Copyright © 2025 Hexastack. All rights reserved.
|
||||
*
|
||||
* Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms:
|
||||
* 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission.
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
ValidatorConstraintInterface,
|
||||
} from 'class-validator';
|
||||
|
||||
import { ContentTypeType } from '@/setting/schemas/types';
|
||||
|
||||
import { FieldType } from '../dto/contentType.dto';
|
||||
|
||||
@ValidatorConstraint({ name: 'validateRequiredFields', async: false })
|
||||
@@ -20,12 +22,12 @@ export class ValidateRequiredFields implements ValidatorConstraintInterface {
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: 'text',
|
||||
type: ContentTypeType.text,
|
||||
},
|
||||
{
|
||||
name: 'status',
|
||||
label: 'Status',
|
||||
type: 'checkbox',
|
||||
type: ContentTypeType.checkbox,
|
||||
},
|
||||
];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user