Files
vexplor/backend-node/src/utils/categoryUtils.ts

30 lines
937 B
TypeScript
Raw Normal View History

import type { PoolClient } from "pg";
/**
* value_label category_values value_code .
* label .
*
* company_code label value_code
* , .
*/
export async function resolveCategoryCode(
client: PoolClient,
tableName: string,
columnName: string,
label: string | null | undefined,
): Promise<string | null> {
if (!label) return label ?? null;
const result = await client.query(
`SELECT DISTINCT value_code FROM category_values
WHERE table_name = $1
AND column_name = $2
AND value_label = $3
AND is_active = true
LIMIT 1`,
[tableName, columnName, label],
);
return result.rows[0]?.value_code ?? label;
}