Files
dlearn-api/src/DTO/faqCategory.dto.ts
T
2024-10-10 16:58:55 +03:30

82 lines
1.9 KiB
TypeScript

import { ApiProperty } from '@nestjs/swagger';
import { IsEnum, IsMongoId, IsNotEmpty, IsOptional } from 'class-validator';
import { FaqDto, faqObj } from './faq.dto';
import { ItemStatus } from '../common/eNums/itemStatus.enum';
// OBJ *******************
export function faqCategoryObj(faqCategory) {
let Faqs = [];
if (faqCategory.Faqs && faqCategory.Faqs.length !== 0) {
Faqs = faqCategory.Faqs.map((faq) => faqObj(faq));
}
return {
id: faqCategory.id,
title: faqCategory.title,
status: faqCategory.status,
description: faqCategory.description,
Faqs,
};
}
// CLASS *******************
export class FaqCategoryDto {
@IsNotEmpty()
@ApiProperty({ type: String })
@IsMongoId({ message: 'آیدی نامعتبر است.' })
id: string;
@IsNotEmpty()
@ApiProperty({ type: String })
status: string;
@IsNotEmpty()
@ApiProperty({ type: String })
title: string;
@ApiProperty({ type: String })
description: string;
@ApiProperty({ isArray: true, type: FaqDto })
Faqs: FaqDto[];
}
export class CreateFaqCategoryDto {
@IsNotEmpty()
@ApiProperty({ type: String })
title: string;
@ApiProperty({ type: String })
description: string;
}
export class UpdateFaqCategoryDto {
@IsNotEmpty()
@ApiProperty({ type: String })
@IsMongoId({ message: 'آیدی نامعتبر است.' })
id: string;
@IsOptional()
@IsEnum(ItemStatus)
@ApiProperty({ type: String, required: false })
status: string;
@IsNotEmpty()
@ApiProperty({ type: String })
title: string;
@ApiProperty({ type: String })
description: string;
}
export class FilterFaqCategoryDto {
@IsOptional()
@ApiProperty({ type: String, required: false })
@IsMongoId({ message: 'آیدی نامعتبر است.' })
id: string;
@IsOptional()
@IsEnum(ItemStatus)
@ApiProperty({ type: String, required: false })
status: string;
}