257b93e691
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | [#353] | front de la page admin client | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: https://gitea.malio.fr/MALIO-DEV/Ferme/pulls/38 Reviewed-by: Autin <tristan@yuno.malio.fr> Co-authored-by: sroy <sebastien@yuno.malio.fr> Co-committed-by: sroy <sebastien@yuno.malio.fr>
43 lines
1.6 KiB
Vue
43 lines
1.6 KiB
Vue
<template>
|
|
<Address type="supplier" :address="address" @validate="validate"/>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import type {AddressData, AddressPayload} from "~/services/address";
|
|
import {createAddress, getAddress, updateAddress} from "~/services/address";
|
|
import {getSupplier, updateSupplier} from "~/services/supplier";
|
|
import type {SupplierData} from "~/services/dto/supplier-data";
|
|
|
|
const route = useRoute()
|
|
const router = useRouter()
|
|
const supplierId = computed(() => { return Number(route.query.supplierId) })
|
|
const supplier = ref<SupplierData|null>(null);
|
|
const addressId = computed(() => { return route.query.addressId !== undefined ? Number(route.query.addressId) : null })
|
|
const address = ref<AddressData|null>(null)
|
|
|
|
const validate = async (address: AddressPayload) => {
|
|
if (addressId.value !== null) {
|
|
await updateAddress(addressId.value, address)
|
|
} else {
|
|
await addAddress(address)
|
|
await router.push('/admin/supplier/' + supplierId.value)
|
|
}
|
|
}
|
|
|
|
const addAddress = async (address: AddressPayload) => {
|
|
const response: AddressData = await createAddress(address)
|
|
const addressIRI = `/api/addresses/${response.id}`
|
|
const existingIris = (supplier.value.addresses ?? []).map((item: any) => `/api/addresses/${item.id}`)
|
|
const next = [...new Set([...existingIris, addressIRI])]
|
|
|
|
return await updateSupplier(supplierId.value, { addresses: next })
|
|
}
|
|
|
|
onMounted(async () => {
|
|
supplier.value = await getSupplier(supplierId.value)
|
|
if (addressId.value !== null) {
|
|
address.value = await getAddress(addressId.value)
|
|
}
|
|
})
|
|
</script>
|