get all the suppliers from floriday api

This commit is contained in:
Pau 2023-02-07 14:38:54 +01:00
parent 1cb0d06282
commit be0c20307b
2 changed files with 39 additions and 12 deletions

View File

@ -6,6 +6,4 @@ let floraholland = [
8718288004970,
];
let others = [];
export default {floraholland};

View File

@ -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(){