update: add thumbnail url to the template entity

This commit is contained in:
mahyargdz
2025-07-16 09:19:15 +03:30
parent c427a8fff2
commit 2e898050ec
4 changed files with 20 additions and 12 deletions
+2
View File
@@ -479,4 +479,6 @@ export const enum TemplateMessage {
TEMPLATE_BUSINESS_NOT_FOUND = "کسب و کار مالک قالب یافت نشد", TEMPLATE_BUSINESS_NOT_FOUND = "کسب و کار مالک قالب یافت نشد",
SEARCH_STRING = "نام برای جستجو باید یک رشته باشد", SEARCH_STRING = "نام برای جستجو باید یک رشته باشد",
TEMPLATE_SELECTED_SUCCESSFULLY = "وضعیت قالب با موفقیت تغییر کرد", TEMPLATE_SELECTED_SUCCESSFULLY = "وضعیت قالب با موفقیت تغییر کرد",
TEMPLATE_THUMBNAIL_URL_VALID = "آدرس تصویر قالب باید یک آدرس معتبر باشد",
TEMPLATE_RAW_HTML_REQUIRED = "HTML خام قالب الزامی است",
} }
@@ -1,5 +1,5 @@
import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger"; import { ApiProperty, ApiPropertyOptional } from "@nestjs/swagger";
import { IsNotEmpty, IsOptional, IsString, MaxLength } from "class-validator"; import { IsNotEmpty, IsOptional, IsString, IsUrl, MaxLength } from "class-validator";
import { TemplateMessage } from "../../../common/enums/message.enum"; import { TemplateMessage } from "../../../common/enums/message.enum";
// import { PersonalityDataType } from "../interfaces/structure.interface"; // import { PersonalityDataType } from "../interfaces/structure.interface";
@@ -33,13 +33,15 @@ export class CreateTemplateDto {
}) })
structure: Record<string, unknown>; structure: Record<string, unknown>;
@IsOptional() @IsNotEmpty({ message: TemplateMessage.TEMPLATE_RAW_HTML_REQUIRED })
@IsString({ message: TemplateMessage.TEMPLATE_RAW_HTML_STRING }) @IsString({ message: TemplateMessage.TEMPLATE_RAW_HTML_STRING })
@ApiPropertyOptional({ @ApiProperty({ description: "Raw HTML content of the template", example: "<html><body><h1>Template Content</h1></body></html>" })
description: "Raw HTML content of the template (optional)", rawHtml: string;
example: "<html><body><h1>Template Content</h1></body></html>",
}) @IsOptional()
rawHtml?: string; @IsUrl({ protocols: ["http", "https"] }, { message: TemplateMessage.TEMPLATE_THUMBNAIL_URL_VALID })
@ApiPropertyOptional({ description: "Thumbnail URL of the template (optional)", example: "https://example.com/thumbnail.png" })
thumbnailUrl?: string;
// @IsNotEmpty({ message: "شناسه کسب و کار الزامی است" }) // @IsNotEmpty({ message: "شناسه کسب و کار الزامی است" })
// @IsUUID("7", { message: "شناسه کسب و کار باید یک UUID معتبر باشد" }) // @IsUUID("7", { message: "شناسه کسب و کار باید یک UUID معتبر باشد" })
@@ -10,20 +10,23 @@ import { TemplateRepository } from "../repositories/template.repository";
@Entity({ repository: () => TemplateRepository }) @Entity({ repository: () => TemplateRepository })
export class Template extends BaseEntity { export class Template extends BaseEntity {
@Property({ type: "varchar", length: 255, nullable: false }) @Property({ type: "varchar", length: 255, nullable: false })
name: string; name!: string;
@Property({ type: "jsonb" }) @Property({ type: "jsonb" })
structure: unknown; structure!: unknown;
@Property({ type: "text", nullable: true }) @Property({ type: "text", nullable: false })
rawHtml?: string; rawHtml!: string;
@Property({ type: "uuid", onCreate: () => uuidv7() }) @Property({ type: "uuid", onCreate: () => uuidv7() })
currentVersion: string; currentVersion!: string;
@Property({ type: "boolean", default: false }) @Property({ type: "boolean", default: false })
selected: boolean & Opt; selected: boolean & Opt;
@Property({ type: "varchar", length: 255, nullable: true })
thumbnailUrl?: string;
//-------------------------------------------------- //--------------------------------------------------
@OneToMany(() => User, (user) => user.template) @OneToMany(() => User, (user) => user.template)
@@ -29,6 +29,7 @@ export class TemplatesService {
name: createTemplateDto.name, name: createTemplateDto.name,
structure: createTemplateDto.structure, structure: createTemplateDto.structure,
rawHtml: createTemplateDto.rawHtml, rawHtml: createTemplateDto.rawHtml,
thumbnailUrl: createTemplateDto.thumbnailUrl,
currentVersion: uuidv7(), currentVersion: uuidv7(),
business, business,
}); });