feat(division): create tree item converter for division
This commit is contained in:
No files matched your search
@@ -50,6 +50,7 @@ const {
|
|||||||
const result = await getDivisions({
|
const result = await getDivisions({
|
||||||
search: params.search,
|
search: params.search,
|
||||||
// page: params['page-number'] || 0,
|
// page: params['page-number'] || 0,
|
||||||
|
includes: 'parent,childrens',
|
||||||
})
|
})
|
||||||
return { success: result.success || false, body: result.body || {} }
|
return { success: result.success || false, body: result.body || {} }
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import type { Installation } from '~/models/installation'
|
|||||||
import type { Specialist } from '~/models/specialist'
|
import type { Specialist } from '~/models/specialist'
|
||||||
import type { Uom } from '~/models/uom'
|
import type { Uom } from '~/models/uom'
|
||||||
import type { Unit } from '~/models/unit'
|
import type { Unit } from '~/models/unit'
|
||||||
|
import type { TreeItem } from '~/models/_model'
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
import { encounterClassCodes } from '~/lib/constants'
|
import { encounterClassCodes } from '~/lib/constants'
|
||||||
@@ -124,3 +125,20 @@ export const getUomList = async () => {
|
|||||||
uoms.value = currentUoms.map((uom: Uom) => ({ value: uom.code || uom.erp_id, label: uom.name }))
|
uoms.value = currentUoms.map((uom: Uom) => ({ value: uom.code || uom.erp_id, label: uom.name }))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert division response (with childrens) to TreeItem[]
|
||||||
|
* @param divisions Array of division objects from API
|
||||||
|
* @returns TreeItem[]
|
||||||
|
*/
|
||||||
|
export function convertDivisionToTreeItems(divisions: any[]): TreeItem[] {
|
||||||
|
return divisions.map((division) => ({
|
||||||
|
value: division.id ? String(division.id) : division.code,
|
||||||
|
label: division.name,
|
||||||
|
hasChildren: Array.isArray(division.childrens) && division.childrens.length > 0,
|
||||||
|
children:
|
||||||
|
Array.isArray(division.childrens) && division.childrens.length > 0
|
||||||
|
? convertDivisionToTreeItems(division.childrens)
|
||||||
|
: undefined,
|
||||||
|
}))
|
||||||
|
}
|
||||||
@@ -14,6 +14,13 @@ export interface PaginationMeta {
|
|||||||
source: string
|
source: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface TreeItem {
|
||||||
|
value: string
|
||||||
|
label: string
|
||||||
|
hasChildren: boolean
|
||||||
|
children?: TreeItem[]
|
||||||
|
}
|
||||||
|
|
||||||
export interface Base {
|
export interface Base {
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
|
|||||||
Reference in New Issue
Block a user