Changed Backend to Supabase
This commit is contained in:
@@ -1,12 +1,18 @@
|
||||
<script setup>
|
||||
import {move} from "@antfu/utils";
|
||||
|
||||
definePageMeta({
|
||||
middleware: "auth"
|
||||
})
|
||||
|
||||
const {find,create, update} = useStrapi4()
|
||||
const spaces = (await find('spaces',{populate: "*"})).data
|
||||
const movements = (await find('movements',{populate: "*"})).data
|
||||
const products = (await find('products',{populate: "*"})).data
|
||||
const supabase = useSupabaseClient()
|
||||
|
||||
const spaces = (await supabase.from("spaces").select()).data
|
||||
const movements = (await supabase.from("movements").select()).data
|
||||
const products = (await supabase.from("products").select()).data
|
||||
const units = (await supabase.from("units").select()).data
|
||||
|
||||
|
||||
|
||||
|
||||
let selectedItem = ref({})
|
||||
@@ -14,9 +20,10 @@ const showCreateSpace = ref(false)
|
||||
|
||||
const selectItem = (item) => {
|
||||
selectedItem.value = item
|
||||
spaceMovements.value = movements.filter(movement => movement.attributes.spaceId === selectedItem.value.attributes.spaceNumber)
|
||||
spaceMovements.value = movements.filter(movement => movement.spaceId === selectedItem.value.id)
|
||||
spaceProducts.value = []
|
||||
spaceMovements.value.forEach(movement => {
|
||||
if(!spaceProducts.value.includes(movement.attributes.productId)) spaceProducts.value.push(movement.attributes.productId)
|
||||
if(spaceProducts.value.filter(product => product.id === movement.productId).length === 0) spaceProducts.value.push(products.find(product => product.id === movement.productId))
|
||||
})
|
||||
|
||||
|
||||
@@ -30,10 +37,16 @@ const createSpaceData = ref({})
|
||||
const createSpace = async () => {
|
||||
let lastSpaceNumber = 0
|
||||
spaces.forEach(space => {
|
||||
if(space.attributes.spaceNumber > lastSpaceNumber) lastSpaceNumber = space.attributes.spaceNumber
|
||||
if(space.spaceNumber > lastSpaceNumber) lastSpaceNumber = space.spaceNumber
|
||||
})
|
||||
|
||||
await create('spaces', {...createSpaceData.value, spaceNumber: String(Number(lastSpaceNumber)+1)})
|
||||
const {data,error} = await supabase
|
||||
.from("spaces")
|
||||
.insert([ {...createSpaceData.value, spaceNumber: String(Number(lastSpaceNumber)+1)}])
|
||||
.select()
|
||||
|
||||
console.log(error)
|
||||
|
||||
showCreateSpace.value = false
|
||||
createSpaceData.value = {}
|
||||
|
||||
@@ -43,9 +56,9 @@ const spaceProducts = ref([])
|
||||
const spaceMovements = ref([])
|
||||
|
||||
function getSpaceProductCount(productId) {
|
||||
let productMovements = spaceMovements.value.filter(movement => movement.attributes.productId === productId)
|
||||
let productMovements = spaceMovements.value.filter(movement => movement.productId === productId)
|
||||
let count = 0;
|
||||
productMovements.forEach(movement => count += movement.attributes.quantity)
|
||||
productMovements.forEach(movement => count += movement.quantity)
|
||||
|
||||
return count
|
||||
|
||||
@@ -87,24 +100,26 @@ function getSpaceProductCount(productId) {
|
||||
</UModal>
|
||||
<a v-for="item in spaces" @click="selectItem(item)">
|
||||
<UCard class="listItem">
|
||||
{{item.attributes.spaceNumber}} - {{item.attributes.type}}
|
||||
{{item.spaceNumber}} - {{item.type}}
|
||||
</UCard>
|
||||
</a>
|
||||
</div>
|
||||
<div id="right">
|
||||
<UCard v-if="selectedItem.attributes">
|
||||
<template #header>
|
||||
<UBadge class="mr-1">{{selectedItem.attributes.spaceNumber}}</UBadge>{{selectedItem.attributes.type}}
|
||||
</template>
|
||||
{{selectedItem.attributes.description}}
|
||||
<div v-if="selectedItem.id">
|
||||
<UCard>
|
||||
<template #header>
|
||||
<UBadge class="mr-1">{{selectedItem.spaceNumber}}</UBadge>{{selectedItem.type}}
|
||||
</template>
|
||||
{{selectedItem.description}}
|
||||
|
||||
|
||||
</UCard>
|
||||
|
||||
|
||||
<p class="mt-5">Artikel in diesem Lagerplatz</p>
|
||||
<p v-for="product in spaceProducts">{{products.find(productItem => Number(productItem.id) === Number(product)).attributes.name}} - {{getSpaceProductCount(product)}} {{products.find(productItem => Number(productItem.id) === Number(product)).attributes.unit}}</p>
|
||||
</div>
|
||||
</UCard>
|
||||
<div v-if="spaceProducts.length > 0">
|
||||
<p class="mt-5">Artikel in diesem Lagerplatz</p>
|
||||
<p v-for="product in spaceProducts">{{product.name}} - {{getSpaceProductCount(product.id)}} {{units.find(unit => unit.id === product.unit).name}}</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user