Skip to content

Commit

Permalink
fix(export-customer): check doc to create customer
Browse files Browse the repository at this point in the history
  • Loading branch information
wisley7l committed Aug 13, 2024
1 parent ef90485 commit 2311137
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions functions/lib/integration/exports/customers-to-horus.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ module.exports = async ({ appSdk, storeId, auth }, customerId, opts = {}) => {
console.log(`> Customer #${customerId} not found`)
return null
}
const { username, password, baseURL } = appData
const horus = new Horus(username, password, baseURL)
const customerHorus = await getClientByCustomer(storeId, horus, customer)
console.log(`customer: ${customerHorus && JSON.stringify(customerHorus)}`)
if (isCreate) {
// create/update customer in HORUS
const documentType = customer.registry_type === 'p' ? 'CPF' : 'CNPJ'
const documentNumber = customer.doc_number
let customerHorus

if (isCreate && documentNumber && documentType) {
const { username, password, baseURL } = appData
const horus = new Horus(username, password, baseURL)
customerHorus = await getClientByCustomer(storeId, horus, customer)
// console.log(`customer: ${customerHorus && JSON.stringify(customerHorus)}`)
// create/update customer in HORUS
const method = customerHorus && customerHorus?.COD_CLI ? 'PUT' : 'POST'
const body = {
COD_CLI: customerHorus?.COD_CLI || 'NOVO',
Expand Down Expand Up @@ -100,9 +104,6 @@ module.exports = async ({ appSdk, storeId, auth }, customerId, opts = {}) => {
}
return customerId
}
if (method === 'PUT') {
console.log(`debug ${JSON.stringify(data)}`)
}

return method === 'PUT' ? customerId : null
})
Expand Down

0 comments on commit 2311137

Please sign in to comment.