import { Type } from 'class-transformer'; import { Allow, IsArray, IsBoolean, IsDateString, IsIn, IsInt, IsOptional, IsString, Max, MaxLength, Min, MinLength, ValidateIf, } from 'class-validator'; /** تکه‌های JSON از ایمپورت مرورگرگرا */ export class ImportActivityRowsDto { @IsArray() @Allow() rows!: Array>; @Type(() => Number) @IsInt() @Min(0) offset!: number; @Type(() => Number) @IsInt() @Min(0) total!: number; @IsOptional() @IsString() sessionId?: string; } const ACTIVITY_TYPES = ['call', 'meeting', 'task', 'note'] as const; const ACTIVITY_STATUSES = ['open', 'done', 'canceled'] as const; const ACTIVITY_PRIORITIES = ['very_low', 'low', 'medium', 'high', 'very_high'] as const; const ACTIVITY_FILTERS = ['today', 'overdue', 'upcoming', 'done', 'all'] as const; export class ListActivitiesQueryDto { @IsOptional() @IsIn(ACTIVITY_FILTERS) filter?: (typeof ACTIVITY_FILTERS)[number] = 'today'; @IsOptional() @IsString() q?: string; @IsOptional() @IsIn(['mine', 'team']) desk?: 'mine' | 'team'; @IsOptional() @IsIn(ACTIVITY_TYPES) type?: (typeof ACTIVITY_TYPES)[number]; @IsOptional() @IsIn(ACTIVITY_STATUSES) status?: (typeof ACTIVITY_STATUSES)[number]; @IsOptional() @IsString() assigneeId?: string; @IsOptional() @IsString() personId?: string; @IsOptional() @IsString() companyId?: string; @IsOptional() @IsString() dealId?: string; /** Inclusive start (ISO). When set with/without filter, restricts dueAt. */ @IsOptional() @IsDateString() from?: string; /** Exclusive end (ISO). */ @IsOptional() @IsDateString() to?: string; @IsOptional() @Type(() => Number) @IsInt() @Min(1) page?: number = 1; @IsOptional() @Type(() => Number) @IsInt() @Min(1) @Max(200) limit?: number = 50; } export class CreateActivityDto { @IsString() @MinLength(2) @MaxLength(200) title!: string; @IsOptional() @IsIn(ACTIVITY_TYPES) type?: (typeof ACTIVITY_TYPES)[number]; @IsOptional() @IsIn(ACTIVITY_PRIORITIES) priority?: (typeof ACTIVITY_PRIORITIES)[number]; @IsOptional() @IsString() @MaxLength(2000) description?: string; @IsOptional() @ValidateIf((_, v) => v !== '' && v != null) @IsDateString() dueAt?: string | null; @IsOptional() @Type(() => Number) @IsInt() @Min(1) @Max(24 * 60) durationMinutes?: number | null; @IsOptional() @ValidateIf((_, v) => v !== '' && v != null) @IsDateString() reminderAt?: string | null; @IsOptional() @IsBoolean() reminderNotifyApp?: boolean; @IsOptional() @IsBoolean() reminderNotifySms?: boolean; @IsOptional() @IsArray() @IsString({ each: true }) tags?: string[]; @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; @IsOptional() @ValidateIf((_, v) => v !== '' && v != null) @IsString() assigneeId?: string | null; @IsOptional() @IsArray() @IsString({ each: true }) assigneeIds?: string[]; } export class UpdateActivityDto { @IsOptional() @IsString() @MinLength(2) @MaxLength(200) title?: string; @IsOptional() @IsIn(ACTIVITY_TYPES) type?: (typeof ACTIVITY_TYPES)[number]; @IsOptional() @IsIn(ACTIVITY_STATUSES) status?: (typeof ACTIVITY_STATUSES)[number]; @IsOptional() @IsIn(ACTIVITY_PRIORITIES) priority?: (typeof ACTIVITY_PRIORITIES)[number]; @IsOptional() @IsString() @MaxLength(2000) description?: string | null; @IsOptional() @ValidateIf((_, v) => v !== '' && v != null) @IsDateString() dueAt?: string | null; @IsOptional() @Type(() => Number) @IsInt() @Min(1) @Max(24 * 60) durationMinutes?: number | null; @IsOptional() @ValidateIf((_, v) => v !== '' && v != null) @IsDateString() reminderAt?: string | null; @IsOptional() @IsBoolean() reminderNotifyApp?: boolean; @IsOptional() @IsBoolean() reminderNotifySms?: boolean; @IsOptional() @IsArray() @IsString({ each: true }) tags?: string[]; @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; @IsOptional() @ValidateIf((_, v) => v !== '' && v != null) @IsString() assigneeId?: string | null; @IsOptional() @IsArray() @IsString({ each: true }) assigneeIds?: string[]; }