Fix: Refactor Organization CRUD {id} to {code}

This commit is contained in:
hasyim_kai
2025-11-11 14:07:46 +07:00
parent 3f63f195d0
commit 270869b928
52 changed files with 211 additions and 216 deletions
+8 -4
View File
@@ -28,13 +28,15 @@ export function remove(id: number | string) {
return base.remove(path, id, name)
}
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
export async function getValueLabelList(params: any = null, useCodeAsValue = false): Promise<{ value: string; label: string }[]> {
let data: { value: string; label: string }[] = []
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: Division) => ({
value: item.id ? Number(item.id) : item.code,
value: useCodeAsValue ? item.code
: item.id ? Number(item.id)
: item.code,
label: item.name,
}))
}
@@ -46,10 +48,12 @@ export async function getValueLabelList(params: any = null): Promise<{ value: st
* @param divisions Array of division objects from API
* @returns TreeItem[]
*/
export function getValueTreeItems(divisions: any[]): TreeItem[] {
export function getValueTreeItems(divisions: any[], byCode = true): TreeItem[] {
return divisions
.map((division: Division) => ({
value: division.id ? String(division.id) : division.code,
value: byCode ? String(division.code)
: String(division.id) ? String(division.id)
: division.code,
label: division.name,
hasChildren: Array.isArray(division.childrens) && division.childrens.length > 0,
children:
+4 -2
View File
@@ -27,13 +27,15 @@ export function remove(id: number | string) {
return base.remove(path, id, name)
}
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
export async function getValueLabelList(params: any = null, useCodeAsValue = false): Promise<{ value: string; label: string }[]> {
let data: { value: string; label: string }[] = []
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: Installation) => ({
value: item.id ? Number(item.id) : item.code,
value: useCodeAsValue ? item.code
: item.id ? Number(item.id)
: item.code,
label: item.name,
}))
}
+4 -2
View File
@@ -28,13 +28,15 @@ export function remove(id: number | string) {
return base.remove(path, id, name)
}
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
export async function getValueLabelList(params: any = null, useCodeAsValue = false): Promise<{ value: string; label: string }[]> {
let data: { value: string; label: string }[] = []
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: Specialist) => ({
value: item.id ? Number(item.id) : item.code,
value: useCodeAsValue ? item.code
: item.id ? Number(item.id)
: item.code,
label: item.name,
parent: item.unit_id ? Number(item.unit_id) : null,
}))
+4 -2
View File
@@ -27,13 +27,15 @@ export function remove(id: number | string) {
return base.remove(path, id, name)
}
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
export async function getValueLabelList(params: any = null, useCodeAsValue = false): Promise<{ value: string; label: string }[]> {
let data: { value: string; label: string }[] = []
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: Subspecialist) => ({
value: item.id ? Number(item.id) : item.code,
value: useCodeAsValue ? item.code
: item.id ? Number(item.id)
: item.code,
label: item.name,
parent: item.specialist_id ? Number(item.specialist_id) : null,
}))
+4 -2
View File
@@ -27,13 +27,15 @@ export function remove(id: number | string) {
return base.remove(path, id, name)
}
export async function getValueLabelList(params: any = null): Promise<{ value: string; label: string }[]> {
export async function getValueLabelList(params: any = null, useCodeAsValue = false): Promise<{ value: string; label: string }[]> {
let data: { value: string; label: string }[] = []
const result = await getList(params)
if (result.success) {
const resultData = result.body?.data || []
data = resultData.map((item: Unit) => ({
value: item.id,
value: useCodeAsValue ? item.code
: item.id ? Number(item.id)
: item.code,
label: item.name,
}))
}