All checks were successful
Build and Deploy / build-and-deploy (push) Successful in 2m44s
27 lines
808 B
JavaScript
27 lines
808 B
JavaScript
const SIZE_SUFFIX_PATTERN = /\s+-\s+(?:(?:PP|P|M|G|GG|XG|XGG|EG|EGG|EXG|U|UNICO|ÚNICO|\d{2})(?:\/(?:PP|P|M|G|GG|XG|XGG|EG|EGG|EXG|U|UNICO|ÚNICO|\d{2}))*)$/i;
|
|
|
|
const getBaseProductName = (name) => {
|
|
return String(name || 'Unknown')
|
|
.split(' TAMANHO')[0]
|
|
.replace(SIZE_SUFFIX_PATTERN, '')
|
|
.trim();
|
|
};
|
|
|
|
const normalizeStockPayload = (item) => {
|
|
const produtoId = item.idProduto || item.ID_Produto || '';
|
|
const nome = item.nome || item.Descricao_Produto || 'Unknown';
|
|
|
|
return {
|
|
produtoId: String(produtoId),
|
|
nome,
|
|
baseProductName: getBaseProductName(nome),
|
|
saldo: parseInt(item.saldo, 10) || 0,
|
|
deltaEstoque: parseInt(item.delta_estoque, 10) || 0
|
|
};
|
|
};
|
|
|
|
module.exports = {
|
|
getBaseProductName,
|
|
normalizeStockPayload
|
|
};
|