fix: define a type for fields in ContentType schema

This commit is contained in:
hexastack
2025-04-04 15:46:51 +01:00
parent 78df48c398
commit c174ddc708
6 changed files with 51 additions and 33 deletions

View File

@@ -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,
},
],
};

View 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 {

View 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.
@@ -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({

View 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.
@@ -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,
},
];

View 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.
@@ -20,6 +20,15 @@ export enum SettingType {
multiple_attachment = 'multiple_attachment',
}
export enum ContentTypeType {
text = 'text',
url = 'url',
textarea = 'textarea',
checkbox = 'checkbox',
file = 'file',
html = 'html',
}
/**
* The following interfaces are declared, and currently not used
* TextSetting
@@ -128,3 +137,9 @@ export type AnySetting =
| MultipleAttachmentSetting;
export type SettingDict = { [group: string]: Setting[] };
export type Field = {
name: string;
label: string;
type: ContentTypeType;
};

View File

@@ -13,6 +13,7 @@ import {
ContentType,
ContentTypeModel,
} from '@/cms/schemas/content-type.schema';
import { ContentTypeType } from '@/setting/schemas/types';
import { getFixturesWithDefaultValues } from '../defaultValues';
import { FixturesTypeBuilder } from '../types';
@@ -27,12 +28,12 @@ export const contentTypeDefaultValues: TContentTypeFixtures['defaultValues'] = {
{
name: 'title',
label: 'Title',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'status',
label: 'Status',
type: 'checkbox',
type: ContentTypeType.checkbox,
},
],
};
@@ -44,27 +45,27 @@ const contentTypes: TContentTypeFixtures['values'][] = [
{
name: 'title',
label: 'Title',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'status',
label: 'Status',
type: 'checkbox',
type: ContentTypeType.checkbox,
},
{
name: 'description',
label: 'Description',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'image',
label: 'Image',
type: 'file',
type: ContentTypeType.file,
},
{
name: 'subtitle',
label: 'Image',
type: 'file',
type: ContentTypeType.file,
},
],
},
@@ -74,22 +75,22 @@ const contentTypes: TContentTypeFixtures['values'][] = [
{
name: 'title',
label: 'Title',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'status',
label: 'Status',
type: 'checkbox',
type: ContentTypeType.checkbox,
},
{
name: 'address',
label: 'Address',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'image',
label: 'Image',
type: 'file',
type: ContentTypeType.file,
},
],
},
@@ -99,22 +100,22 @@ const contentTypes: TContentTypeFixtures['values'][] = [
{
name: 'title',
label: 'Title',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'status',
label: 'Status',
type: 'checkbox',
type: ContentTypeType.checkbox,
},
{
name: 'address',
label: 'Address',
type: 'text',
type: ContentTypeType.text,
},
{
name: 'image',
label: 'Image',
type: 'file',
type: ContentTypeType.file,
},
],
},