fixed type conversion for deletedAt
This commit is contained in:
parent
c4aeaa2c45
commit
4ea6a1b1b4
@ -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,8 +45,16 @@ 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;
|
||||
|
||||
@ -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<Record<ParentKeyType, string>> = {
|
||||
input: "Input",
|
||||
@ -37,26 +15,28 @@ export const PARENT_TYPE_LABELS: Readonly<Record<ParentKeyType, string>> = {
|
||||
|
||||
export const INPUT_SUB_TYPE_LABELS: Readonly<Record<InputSubType, string>> = {
|
||||
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;
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user