Changes in times and Dashboard
This commit is contained in:
@@ -6,90 +6,39 @@ const {createClient} = require("@supabase/supabase-js")
|
||||
const supabase = createClient("https://uwppvcxflrcsibuzsbil.supabase.co","eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InV3cHB2Y3hmbHJjc2lidXpzYmlsIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImlhdCI6MTcwMDkzODE5NCwiZXhwIjoyMDE2NTE0MTk0fQ.6hOkD1J8XBkVJUm-swv0ngLQ74xrEYr28EEbo0rUrts")
|
||||
const tenant = 6
|
||||
let rows = []
|
||||
let vendors = []
|
||||
let contacts = []
|
||||
fs.createReadStream(path.join(__dirname, "./Lieferanten.csv"), "utf-8")
|
||||
let projects = []
|
||||
fs.createReadStream(path.join(__dirname, "./Projekte.csv"), "utf-8")
|
||||
.pipe(csv({ separator: ";" }))
|
||||
.on("data", (data) => rows.push(data))
|
||||
.on("end", async function () {
|
||||
console.log("finished");
|
||||
console.log(rows)
|
||||
|
||||
vendors = rows.map(i => {
|
||||
console.log(rows[10].customer)
|
||||
|
||||
projects = rows.map(i => {
|
||||
|
||||
let item = {
|
||||
vendorNumber : Number(i['Lieferanten-Nr.']),
|
||||
customer : Number(i.customer),
|
||||
tenant: tenant,
|
||||
name: i.Firmenname,
|
||||
infoData: {
|
||||
zip: i["PLZ"],
|
||||
city: i["Ort"],
|
||||
street: i["Namenszusatz"],
|
||||
tel: i["Telefon 1"],
|
||||
}
|
||||
}
|
||||
|
||||
if(i["Land"] === "D") {
|
||||
item.infoData.country = "Deutschland"
|
||||
} else if(i["Land"] === "IRL") {
|
||||
item.infoData.country = "Irland"
|
||||
} else if(i["Land"] === "B") {
|
||||
item.infoData.country = "Belgien"
|
||||
} else if(i["Land"] === "F") {
|
||||
item.infoData.country = "Frankreich"
|
||||
} else if(i["Land"] === "E") {
|
||||
item.infoData.country = "Spanien"
|
||||
} else if(i["Land"] === "USA") {
|
||||
item.infoData.country = "USA"
|
||||
} else if(i["Land"] === "NL") {
|
||||
item.infoData.country = "Niederlande"
|
||||
} else if(i["Land"] === "S") {
|
||||
item.infoData.country = "Schweden"
|
||||
name: i.Projektname,
|
||||
notes: i.Anmerkungen + "\n" + i['Angaben zum Projekt']
|
||||
}
|
||||
|
||||
|
||||
return item
|
||||
|
||||
})
|
||||
console.log(vendors)
|
||||
|
||||
rows.forEach(i => {
|
||||
if(i["Haupt-AP"]) {
|
||||
let item = {
|
||||
firstName: i["Haupt-AP"].split(" ")[1],
|
||||
lastName: i["Haupt-AP"].split(" ")[2],
|
||||
fullName: i["Haupt-AP"].split(" ")[1] + i["Haupt-AP"].split(" ")[2],
|
||||
salutation: i["Haupt-AP"].split(" ")[0],
|
||||
tenant: tenant,
|
||||
vendorNumber: i['Lieferanten-Nr.']
|
||||
}
|
||||
|
||||
contacts.push(item)
|
||||
}
|
||||
console.log(projects)
|
||||
|
||||
|
||||
})
|
||||
console.log(contacts)
|
||||
|
||||
|
||||
const {data:vendorsData,error: vendorsError} = await supabase.from("vendors").insert(vendors).select()
|
||||
const {data:vendorsData,error: vendorsError} = await supabase.from("projects").insert(projects).select()
|
||||
console.log(vendorsData)
|
||||
console.log(vendorsError)
|
||||
|
||||
contacts = contacts.map(i => {
|
||||
let item = {
|
||||
...i,
|
||||
vendor: vendorsData.find(v => v.vendorNumber === i.vendorNumber).id
|
||||
}
|
||||
|
||||
delete item.vendorNumber
|
||||
|
||||
return item
|
||||
})
|
||||
|
||||
const {data:contactsData,error: contactsError} = await supabase.from("contacts").insert(contacts).select()
|
||||
console.log(contactsData)
|
||||
console.log(contactsError)
|
||||
|
||||
|
||||
//console.log(rows)
|
||||
|
||||
Reference in New Issue
Block a user