Files
Khafid Prayoga e967ee1cf0 refactor(role): rename PagePermission to RoleAccesses and fix base model id
Update type name from PagePermission to RoleAccesses across multiple files for consistency
Change mock id value from -1 to 0 in base model to match backend constraints
Enable RBAC middleware and fix patient edit page permissions
2025-12-08 18:57:35 +07:00

49 lines
1.3 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 {
id: 0,
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>
}