From 4ea6a1b1b4794eedcdec7ffb1fca2c48410c8d46 Mon Sep 17 00:00:00 2001 From: Suman991 Date: Fri, 10 Apr 2026 14:46:13 +0530 Subject: [PATCH] fixed type conversion for deletedAt --- src/form/dto/query-form.dto.ts | 27 +++++++++--- src/form/helpers/form-query.builder.ts | 4 +- src/form/types/field.type.ts | 58 +++++++++----------------- 3 files changed, 43 insertions(+), 46 deletions(-) diff --git a/src/form/dto/query-form.dto.ts b/src/form/dto/query-form.dto.ts index 05145fa..7b3deda 100644 --- a/src/form/dto/query-form.dto.ts +++ b/src/form/dto/query-form.dto.ts @@ -1,6 +1,15 @@ import { ApiPropertyOptional } from '@nestjs/swagger'; -import { Type } from 'class-transformer'; -import { IsBoolean, IsEnum, IsInt, IsOptional, IsString, Max, MaxLength, Min } from 'class-validator'; +import { Transform, Type } from 'class-transformer'; +import { + IsBoolean, + IsEnum, + IsInt, + IsOptional, + IsString, + Max, + MaxLength, + Min, +} from 'class-validator'; export enum SortOrder { ASC = 'asc', @@ -36,11 +45,19 @@ export class QueryFormDto { @MaxLength(100) search?: string; - @ApiPropertyOptional({ example: false, description: 'true = deleted only, false = active only, omit = all' }) - @Type(() => Boolean) + @ApiPropertyOptional({ + example: false, + description: 'true = deleted only, false = active only, omit = all', + }) + // @Type(() => Boolean) + @Transform(({ value }) => { + if (value === 'true' || value === true) return true; + if (value === 'false' || value === false) return false; + return undefined; + }) @IsBoolean() @IsOptional() - isDeleted?: boolean; + isDeleted?: boolean; @ApiPropertyOptional({ enum: SortBy, example: SortBy.CREATED_AT }) @IsEnum(SortBy) diff --git a/src/form/helpers/form-query.builder.ts b/src/form/helpers/form-query.builder.ts index ff395de..47036a8 100644 --- a/src/form/helpers/form-query.builder.ts +++ b/src/form/helpers/form-query.builder.ts @@ -16,9 +16,9 @@ export class FormQueryBuilder { // soft delete search if (query.isDeleted === true) { - filter.deletedAt = { $ne: null }; + filter.deletedAt = { $ne: null }; } else if (query.isDeleted === false) { - filter.deletedAt = null; + filter.deletedAt = null; } return filter; diff --git a/src/form/types/field.type.ts b/src/form/types/field.type.ts index 6fdcfdb..2df5c87 100644 --- a/src/form/types/field.type.ts +++ b/src/form/types/field.type.ts @@ -1,31 +1,9 @@ -// ─── Field Type Definitions ─── - -export interface FormField { - id: string; - keyType: string; - keySubType?: string; - keyName: string; - label: string; - placeholder: string; - options?: string[]; - required?: boolean; -} - -export interface FormData { - id: string; - name: string; - fields: FormField[]; - createdAt: string; - generatedCode?: string; -} - // ─── Parent types ─── export type ParentKeyType = "input" | "textarea" | "select" | "multiselect" | "checkbox"; // ─── Child types (only for "input") ─── -export type InputSubType = "text" | "email" | "number" | "password"; +export type InputSubType = "text" | "email" | "number" | "password" | "button" | "color" | "date" | "datetime-local" | "file" | "hidden" | "image" | "month" | "radio" | "range" | "reset" | "search" | "submit" | "tel" | "time" | "url" | "week" ; -// ─── Constant lookup tables ─── export const PARENT_TYPE_LABELS: Readonly> = { input: "Input", @@ -37,26 +15,28 @@ export const PARENT_TYPE_LABELS: Readonly> = { export const INPUT_SUB_TYPE_LABELS: Readonly> = { text: "Text", - number: "Number", email: "Email", + number: "Number", password: "Password", + button: "Button", + color: "Color Picker", + date: "Date", + "datetime-local" : "Date & Time", + file: "File Upload", + hidden: "Hidden", + image: "Image Button", + month: "Month", + radio: "Radio", + range: "Range Slider", + reset: "Reset Button", + search: "Search", + submit: "Submit Button", + tel: "Telephone", + time: "Time", + url: "URL", + week: "Week", } as const; export const PARENT_TYPE_KEYS = Object.keys(PARENT_TYPE_LABELS) as ParentKeyType[]; export const INPUT_SUB_TYPE_KEYS = Object.keys(INPUT_SUB_TYPE_LABELS) as InputSubType[]; -// Types that need an options list -export const NEEDS_OPTIONS: readonly ParentKeyType[] = ["select", "multiselect", "checkbox"] as const; - -// ─── Derived helpers ─── - -export function getFieldTypeLabel(field: FormField): string { - const parentLabel = PARENT_TYPE_LABELS[field.keyType as ParentKeyType] ?? field.keyType; - - if (field.keyType === "input" && field.keySubType) { - const subLabel = INPUT_SUB_TYPE_LABELS[field.keySubType as InputSubType] ?? field.keySubType; - return `${parentLabel} › ${subLabel}`; - } - - return parentLabel; -}