Files
backend/src/blogs/dto/blog.dto.ts
T
Alireza HassaniandCursor 1b16e79d3f Add tag filter to blogs, portfolios, and videos list APIs.
Storefronts can filter published content by metadata.tags the same way as products; website API docs are updated to match.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-22 21:14:42 +03:30

179 lines
2.6 KiB
TypeScript

import { BlogPostType, ContentStatus } from '@prisma/client';
import { Type } from 'class-transformer';
import {
IsArray,
IsEnum,
IsInt,
IsOptional,
IsString,
Matches,
Min,
MinLength,
} from 'class-validator';
export class ListBlogsDto {
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
page?: number;
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
pageSize?: number;
@IsOptional()
@IsEnum(ContentStatus)
status?: ContentStatus;
@IsOptional()
@IsEnum(BlogPostType)
type?: BlogPostType;
@IsOptional()
@IsString()
categoryId?: string;
@IsOptional()
@IsString()
title?: string;
@IsOptional()
@IsString()
tag?: string;
}
export class ListPublicBlogsDto {
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
page?: number;
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
pageSize?: number;
@IsOptional()
@IsEnum(BlogPostType)
type?: BlogPostType;
@IsOptional()
@IsString()
categoryId?: string;
@IsOptional()
@IsString()
title?: string;
@IsOptional()
@IsString()
tag?: string;
}
export class CreateBlogDto {
@IsString()
@MinLength(2)
title!: string;
@IsEnum(BlogPostType)
type!: BlogPostType;
@IsOptional()
@IsString()
abstract?: string;
@IsOptional()
@IsString()
mainTextHtml?: string;
@IsOptional()
@IsString()
categoryId?: string;
@IsOptional()
@IsEnum(ContentStatus)
status?: ContentStatus;
@IsOptional()
@IsString()
featuredMediaId?: string;
@IsOptional()
@IsArray()
@IsString({ each: true })
tags?: string[];
@IsOptional()
@IsString()
authorId?: string;
@IsOptional()
@IsString()
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
slug?: string;
}
export class UpdateBlogDto {
@IsOptional()
@IsString()
@MinLength(2)
title?: string;
@IsOptional()
@IsEnum(BlogPostType)
type?: BlogPostType;
@IsOptional()
@IsString()
abstract?: string | null;
@IsOptional()
@IsString()
mainTextHtml?: string | null;
@IsOptional()
@IsString()
categoryId?: string | null;
@IsOptional()
@IsEnum(ContentStatus)
status?: ContentStatus;
@IsOptional()
@IsString()
featuredMediaId?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
tags?: string[];
@IsOptional()
@IsString()
authorId?: string | null;
@IsOptional()
@IsString()
@Matches(/^[a-z0-9]+(?:-[a-z0-9]+)*$/)
slug?: string;
}
export class CreateBlogCommentDto {
@IsString()
@MinLength(2)
authorName!: string;
@IsOptional()
@IsString()
authorEmail?: string;
@IsString()
@MinLength(1)
text!: string;
}