Files
simrsx-fe/app/models/_base.ts
Khafid Prayoga 6a29fdfd50 refactor(glob:form): update form handling and type definitions
- Migrate from Form component to vee-validate useForm
- Update combobox component to support number values
- Modify base model ID type for mock data
- Improve type safety in treatment report schema
- Add proper form submission handling
2025-11-25 20:46:53 +07:00

51 lines
1.5 KiB
TypeScript

export interface Base {
id: number
createdAt: string | null
updatedAt: string | null
deletedAt?: string | null
}
export interface CodeName {
name: string
code: string
}
export interface TreeItem {
value: string
label: string
hasChildren: boolean
children?: TreeItem[]
}
export function genBase(): Base {
return {
// -1 buat mock data
// backend harusnya non-negative/ > 0 (untuk auto increment constraint) jadi harusnya aman ya
id: -1,
createdAt: '',
updatedAt: '',
}
}
export type WithBase<T extends Base> = Omit<T, keyof Base> & Required<Base>
/**
* The function `withBase` sets default values for item properties if not provided.
* @param item - The `withBase` function takes in an optional parameter `item`, which is a
* partial object of type `T`. The function merges the properties of `item` with default values for
* `id`, `createdAt`, `updatedAt`, and `deletedAt`. The function then returns an object of type
* @returns The `withBase` function returns an object with default values for the properties
* `id`, `createdAt`, `updatedAt`, and `deletedAt`, along with any additional properties provided in
* the `item` parameter. The returned object has a type `WithBase<T>`, which extends `T` and
* includes the default properties.
*/
export function withBase<T extends Base>(item: Partial<T> = {}): WithBase<T> {
return {
id: 0,
createdAt: null,
updatedAt: null,
deletedAt: null,
...item,
} as WithBase<T>
}