get all the suppliers from floriday api
This commit is contained in:
parent
1cb0d06282
commit
be0c20307b
|
@ -6,6 +6,4 @@ let floraholland = [
|
|||
8718288004970,
|
||||
];
|
||||
|
||||
let others = [];
|
||||
|
||||
export default {floraholland};
|
49
utils.js
49
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(){
|
||||
|
|
Loading…
Reference in New Issue