diff --git a/suppliersGln.js b/suppliersGln.js index 4ba939c..0692031 100644 --- a/suppliersGln.js +++ b/suppliersGln.js @@ -6,6 +6,4 @@ let floraholland = [ 8718288004970, ]; -let others = []; - export default {floraholland}; \ No newline at end of file diff --git a/utils.js b/utils.js index dab88c3..76f609c 100644 --- a/utils.js +++ b/utils.js @@ -222,20 +222,49 @@ async function syncSuppliers(){ 'Authorization': `Bearer ${await getJWT()}`, 'X-Api-Key': process.env.API_KEY }; - - let rFloraHolland = suppliersGln.floraholland; - let queryMaxSeqNumber = `${BASE_CUSTOMER_URL}organizations/current-max-sequence`; + let maximumSequenceNumber = 500; - let responseMaxSequence = await fetch(queryMaxSeqNumber, { - method: 'GET', - headers: headers - }); + for (let i = 0; i < maximumSequenceNumber; i++) { - let dataMaxSequence = await responseMaxSequence.json(); + let query = `${BASE_CUSTOMER_URL}organizations/sync/${i}?organizationType=SUPPLIER&limit=500`; + let response = await fetch(query, { + method: 'GET', + headers: headers + }); - console.log('Maximum sequence number: ', dataMaxSequence); - + let data = await response.json(); + + maximumSequenceNumber = data.maximumSequenceNumber; + let suppliers = data.results; + + for (let supplier of suppliers) { + i = supplier.sequenceNumber; + await models.suppliers.upsert({ + isConnected: false, + commercialName: supplier.commercialName, + email: supplier.email, + phone: supplier.phone, + website: supplier.website, + mailingAddress: supplier.mailingAddress, + physicalAddress: supplier.physicalAddress, + pythosanitaryNumber: supplier.pythosanitaryNumber, + sequenceNumber: supplier.sequenceNumber, + organizationId: supplier.organizationId, + companyGln: supplier.companyGln, + name: supplier.name, + endDate: supplier.endDate, + rfhRelationId: supplier.rfhRelationId, + organizationType: supplier.organizationType, + paymentProviders: `${supplier.paymentProviders}`, + }); + console.log('INSERTED:\t', supplier.commercialName, '\nsequenceNumber:\t', supplier.sequenceNumber); + } + await syncSequence(i, 'suppliers', maximumSequenceNumber); + console.log(data.maximumSequenceNumber); + console.log(data.results.length); + console.log(i); + } } async function syncTradeItems(){