Clean seller metadata display names
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 40s

This commit is contained in:
Cauê Faleiros
2026-06-24 13:03:55 -03:00
parent b129307bae
commit ca9615a1fd
5 changed files with 57 additions and 13 deletions

View File

@@ -42,6 +42,7 @@ const CUSTOMER_IDENTITY_CTE = `
)
`;
const CUSTOMER_KEY_SQL = 'customer_key';
const TRAILING_SELLER_ID_SQL_PATTERN = '[[:space:]]*#([0-9]+)[[:space:]]*$';
const getClientTokenSecret = () => (
process.env.CLIENT_TOKEN_SECRET ||
@@ -196,6 +197,19 @@ const normalizeSellerFilter = (value) => {
return { type: 'any', value: normalizedValue };
};
const normalizeSellerOption = (row) => {
const rawId = String(row.id || '').trim();
const rawName = String(row.name || '').trim();
const idFromName = rawName.match(/#(\d+)\s*$/)?.[1] || '';
const id = rawId || idFromName;
const name = rawName.replace(/#\d+\s*$/, '').trim();
return {
id,
name: name || id
};
};
const appendOrderMetadataFilters = (params, filters, range = {}) => {
const marketplace = normalizeTextFilter(range.marketplace);
const salesChannel = normalizeTextFilter(range.canal_venda || range.canalVenda);
@@ -703,8 +717,11 @@ const getClientFilterOptions = async () => {
pool.query(`
WITH seller_options AS (
SELECT
NULLIF(TRIM(id_vendedor), '') as id,
NULLIF(TRIM(nome_vendedor), '') as name
COALESCE(
NULLIF(TRIM(id_vendedor), ''),
substring(NULLIF(TRIM(nome_vendedor), '') from '${TRAILING_SELLER_ID_SQL_PATTERN}')
) as id,
NULLIF(TRIM(regexp_replace(COALESCE(nome_vendedor, ''), '${TRAILING_SELLER_ID_SQL_PATTERN}', '')), '') as name
FROM orders
WHERE (
NULLIF(TRIM(id_vendedor), '') IS NOT NULL
@@ -720,8 +737,7 @@ const getClientFilterOptions = async () => {
const sellerOptionsByValue = new Map();
sellerResult.rows.forEach(row => {
const id = row.id || '';
const name = row.name || '';
const { id, name } = normalizeSellerOption(row);
const value = id ? `id:${id}` : `name:${name}`;
if (!value || sellerOptionsByValue.has(value)) return;