Show all client metadata filter options
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 44s
All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 44s
This commit is contained in:
@@ -684,40 +684,32 @@ const getClientAnalytics = async (range = {}) => {
|
|||||||
return clients;
|
return clients;
|
||||||
};
|
};
|
||||||
|
|
||||||
const getClientFilterOptions = async (range = {}) => {
|
const getClientFilterOptions = async () => {
|
||||||
const dateRange = {
|
|
||||||
start: range.start,
|
|
||||||
end: range.end
|
|
||||||
};
|
|
||||||
const { params, whereClause } = buildDateFilter(dateRange);
|
|
||||||
const [marketplaceResult, salesChannelResult, sellerResult] = await Promise.all([
|
const [marketplaceResult, salesChannelResult, sellerResult] = await Promise.all([
|
||||||
pool.query(`
|
pool.query(`
|
||||||
SELECT DISTINCT NULLIF(TRIM(marketplace), '') as value
|
SELECT DISTINCT NULLIF(TRIM(marketplace), '') as value
|
||||||
FROM orders
|
FROM orders
|
||||||
${whereClause}
|
WHERE NULLIF(TRIM(marketplace), '') IS NOT NULL
|
||||||
AND NULLIF(TRIM(marketplace), '') IS NOT NULL
|
|
||||||
ORDER BY value ASC;
|
ORDER BY value ASC;
|
||||||
`, params),
|
`),
|
||||||
pool.query(`
|
pool.query(`
|
||||||
SELECT DISTINCT NULLIF(TRIM(canal_venda), '') as value
|
SELECT DISTINCT NULLIF(TRIM(canal_venda), '') as value
|
||||||
FROM orders
|
FROM orders
|
||||||
${whereClause}
|
WHERE NULLIF(TRIM(canal_venda), '') IS NOT NULL
|
||||||
AND NULLIF(TRIM(canal_venda), '') IS NOT NULL
|
|
||||||
ORDER BY value ASC;
|
ORDER BY value ASC;
|
||||||
`, params),
|
`),
|
||||||
pool.query(`
|
pool.query(`
|
||||||
SELECT
|
SELECT
|
||||||
NULLIF(TRIM(id_vendedor), '') as id,
|
NULLIF(TRIM(id_vendedor), '') as id,
|
||||||
NULLIF(TRIM(nome_vendedor), '') as name
|
NULLIF(TRIM(nome_vendedor), '') as name
|
||||||
FROM orders
|
FROM orders
|
||||||
${whereClause}
|
WHERE (
|
||||||
AND (
|
|
||||||
NULLIF(TRIM(id_vendedor), '') IS NOT NULL
|
NULLIF(TRIM(id_vendedor), '') IS NOT NULL
|
||||||
OR NULLIF(TRIM(nome_vendedor), '') IS NOT NULL
|
OR NULLIF(TRIM(nome_vendedor), '') IS NOT NULL
|
||||||
)
|
)
|
||||||
GROUP BY id, name
|
GROUP BY id, name
|
||||||
ORDER BY COALESCE(name, id) ASC, id ASC;
|
ORDER BY COALESCE(name, id) ASC, id ASC;
|
||||||
`, params)
|
`)
|
||||||
]);
|
]);
|
||||||
const sellerOptionsByValue = new Map();
|
const sellerOptionsByValue = new Map();
|
||||||
|
|
||||||
|
|||||||
@@ -612,7 +612,7 @@ test('getClientAnalytics groups phone-less history through the customer identity
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
test('getClientFilterOptions returns distinct date-scoped order metadata options', async () => {
|
test('getClientFilterOptions returns all distinct order metadata options', async () => {
|
||||||
const originalQuery = pool.query;
|
const originalQuery = pool.query;
|
||||||
const calls = [];
|
const calls = [];
|
||||||
|
|
||||||
@@ -641,10 +641,12 @@ test('getClientFilterOptions returns distinct date-scoped order metadata options
|
|||||||
|
|
||||||
assert.equal(calls.length, 3);
|
assert.equal(calls.length, 3);
|
||||||
calls.forEach(call => {
|
calls.forEach(call => {
|
||||||
assert.deepEqual(call.params, ['2026-06-01', '2026-06-15']);
|
assert.deepEqual(call.params, []);
|
||||||
assert.match(call.sql, /data_pedido_date >= \$1::date/);
|
assert.doesNotMatch(call.sql, /data_pedido_date >=/);
|
||||||
assert.match(call.sql, /data_pedido_date <= \$2::date/);
|
assert.doesNotMatch(call.sql, /data_pedido_date <=/);
|
||||||
});
|
});
|
||||||
|
assert.match(calls[0].sql, /WHERE NULLIF\(TRIM\(marketplace\), ''\) IS NOT NULL/);
|
||||||
|
assert.match(calls[2].sql, /NULLIF\(TRIM\(nome_vendedor\), ''\) IS NOT NULL/);
|
||||||
assert.deepEqual(options.marketplaces, ['Mercado Livre', 'Shopee']);
|
assert.deepEqual(options.marketplaces, ['Mercado Livre', 'Shopee']);
|
||||||
assert.deepEqual(options.salesChannels, ['Online']);
|
assert.deepEqual(options.salesChannels, ['Online']);
|
||||||
assert.deepEqual(options.sellers, [
|
assert.deepEqual(options.sellers, [
|
||||||
|
|||||||
Reference in New Issue
Block a user