Files
crm/apps/api/src/notes/dto.ts
T

222 lines
3.6 KiB
TypeScript

import { Type } from 'class-transformer';
import {
IsArray,
IsBoolean,
IsDateString,
IsIn,
IsInt,
IsOptional,
IsString,
Max,
MaxLength,
Min,
MinLength,
ValidateIf,
} from 'class-validator';
const NOTE_TYPES = [
'general',
'call_result',
'meeting',
'important',
'warning',
'next_action',
] as const;
export class ListNotesQueryDto {
@IsOptional()
@IsString()
q?: string;
@IsOptional()
@Type(() => Boolean)
@IsBoolean()
pinned?: boolean;
@IsOptional()
@IsString()
personId?: string;
@IsOptional()
@IsString()
companyId?: string;
@IsOptional()
@IsString()
dealId?: string;
@IsOptional()
@IsString()
tag?: string;
@IsOptional()
@IsIn(NOTE_TYPES)
noteType?: (typeof NOTE_TYPES)[number];
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
page?: number = 1;
@IsOptional()
@Type(() => Number)
@IsInt()
@Min(1)
@Max(100)
limit?: number = 50;
}
export class CreateNoteDto {
@IsOptional()
@IsString()
@MaxLength(200)
title?: string;
@IsString()
@MinLength(1)
@MaxLength(8000)
body!: string;
@IsOptional()
@IsIn(NOTE_TYPES)
noteType?: (typeof NOTE_TYPES)[number];
@IsOptional()
@IsBoolean()
pinned?: boolean;
@IsOptional()
@IsString()
@MaxLength(32)
color?: string;
@IsOptional()
@IsArray()
@IsString({ each: true })
tags?: string[];
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsDateString()
reminderAt?: string | null;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
personId?: string | null;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
companyId?: string | null;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
dealId?: string | null;
}
export class UpdateNoteDto {
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
@MaxLength(200)
title?: string | null;
@IsOptional()
@IsString()
@MinLength(1)
@MaxLength(8000)
body?: string;
@IsOptional()
@IsIn(NOTE_TYPES)
noteType?: (typeof NOTE_TYPES)[number];
@IsOptional()
@IsBoolean()
pinned?: boolean;
@IsOptional()
@IsString()
@MaxLength(32)
color?: string | null;
@IsOptional()
@IsArray()
@IsString({ each: true })
tags?: string[];
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsDateString()
reminderAt?: string | null;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
personId?: string | null;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
companyId?: string | null;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsString()
dealId?: string | null;
}
class NoteAiNextActionDtoClass {
@IsString()
@MinLength(1)
@MaxLength(200)
title!: string;
@IsOptional()
@IsString()
@MaxLength(2000)
description?: string;
@IsOptional()
@ValidateIf((_, v) => v !== '' && v != null)
@IsDateString()
dueAt?: string | null;
}
class ApplyMemoryEditDto {
@Type(() => Number)
@IsInt()
@Min(0)
index!: number;
@IsString()
@MinLength(2)
@MaxLength(500)
content!: string;
}
export class ApplyNoteAiSuggestionDto {
@IsOptional()
@IsBoolean()
applyNextAction?: boolean;
@IsOptional()
@IsArray()
@Type(() => Number)
@IsInt({ each: true })
@Min(0, { each: true })
memoryIndices?: number[];
@IsOptional()
@Type(() => NoteAiNextActionDtoClass)
nextAction?: NoteAiNextActionDtoClass;
@IsOptional()
@IsArray()
@Type(() => ApplyMemoryEditDto)
memoryItems?: ApplyMemoryEditDto[];
}