Removed Old Update and Create
This commit is contained in:
132
stores/data.js
132
stores/data.js
@@ -49,7 +49,6 @@ import sepaDate from "~/components/columnRenderings/sepaDate.vue";
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
export const useDataStore = defineStore('data', () => {
|
export const useDataStore = defineStore('data', () => {
|
||||||
|
|
||||||
const supabase = useSupabaseClient()
|
|
||||||
const profileStore = useProfileStore()
|
const profileStore = useProfileStore()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
@@ -2593,136 +2592,7 @@ export const useDataStore = defineStore('data', () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
async function createNewItem (dataType,data,noRedirect=false){
|
|
||||||
if(typeof(data) === 'object') {
|
|
||||||
data = {...data, tenant: profileStore.currentTenant}
|
|
||||||
} else if(typeof(data) === 'array') {
|
|
||||||
data.map(i => {
|
|
||||||
return {
|
|
||||||
...i,
|
|
||||||
tenant: profileStore.currentTenant
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(dataType)
|
|
||||||
if(dataTypes[dataType].numberRangeHolder) {
|
|
||||||
|
|
||||||
if(!data[dataTypes[dataType].numberRangeHolder]) {
|
|
||||||
data[dataTypes[dataType].numberRangeHolder] = await useFunctions().useNextNumber(dataType)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
} else if(dataType === "createddocuments" && data.type !== "serialInvoices") {
|
|
||||||
/*if(data.state !== "Entwurf") {
|
|
||||||
console.log(data.type)
|
|
||||||
|
|
||||||
let type = ""
|
|
||||||
if(data.type === "advanceInvoices"){
|
|
||||||
type = "invoices"
|
|
||||||
} else {
|
|
||||||
type = data.type
|
|
||||||
}
|
|
||||||
|
|
||||||
const numberRange = useNumberRange(type)
|
|
||||||
data.documentNumber = await numberRange.useNextNumber()
|
|
||||||
}*/
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const {data:supabaseData,error:supabaseError} = await supabase
|
|
||||||
.from(dataType)
|
|
||||||
.insert(data)
|
|
||||||
.select()
|
|
||||||
|
|
||||||
if(supabaseError) {
|
|
||||||
console.log(supabaseError)
|
|
||||||
toast.add({title: "Es ist ein Fehler bei der Erstellung aufgetreten", color: "rose"})
|
|
||||||
} else if (supabaseData) {
|
|
||||||
console.log(supabaseData)
|
|
||||||
|
|
||||||
let returnData = supabaseData[0]
|
|
||||||
|
|
||||||
await generateHistoryItems(dataType, supabaseData[0])
|
|
||||||
|
|
||||||
/*if(!["statementallocations","absencerequests", "productcategories", "servicecategories", "projecttypes", "checks", "profiles","services", "inventoryitems", "inventoryitemgroups", "incominginvoices", "costcentres", "ownaccounts"].includes(dataType) ){
|
|
||||||
await eval( dataType + '.value.push(' + JSON.stringify(...supabaseData) + ')')
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
toast.add({title: `${dataTypes[dataType].labelSingle} hinzugefügt`})
|
|
||||||
if(dataTypes[dataType].redirect && !noRedirect) {
|
|
||||||
if(dataTypes[dataType].isStandardEntity) {
|
|
||||||
await router.push(dataTypes[dataType].redirectToList ? `/standardEntity/${dataType}` : `/standardEntity/${dataType}/show/${returnData.id}`)
|
|
||||||
} else {
|
|
||||||
await router.push(dataTypes[dataType].redirectToList ? `/${dataType}` : `/${dataType}/show/${returnData.id}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modal.close()
|
|
||||||
return supabaseData[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async function updateItem (dataType, data, oldData = null, noRedirect = false) {
|
|
||||||
//console.log(dataType, data)
|
|
||||||
//Temporary Fix TODO: Remove and build Solution
|
|
||||||
data = JSON.parse(JSON.stringify(data))
|
|
||||||
delete data.users
|
|
||||||
|
|
||||||
if(oldData) {
|
|
||||||
oldData = JSON.parse(JSON.stringify(oldData))
|
|
||||||
delete oldData.users
|
|
||||||
}
|
|
||||||
|
|
||||||
const {tenants, ...newData} = data
|
|
||||||
|
|
||||||
/*if(dataType === "createddocuments" && data.type !== "serialInvoices") {
|
|
||||||
if(data.state !== "Entwurf") {
|
|
||||||
console.log(data.type)
|
|
||||||
|
|
||||||
let type = ""
|
|
||||||
if(data.type === "advanceInvoices"){
|
|
||||||
type = "invoices"
|
|
||||||
} else {
|
|
||||||
type = data.type
|
|
||||||
}
|
|
||||||
|
|
||||||
const numberRange = useNumberRange(type)
|
|
||||||
data.documentNumber = await numberRange.useNextNumber()
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
await generateHistoryItems(dataType,data,oldData)
|
|
||||||
|
|
||||||
const {data:supabaseData,error: supabaseError} = await supabase
|
|
||||||
.from(dataType)
|
|
||||||
.update(newData)
|
|
||||||
.eq('id',newData.id)
|
|
||||||
.select()
|
|
||||||
|
|
||||||
if(supabaseError) {
|
|
||||||
console.log(supabaseError)
|
|
||||||
toast.add({title: `Fehler beim Speichern`, color: 'rose'})
|
|
||||||
} else if(supabaseData) {
|
|
||||||
//await eval(dataType + '.value[' + dataType + '.value.findIndex(i => i.id === ' + JSON.stringify(data.id) + ')] = ' + JSON.stringify(supabaseData[0]))
|
|
||||||
//if(dataType === 'profiles') await fetchProfiles()
|
|
||||||
toast.add({title: `${dataTypes[dataType].labelSingle} gespeichert`})
|
|
||||||
if(dataTypes[dataType].redirect && !noRedirect) {
|
|
||||||
if(dataTypes[dataType].isStandardEntity) {
|
|
||||||
await router.push(dataTypes[dataType].redirectToList ? `/standardEntity/${dataType}` : `/standardEntity/${dataType}/show/${data.id}`)
|
|
||||||
} else {
|
|
||||||
await router.push(dataTypes[dataType].redirectToList ? `/${dataType}` : `/${dataType}/show/${data.id}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modal.close()
|
|
||||||
return supabaseData[0]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -2732,7 +2602,5 @@ export const useDataStore = defineStore('data', () => {
|
|||||||
return {
|
return {
|
||||||
dataTypes,
|
dataTypes,
|
||||||
documentTypesForCreation,
|
documentTypesForCreation,
|
||||||
createNewItem,
|
|
||||||
updateItem,
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user