Compare commits
1 Commits
83b339746e
...
feat/admin
| Author | SHA1 | Date | |
|---|---|---|---|
| 311f523647 |
85
.idea/workspace.xml
generated
85
.idea/workspace.xml
generated
@@ -4,11 +4,16 @@
|
|||||||
<option name="autoReloadType" value="SELECTIVE" />
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="7c107abe-5995-4428-8429-b146aaca8386" name="Changes" comment="fix : panel scrollable plus interface revue">
|
<list default="true" id="7c107abe-5995-4428-8429-b146aaca8386" name="Changes" comment="feat : test auto-tag-develop.yml (auto incrément version)">
|
||||||
|
<change afterPath="$PROJECT_DIR$/frontend/composables/useAppVersion.ts" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/config/packages/security.yaml" beforeDir="false" afterPath="$PROJECT_DIR$/config/packages/security.yaml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/config/reference.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/reference.php" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/config/reference.php" beforeDir="false" afterPath="$PROJECT_DIR$/config/reference.php" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/frontend/pages/admin/carrier/carrier-list.vue" beforeDir="false" afterPath="$PROJECT_DIR$/frontend/pages/admin/carrier/carrier-list.vue" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/frontend/app.vue" beforeDir="false" afterPath="$PROJECT_DIR$/frontend/app.vue" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/frontend/pages/admin/supplier/supplier-list.vue" beforeDir="false" afterPath="$PROJECT_DIR$/frontend/pages/admin/supplier/supplier-list.vue" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/frontend/layouts/default.vue" beforeDir="false" afterPath="$PROJECT_DIR$/frontend/layouts/default.vue" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/frontend/pages/login.vue" beforeDir="false" afterPath="$PROJECT_DIR$/frontend/pages/login.vue" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/Dto/AppVersion.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/ApiResource/AppVersion.php" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/src/State/AppVersionProvider.php" beforeDir="false" afterPath="$PROJECT_DIR$/src/State/AppVersionProvider.php" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -220,43 +225,43 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"RunOnceActivity.MCP Project settings loaded": "true",
|
"RunOnceActivity.MCP Project settings loaded": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
"RunOnceActivity.TerminalTabsStorage.copyFrom.TerminalArrangementManager.252": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
"RunOnceActivity.typescript.service.memoryLimit.init": "true",
|
||||||
"git-widget-placeholder": "feat/312-creation-d-une-page-d-administration-listing-des-fournisseurs",
|
"git-widget-placeholder": "develop",
|
||||||
"last_opened_file_path": "/home/sroy/Documents/test/Ferme",
|
"last_opened_file_path": "/home/sroy/Documents/test/Ferme",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"settings.editor.selected.configurable": "configurable.tailwindcss",
|
"settings.editor.selected.configurable": "configurable.tailwindcss",
|
||||||
"ts.external.directory.path": "/opt/phpstorm/plugins/javascript-plugin/jsLanguageServicesImpl/external",
|
"ts.external.directory.path": "/opt/phpstorm/plugins/javascript-plugin/jsLanguageServicesImpl/external",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
},
|
},
|
||||||
"keyToStringList": {
|
"keyToStringList": {
|
||||||
"DatabaseDriversLRU": [
|
"DatabaseDriversLRU": [
|
||||||
"postgresql"
|
"postgresql"
|
||||||
],
|
],
|
||||||
"com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [
|
"com.intellij.ide.scratch.ScratchImplUtil$2/New Scratch File": [
|
||||||
"TEXT"
|
"TEXT"
|
||||||
],
|
],
|
||||||
"vue.recent.templates": [
|
"vue.recent.templates": [
|
||||||
"Vue Composition API Component"
|
"Vue Composition API Component"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RecentsManager">
|
<component name="RecentsManager">
|
||||||
<key name="MoveFile.RECENT_KEYS">
|
<key name="MoveFile.RECENT_KEYS">
|
||||||
<recent name="\\wsl.localhost\Ubuntu-24.04\home\matte\Ferme\frontend\pages\admin\supplier" />
|
|
||||||
<recent name="\\wsl.localhost\Ubuntu-24.04\home\m-tristan\workspace\Ferme" />
|
<recent name="\\wsl.localhost\Ubuntu-24.04\home\m-tristan\workspace\Ferme" />
|
||||||
<recent name="\\wsl.localhost\Ubuntu-24.04\home\tristan\workspace\ferme\templates" />
|
<recent name="\\wsl.localhost\Ubuntu-24.04\home\tristan\workspace\ferme\templates" />
|
||||||
<recent name="C:\Users\autin\AppData\Roaming\JetBrains\PhpStorm2025.3\scratches" />
|
<recent name="C:\Users\autin\AppData\Roaming\JetBrains\PhpStorm2025.3\scratches" />
|
||||||
<recent name="C:\Users\autin\AppData\Roaming\JetBrains\PhpStorm2025.3\scratches\Ferme_MCD\MCD_DOC" />
|
<recent name="C:\Users\autin\AppData\Roaming\JetBrains\PhpStorm2025.3\scratches\Ferme_MCD\MCD_DOC" />
|
||||||
|
<recent name="\\wsl.localhost\Ubuntu-24.04\home\tristan\workspace\ferme\frontend\pages\reception" />
|
||||||
</key>
|
</key>
|
||||||
</component>
|
</component>
|
||||||
<component name="SharedIndexes">
|
<component name="SharedIndexes">
|
||||||
@@ -297,6 +302,14 @@
|
|||||||
<workItem from="1770195959162" duration="18915000" />
|
<workItem from="1770195959162" duration="18915000" />
|
||||||
<workItem from="1770274844804" duration="3940000" />
|
<workItem from="1770274844804" duration="3940000" />
|
||||||
</task>
|
</task>
|
||||||
|
<task id="LOCAL-00009" summary="feat : ajout d'une gestion d'erreur au global côté front avec la lib toaster et I18n pour centraliser les messages d'erreur">
|
||||||
|
<option name="closed" value="true" />
|
||||||
|
<created>1768555180530</created>
|
||||||
|
<option name="number" value="00009" />
|
||||||
|
<option name="presentableId" value="LOCAL-00009" />
|
||||||
|
<option name="project" value="LOCAL" />
|
||||||
|
<updated>1768555180530</updated>
|
||||||
|
</task>
|
||||||
<task id="LOCAL-00010" summary="feat : ajout de l'authentification avec lexik">
|
<task id="LOCAL-00010" summary="feat : ajout de l'authentification avec lexik">
|
||||||
<option name="closed" value="true" />
|
<option name="closed" value="true" />
|
||||||
<created>1768832208350</created>
|
<created>1768832208350</created>
|
||||||
@@ -681,15 +694,7 @@
|
|||||||
<option name="project" value="LOCAL" />
|
<option name="project" value="LOCAL" />
|
||||||
<updated>1770371073055</updated>
|
<updated>1770371073055</updated>
|
||||||
</task>
|
</task>
|
||||||
<task id="LOCAL-00058" summary="fix : nom page fournisseur">
|
<option name="localTasksCounter" value="58" />
|
||||||
<option name="closed" value="true" />
|
|
||||||
<created>1770632525875</created>
|
|
||||||
<option name="number" value="00058" />
|
|
||||||
<option name="presentableId" value="LOCAL-00058" />
|
|
||||||
<option name="project" value="LOCAL" />
|
|
||||||
<updated>1770632525875</updated>
|
|
||||||
</task>
|
|
||||||
<option name="localTasksCounter" value="59" />
|
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
<component name="TypeScriptGeneratedFilesManager">
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
@@ -739,6 +744,7 @@
|
|||||||
</option>
|
</option>
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
<component name="VcsManagerConfiguration">
|
||||||
|
<MESSAGE value="fix : gitea workflow" />
|
||||||
<MESSAGE value="fix : script de déploiement" />
|
<MESSAGE value="fix : script de déploiement" />
|
||||||
<MESSAGE value="feat : ajout plus d'information sur la liste des réceptions côté front sur la page d'accueil" />
|
<MESSAGE value="feat : ajout plus d'information sur la liste des réceptions côté front sur la page d'accueil" />
|
||||||
<MESSAGE value="fix : redirige sur le login sur une 401 et reset du auth state + doc + timeout du toaster" />
|
<MESSAGE value="fix : redirige sur le login sur une 401 et reset du auth state + doc + timeout du toaster" />
|
||||||
@@ -763,8 +769,7 @@
|
|||||||
<MESSAGE value="feat : update numéro de version" />
|
<MESSAGE value="feat : update numéro de version" />
|
||||||
<MESSAGE value="fix : auto-tag-develop.yml" />
|
<MESSAGE value="fix : auto-tag-develop.yml" />
|
||||||
<MESSAGE value="feat : test auto-tag-develop.yml (auto incrément version)" />
|
<MESSAGE value="feat : test auto-tag-develop.yml (auto incrément version)" />
|
||||||
<MESSAGE value="fix : nom page fournisseur" />
|
<option name="LAST_COMMIT_MESSAGE" value="feat : test auto-tag-develop.yml (auto incrément version)" />
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="fix : nom page fournisseur" />
|
|
||||||
</component>
|
</component>
|
||||||
<component name="XSLT-Support.FileAssociations.UIState">
|
<component name="XSLT-Support.FileAssociations.UIState">
|
||||||
<expand />
|
<expand />
|
||||||
|
|||||||
@@ -29,12 +29,6 @@ Ajouter dans le fichier .env du frontend
|
|||||||
* Finalisation de la partie réception de marchandise
|
* Finalisation de la partie réception de marchandise
|
||||||
* [#267] Lister les réceptions en attente
|
* [#267] Lister les réceptions en attente
|
||||||
* [#268] Lister les réceptions terminées
|
* [#268] Lister les réceptions terminées
|
||||||
* [#316] Admin liste des transporteurs
|
|
||||||
* [#312] Creation administration listing fournisseurs
|
|
||||||
* [#315] Creation page admin utilisateur
|
|
||||||
* [#317] Admin modification creation transporteur
|
|
||||||
* [#318] Affichage modification reception terminée
|
|
||||||
* [#313] Admin modification creation fournisseur
|
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
parameters:
|
parameters:
|
||||||
app.version: '0.0.37'
|
app.version: '0.0.32'
|
||||||
|
|||||||
@@ -144,7 +144,19 @@ import type {VehicleData} from '~/services/dto/vehicle-data'
|
|||||||
import {getVehicleList} from '~/services/vehicle'
|
import {getVehicleList} from '~/services/vehicle'
|
||||||
import {RECEPTION_TYPE_CODES, SUPLLIER_CODE} from "~/utils/constants";
|
import {RECEPTION_TYPE_CODES, SUPLLIER_CODE} from "~/utils/constants";
|
||||||
import {deleteReceptionBovine, getReceptionBovineList} from "~/services/reception-bovine";
|
import {deleteReceptionBovine, getReceptionBovineList} from "~/services/reception-bovine";
|
||||||
import type {ReceptionFormData} from "~/services/dto/reception-data";
|
|
||||||
|
type ReceptionFormData = {
|
||||||
|
licensePlate: string
|
||||||
|
receptionDate: string
|
||||||
|
receptionTypeId: string
|
||||||
|
userId: string
|
||||||
|
supplierId: string
|
||||||
|
addressId: string
|
||||||
|
truckId: string
|
||||||
|
carrierId: string
|
||||||
|
driverId: string
|
||||||
|
vehicleId: string
|
||||||
|
}
|
||||||
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const receptionStore = useReceptionStore()
|
const receptionStore = useReceptionStore()
|
||||||
|
|||||||
@@ -1,163 +0,0 @@
|
|||||||
<template>
|
|
||||||
<form @submit.prevent="validate">
|
|
||||||
<div class="flex items-center justify-between gap-10">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">
|
|
||||||
{{ supplierId ? "Modifications du fournisseur" : "Ajout d'un fournisseur" }}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
type="submit"
|
|
||||||
:disabled="isLoading"
|
|
||||||
>
|
|
||||||
{{ supplierId ? "Sauvegarder" : "Ajouter" }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 gap-y-16 gap-x-12 mb-16">
|
|
||||||
<UiTextInput id="supplier-name" v-model="form.name" label="Nom du fournisseur" />
|
|
||||||
<UiTextInput id="supplier-email" v-model="form.email" label="Email" />
|
|
||||||
<UiTextInput id="supplier-phone" v-model="form.phone" label="Téléphone" />
|
|
||||||
|
|
||||||
<UiTextInput id="supplier-street" v-model="form.addresses[0].street" label="Rue" />
|
|
||||||
<UiTextInput id="supplier-street2" v-model="form.addresses[0].street2" label="Complément" />
|
|
||||||
<UiTextInput id="supplier-postalCode" v-model="form.addresses[0].postalCode" label="Code postal" />
|
|
||||||
<UiTextInput id="supplier-city" v-model="form.addresses[0].city" label="Ville" />
|
|
||||||
<UiTextInput id="supplier-country" v-model="form.addresses[0].countryCode" label="Pays" />
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p v-if="errorMsg" class="text-red-600 mt-4">{{ errorMsg }}</p>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { computed, reactive, ref, watch } from "vue"
|
|
||||||
import { createSupplier, getSupplier, updateSupplier } from "~/services/supplier"
|
|
||||||
import { createAddress, updateAddress, type AddressPayload } from "~/services/address"
|
|
||||||
import type { SupplierData, SupplierFormData, SupplierPayload } from "~/services/dto/supplier-data"
|
|
||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
|
||||||
|
|
||||||
definePageMeta({ layout: "admin" })
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const resolveId = (param: unknown) => {
|
|
||||||
const idStr = Array.isArray(param) ? param[0] : param
|
|
||||||
if (!idStr) return null
|
|
||||||
const id = Number(idStr)
|
|
||||||
return Number.isFinite(id) ? id : null
|
|
||||||
}
|
|
||||||
|
|
||||||
const supplierId = computed(() => resolveId(route.params.id))
|
|
||||||
|
|
||||||
const isLoading = ref(false)
|
|
||||||
const errorMsg = ref<string | null>(null)
|
|
||||||
|
|
||||||
const emptyAddress = (): AddressFormData => ({
|
|
||||||
id: null,
|
|
||||||
label: "",
|
|
||||||
street: "",
|
|
||||||
street2: null,
|
|
||||||
postalCode: "",
|
|
||||||
city: "",
|
|
||||||
countryCode: "",
|
|
||||||
})
|
|
||||||
|
|
||||||
const form = reactive<SupplierFormData>({
|
|
||||||
name: "",
|
|
||||||
email: "",
|
|
||||||
phone: "",
|
|
||||||
addresses: [emptyAddress()],
|
|
||||||
})
|
|
||||||
|
|
||||||
const hydrateFromSupplier = (supplier: SupplierData | null) => {
|
|
||||||
if (!supplier) return
|
|
||||||
|
|
||||||
form.name = supplier.name ?? ""
|
|
||||||
form.email = supplier.email ?? ""
|
|
||||||
form.phone = supplier.phone ?? ""
|
|
||||||
|
|
||||||
if (!Array.isArray(supplier.addresses) || supplier.addresses.length === 0) return
|
|
||||||
const a0 = supplier.addresses[0]
|
|
||||||
|
|
||||||
if (typeof a0 === "string") return
|
|
||||||
|
|
||||||
form.addresses[0].id = a0.id ?? null
|
|
||||||
form.addresses[0].label = a0.label ?? ""
|
|
||||||
form.addresses[0].street = a0.street ?? ""
|
|
||||||
form.addresses[0].street2 = a0.street2 ?? null
|
|
||||||
form.addresses[0].postalCode = a0.postalCode ?? ""
|
|
||||||
form.addresses[0].city = a0.city ?? ""
|
|
||||||
form.addresses[0].countryCode = a0.countryCode ?? ""
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => supplierId.value,
|
|
||||||
async (id) => {
|
|
||||||
if (id === null) return
|
|
||||||
isLoading.value = true
|
|
||||||
try {
|
|
||||||
const supplier = await getSupplier(id)
|
|
||||||
hydrateFromSupplier(supplier)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{ immediate: true }
|
|
||||||
)
|
|
||||||
|
|
||||||
async function validate() {
|
|
||||||
if (isLoading.value) return
|
|
||||||
isLoading.value = true
|
|
||||||
errorMsg.value = null
|
|
||||||
|
|
||||||
try {
|
|
||||||
const name = form.name.trim()
|
|
||||||
const email = (form.email ?? "").trim() || null
|
|
||||||
const phone = (form.phone ?? "").trim() || null
|
|
||||||
|
|
||||||
const a0 = form.addresses[0]
|
|
||||||
|
|
||||||
const label = a0.label.trim() || name || "Adresse"
|
|
||||||
|
|
||||||
const addressPayload: AddressPayload = {
|
|
||||||
label,
|
|
||||||
street: a0.street.trim(),
|
|
||||||
street2: a0.street2?.trim() || null,
|
|
||||||
postalCode: a0.postalCode.trim(),
|
|
||||||
city: a0.city.trim(),
|
|
||||||
countryCode: a0.countryCode.trim(),
|
|
||||||
}
|
|
||||||
|
|
||||||
let addressId: number
|
|
||||||
if (a0.id) {
|
|
||||||
const updated = await updateAddress(a0.id, addressPayload)
|
|
||||||
addressId = updated.id
|
|
||||||
} else {
|
|
||||||
const created = await createAddress(addressPayload)
|
|
||||||
addressId = created.id
|
|
||||||
a0.id = addressId
|
|
||||||
}
|
|
||||||
const supplierPayload: SupplierPayload = {
|
|
||||||
name,
|
|
||||||
email,
|
|
||||||
phone,
|
|
||||||
addresses: [`/api/addresses/${addressId}`],
|
|
||||||
}
|
|
||||||
|
|
||||||
if (supplierId.value !== null) {
|
|
||||||
await updateSupplier(supplierId.value, supplierPayload)
|
|
||||||
} else {
|
|
||||||
await createSupplier(supplierPayload)
|
|
||||||
}
|
|
||||||
|
|
||||||
await router.push("/admin/supplier/supplier-list")
|
|
||||||
} catch (e) {
|
|
||||||
errorMsg.value = "Erreur lors de l’enregistrement."
|
|
||||||
throw e
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,123 +0,0 @@
|
|||||||
<template>
|
|
||||||
<form @submit.prevent="validate">
|
|
||||||
<div
|
|
||||||
class="flex items-center justify-between gap-10">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">
|
|
||||||
{{ userId ? "Modifications de l'utilisateur" : "Ajout d'un utilisateur" }}
|
|
||||||
</h1>
|
|
||||||
<button
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
type="submit"
|
|
||||||
>
|
|
||||||
{{ userId ? 'Sauvegarder' : 'Ajouter' }}
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid gap-y-16 gap-x-40 mb-16">
|
|
||||||
<UiTextInput
|
|
||||||
id="user-name"
|
|
||||||
v-model="form.username"
|
|
||||||
label="Nom de l'utilisateur"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<UiSelect
|
|
||||||
id="user-role"
|
|
||||||
v-model="form.role"
|
|
||||||
label="Rôle de l'utilisateur"
|
|
||||||
:options="ROLE"
|
|
||||||
/>
|
|
||||||
<UiTextInput
|
|
||||||
id="user-password"
|
|
||||||
v-model="form.password"
|
|
||||||
label="Mot de passe"
|
|
||||||
type="password"
|
|
||||||
|
|
||||||
/>
|
|
||||||
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
|
|
||||||
import {computed, reactive, ref, watch} from 'vue'
|
|
||||||
import {ROLE} from '~/utils/constants'
|
|
||||||
import {createUser, updateUser, getUser} from '~/services/auth'
|
|
||||||
import type {UserData, UserFormData} from '~/services/dto/user-data'
|
|
||||||
|
|
||||||
const route = useRoute()
|
|
||||||
const router = useRouter()
|
|
||||||
const userId = computed(() => resolveUserId(route.params.id))
|
|
||||||
const isLoading = ref(false)
|
|
||||||
const isHydrating = ref(false)
|
|
||||||
|
|
||||||
const resolveUserId = (param: unknown) => {
|
|
||||||
const idStr = Array.isArray(param) ? param[0] : param
|
|
||||||
if (!idStr) {
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
const id = Number(idStr)
|
|
||||||
return Number.isFinite(id) ? id : null
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
const form = reactive<UserFormData>({
|
|
||||||
username: '',
|
|
||||||
password: '',
|
|
||||||
role: ''
|
|
||||||
})
|
|
||||||
|
|
||||||
const hydrateFromUser = (user: UserData | null) => {
|
|
||||||
if (!user) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isHydrating.value = true
|
|
||||||
form.username = user.username ?? ''
|
|
||||||
const roles = user.roles ?? []
|
|
||||||
const hasAdmin = roles.includes("ROLE_ADMIN")
|
|
||||||
form.role = hasAdmin ? "ROLE_ADMIN" : "ROLE_USER"
|
|
||||||
form.password = ''
|
|
||||||
isHydrating.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => userId.value,
|
|
||||||
async (id) => {
|
|
||||||
if (id === null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isLoading.value = true
|
|
||||||
try {
|
|
||||||
const user = await getUser(id)
|
|
||||||
hydrateFromUser(user)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
async function validate() {
|
|
||||||
|
|
||||||
const normalizedUsername = form.username.trim()
|
|
||||||
const normalizedRole = form.role.trim()
|
|
||||||
const normalizedPassword = form.password.trim()
|
|
||||||
|
|
||||||
const basePayload = {
|
|
||||||
username: normalizedUsername,
|
|
||||||
roles: normalizedRole ? [normalizedRole] : undefined,
|
|
||||||
password: normalizedPassword || undefined
|
|
||||||
}
|
|
||||||
|
|
||||||
if (userId.value) {
|
|
||||||
await updateUser(userId.value, basePayload)
|
|
||||||
await router.push(`/admin/user/list/`)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const created = await createUser(basePayload)
|
|
||||||
if (created) {
|
|
||||||
await router.push(`/admin/user/list/`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -46,11 +46,7 @@
|
|||||||
"list": "Impossible de récupérer la liste des races de bovins."
|
"list": "Impossible de récupérer la liste des races de bovins."
|
||||||
},
|
},
|
||||||
"carrier": {
|
"carrier": {
|
||||||
"list": "Impossible de récupérer la liste des transporteurs.",
|
"list": "Impossible de récupérer la liste des transporteurs."
|
||||||
"fetch": "Impossible de récupérer les données du transporteur",
|
|
||||||
"update": "Impossible de mettre à jour le transporteur",
|
|
||||||
"create": "Impossible de créer le transporteur"
|
|
||||||
|
|
||||||
},
|
},
|
||||||
"driver": {
|
"driver": {
|
||||||
"list": "Impossible de récupérer la liste des chauffeurs."
|
"list": "Impossible de récupérer la liste des chauffeurs."
|
||||||
@@ -61,9 +57,7 @@
|
|||||||
"auth": {
|
"auth": {
|
||||||
"login": "Identifiants invalides.",
|
"login": "Identifiants invalides.",
|
||||||
"users": "Impossible de récupérer les utilisateurs.",
|
"users": "Impossible de récupérer les utilisateurs.",
|
||||||
"logout": "Impossible de se déconnecter.",
|
"logout": "Impossible de se déconnecter."
|
||||||
"update": "Impossible de mettre à jour l'utilisateur.",
|
|
||||||
"create": "Impossible de créer l'utilisateur."
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"success": {
|
"success": {
|
||||||
@@ -71,14 +65,8 @@
|
|||||||
"update": "Réception mise à jour avec succès."
|
"update": "Réception mise à jour avec succès."
|
||||||
},
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"update": "Utilisateur mis à jour avec succès.",
|
|
||||||
"create": "Utilisateur créé avec succès.",
|
|
||||||
"login": "Connexion réussie.",
|
"login": "Connexion réussie.",
|
||||||
"logout": "Déconnexion réussie."
|
"logout": "Déconnexion réussie."
|
||||||
},
|
|
||||||
"carrier": {
|
|
||||||
"update": "Transporteur mis à jour",
|
|
||||||
"create": "Transporteur créé"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,19 +21,16 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<div class="grid grid-cols-[16rem,1fr] h-[calc(100vh-85px)] min-h-0">
|
<div class="grid grid-cols-[16rem,1fr] h-[calc(100vh-85px)] min-h-0">
|
||||||
<aside class="bg-primary-500 text-white min-h-0 flex flex-col justify-between">
|
<aside class="bg-primary-500 text-white min-h-0 grid grid-rows-[auto,1fr,auto]">
|
||||||
<div class="flex flex-col gap-4 p-4 font-bold text-xl">
|
<div class="p-4 font-semibold">Tableau de bord</div>
|
||||||
|
|
||||||
|
<div class="overflow-y-auto min-h-0 p-4 space-y-3">
|
||||||
<!-- Liste des liens à ajouter ci-dessous -->
|
<!-- Liste des liens à ajouter ci-dessous -->
|
||||||
<NuxtLink to="/admin/dashboard">
|
<!--Button pour afficher le component admin-users -->
|
||||||
Tableau de bord
|
<NuxtLink
|
||||||
</NuxtLink>
|
to="/admin/user-list"
|
||||||
<NuxtLink to="/admin/supplier/supplier-list">
|
class="block px-4 py-2 rounded hover:bg-primary-600 transition"
|
||||||
Fournisseur
|
>
|
||||||
</NuxtLink>
|
|
||||||
<NuxtLink to="/admin/carrier/carrier-list">
|
|
||||||
Transporteur
|
|
||||||
</NuxtLink>
|
|
||||||
<NuxtLink to="/admin/user/list">
|
|
||||||
Utilisateurs
|
Utilisateurs
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
</div>
|
</div>
|
||||||
@@ -47,6 +44,7 @@
|
|||||||
Déconnexion
|
Déconnexion
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</aside>
|
</aside>
|
||||||
|
|
||||||
<main class="min-h-0 overflow-auto px-12 py-12 ">
|
<main class="min-h-0 overflow-auto px-12 py-12 ">
|
||||||
@@ -60,9 +58,8 @@
|
|||||||
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import {useAuthStore} from '~/stores/auth'
|
import auth from "~/layouts/auth.vue";
|
||||||
|
|
||||||
const auth = useAuthStore()
|
|
||||||
const { version } = useAppVersion()
|
const { version } = useAppVersion()
|
||||||
const handleLogout = async () => {
|
const handleLogout = async () => {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -20,10 +20,7 @@
|
|||||||
Accueil
|
Accueil
|
||||||
</a>
|
</a>
|
||||||
</NuxtLink>
|
</NuxtLink>
|
||||||
<NuxtLink
|
<NuxtLink to="/admin/dashboard" custom v-slot="{ href, navigate, isActive }">
|
||||||
to="/admin/dashboard" custom v-slot="{ href, navigate, isActive }"
|
|
||||||
v-if="auth.isAdmin"
|
|
||||||
>
|
|
||||||
<a
|
<a
|
||||||
:href="href"
|
:href="href"
|
||||||
@click="navigate"
|
@click="navigate"
|
||||||
|
|||||||
@@ -1,101 +0,0 @@
|
|||||||
|
|
||||||
<template>
|
|
||||||
<form @submit.prevent="validate">
|
|
||||||
<div class="flex items-center justify-between ">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">
|
|
||||||
{{ route.params.id ? 'Modifier transporteur' : 'Ajout transporteur' }}
|
|
||||||
</h1>
|
|
||||||
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] justify-self-end"
|
|
||||||
>Enregistrer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-16">
|
|
||||||
|
|
||||||
<UiTextInput
|
|
||||||
label = "nom du fournisseur"
|
|
||||||
id="carrier-name"
|
|
||||||
v-model="form.name"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<UiTextInput
|
|
||||||
label = "code fournisseur"
|
|
||||||
id="code-id"
|
|
||||||
v-model="form.code"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import {createCarrier, getCarrier, updateCarrier} from "~/services/carrier";
|
|
||||||
import type {CarrierData, CarrierFormData} from "~/services/dto/carrier-data";
|
|
||||||
const router = useRouter()
|
|
||||||
const route = useRoute()
|
|
||||||
const idCarrier = Number(route.params.id)
|
|
||||||
const isLoading = ref(false)
|
|
||||||
const isHydrating = ref(false)
|
|
||||||
|
|
||||||
const form = reactive<CarrierFormData>({
|
|
||||||
code:'',
|
|
||||||
name:''
|
|
||||||
})
|
|
||||||
|
|
||||||
definePageMeta({
|
|
||||||
layout: 'admin'
|
|
||||||
})
|
|
||||||
|
|
||||||
const hydrateFromUser = (carrier: CarrierData | null) => {
|
|
||||||
if (!carrier) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isHydrating.value = true
|
|
||||||
form.name = carrier.name ?? ''
|
|
||||||
form.code = carrier.code ?? ''
|
|
||||||
isHydrating.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => idCarrier,
|
|
||||||
async (id) => {
|
|
||||||
if (id === null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isLoading.value = true
|
|
||||||
try {
|
|
||||||
const user = await getCarrier(id)
|
|
||||||
hydrateFromUser(user)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
async function validate() {
|
|
||||||
|
|
||||||
const normalizedCarrierCode = form.code.trim()
|
|
||||||
const normalizedCarrierName = form.name.trim()
|
|
||||||
|
|
||||||
const basePayload = {
|
|
||||||
name: normalizedCarrierName,
|
|
||||||
code: normalizedCarrierCode
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if(idCarrier){
|
|
||||||
await updateCarrier(idCarrier, basePayload)
|
|
||||||
navigate()
|
|
||||||
return
|
|
||||||
}
|
|
||||||
await createCarrier(basePayload)
|
|
||||||
navigate()
|
|
||||||
}
|
|
||||||
|
|
||||||
function navigate(){
|
|
||||||
router.push("/admin/carrier/carrier-list")
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
<template>
|
|
||||||
|
|
||||||
<div class="flex items-center justify-between ">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">listes des transporteurs</h1>
|
|
||||||
<NuxtLink
|
|
||||||
to="/admin/carrier"
|
|
||||||
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
>Ajouter
|
|
||||||
</NuxtLink>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-6 border border-slate-200 mb-16 ">
|
|
||||||
<div class="grid grid-cols-2 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide">
|
|
||||||
<div>Label</div>
|
|
||||||
<div>Code</div>
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
v-for="carrier in carrierList"
|
|
||||||
:key="carrier.id"
|
|
||||||
class="grid grid-cols-2 gap-4 px-4 py-3 text-sm hover:bg-slate-50 cursor-pointer border-t border-slate-200"
|
|
||||||
role="button"
|
|
||||||
tabindex="0"
|
|
||||||
@click="goToCarrier(carrier.id)"
|
|
||||||
@keydown.enter="goToCarrier(carrier.id)"
|
|
||||||
>
|
|
||||||
<div>{{ carrier.name}}</div>
|
|
||||||
<div>{{ carrier.code }}</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import type {CarrierData} from "~/services/dto/carrier-data";
|
|
||||||
import {getCarrierList} from "~/services/carrier";
|
|
||||||
|
|
||||||
const carrierList = ref<CarrierData[]>()
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const goToCarrier = (id: number) => {
|
|
||||||
router.push(`/admin/carrier/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
definePageMeta({
|
|
||||||
layout: 'admin'
|
|
||||||
})
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
carrierList.value = await getCarrierList(false)
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,9 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<AdminUserForm/>
|
<admin-users v-if="activeCode === 'users'" />
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: 'admin'
|
layout: 'admin'
|
||||||
})
|
})
|
||||||
|
const route = useRoute()
|
||||||
|
|
||||||
|
const activeCode = computed(() => (route.query.code as string))
|
||||||
|
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<template>
|
|
||||||
<SupplierForm/>
|
|
||||||
</template>
|
|
||||||
<script setup lang="ts">
|
|
||||||
definePageMeta({
|
|
||||||
layout: 'admin'
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,97 +0,0 @@
|
|||||||
<template>
|
|
||||||
<div class="flex items-center justify-between">
|
|
||||||
<h1 class="text-3xl font-bold uppercase">Fournisseurs</h1>
|
|
||||||
<NuxtLink
|
|
||||||
to="/admin/supplier"
|
|
||||||
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
|
||||||
>
|
|
||||||
Ajouter
|
|
||||||
</NuxtLink>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="mt-6 border border-slate-200 mb-16">
|
|
||||||
<div class="max-h-96 overflow-y-auto">
|
|
||||||
<div
|
|
||||||
class="sticky top-0 z-10 grid grid-cols-7 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide"
|
|
||||||
>
|
|
||||||
<div>Nom</div>
|
|
||||||
<div>Mail</div>
|
|
||||||
<div>Rue</div>
|
|
||||||
<div>Complément</div>
|
|
||||||
<div>Code Postal</div>
|
|
||||||
<div>Ville</div>
|
|
||||||
<div>Pays</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-if="supplierList.length === 0" class="px-4 py-6 text-slate-400">
|
|
||||||
Aucun fournisseur.
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div v-for="supplier in supplierList" :key="supplier.id">
|
|
||||||
<div
|
|
||||||
v-if="!supplier.addresses || supplier.addresses.length === 0"
|
|
||||||
class="grid grid-cols-7 border-t gap-4 px-4 py-2 text-slate-400"
|
|
||||||
>
|
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="col-span-5">—</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<template v-else-if="isAddressObjectArray(supplier.addresses)">
|
|
||||||
<div
|
|
||||||
v-for="(address, idx) in supplier.addresses"
|
|
||||||
:key="address.id ?? `${supplier.id}-${idx}-${address.street}-${address.postalCode}`"
|
|
||||||
class="grid grid-cols-7 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
|
||||||
@click="goToSupplier(supplier.id)"
|
|
||||||
>
|
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="truncate">{{ address.street }}</div>
|
|
||||||
<div class="truncate">{{ address.street2 }}</div>
|
|
||||||
<div>{{ address.postalCode }}</div>
|
|
||||||
<div class="uppercase truncate">{{ address.city }}</div>
|
|
||||||
<div class="uppercase truncate">{{ address.countryCode }}</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<template v-else>
|
|
||||||
<div
|
|
||||||
class="grid grid-cols-7 hover:bg-slate-50 border-t gap-4 px-4 py-2 cursor-pointer"
|
|
||||||
@click="goToSupplier(supplier.id)"
|
|
||||||
>
|
|
||||||
<div class="truncate">{{ supplier.name }}</div>
|
|
||||||
<div class="truncate">{{ supplier.email }}</div>
|
|
||||||
<div class="col-span-5 text-slate-400">
|
|
||||||
Adresses non chargées (IRIs)
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import { getSupplierList } from "~/services/supplier"
|
|
||||||
import type { SupplierData } from "~/services/dto/supplier-data"
|
|
||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
|
||||||
|
|
||||||
definePageMeta({ layout: "admin" })
|
|
||||||
|
|
||||||
const supplierList = ref<SupplierData[]>([])
|
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const goToSupplier = (id: number) => {
|
|
||||||
router.push(`/admin/supplier/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
function isAddressObjectArray(value: SupplierData["addresses"]): value is AddressFormData[] {
|
|
||||||
if (!Array.isArray(value) || value.length === 0) return false
|
|
||||||
const v0 = value[0]
|
|
||||||
return typeof v0 === "object" && v0 !== null && "street" in v0 && "postalCode" in v0
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
supplierList.value = await getSupplierList()
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -1,13 +1,12 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="flex items-center justify-between">
|
<div class="flex items-center justify-between gap-10">
|
||||||
<h1 class="text-3xl font-bold uppercase">Liste des utilisateurs</h1>
|
<h1 class="text-3xl font-bold uppercase">Utilisateurs</h1>
|
||||||
<NuxtLink
|
<button
|
||||||
class="flex items-center justify-center text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
@click="router.push('/admin/user/')"
|
@click="null"
|
||||||
>
|
>
|
||||||
Ajouter
|
Ajouter
|
||||||
</NuxtLink>
|
</button>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
@@ -15,14 +14,14 @@
|
|||||||
<div class="grid grid-cols-3 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide">
|
<div class="grid grid-cols-3 gap-4 bg-slate-100 px-4 py-3 text-sm font-semibold uppercase tracking-wide">
|
||||||
<div>Username</div>
|
<div>Username</div>
|
||||||
<div>Role</div>
|
<div>Role</div>
|
||||||
|
<div>Action</div>
|
||||||
</div>
|
</div>
|
||||||
<div
|
<div
|
||||||
v-for="user in userList"
|
v-for="user in userList"
|
||||||
:key="user.id"
|
:key="user.id"
|
||||||
class="grid grid-cols-3 gap-4 px-4 py-3 text-sm hover:bg-slate-50 cursor-pointer border-t items-center"
|
class="grid grid-cols-3 gap-4 px-4 py-3 text-sm hover:bg-slate-50 cursor-pointer border-t border-slate-200 items-center"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
@click="goToUser(user.id)"
|
|
||||||
>
|
>
|
||||||
<div>
|
<div>
|
||||||
{{ user.username}}
|
{{ user.username}}
|
||||||
@@ -30,28 +29,36 @@
|
|||||||
<div>
|
<div>
|
||||||
{{ user.roles?.join(', ') || ' ---' }}
|
{{ user.roles?.join(', ') || ' ---' }}
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<div class="p-4">
|
||||||
|
<button
|
||||||
|
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px]"
|
||||||
|
@click="null"
|
||||||
|
>
|
||||||
|
Modifier
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
layout: 'admin'
|
layout: 'admin'
|
||||||
})
|
})
|
||||||
|
|
||||||
import type {UserData} from "~/services/dto/user-data";
|
import type {UserData} from "~/services/dto/user-data";
|
||||||
import {getAdminUsers, getUsers} from "~/services/auth";
|
import {getUsers} from "~/services/auth";
|
||||||
|
|
||||||
const userList = ref<UserData[]>([])
|
const userList = ref<UserData[]>([])
|
||||||
const router = useRouter()
|
|
||||||
|
|
||||||
const goToUser = (id: number) => {
|
|
||||||
router.push(`/admin/user/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
userList.value = await getAdminUsers()
|
userList.value = await getUsers()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<template>
|
|
||||||
<UserForm/>
|
|
||||||
</template>
|
|
||||||
<script setup lang="ts">
|
|
||||||
definePageMeta({
|
|
||||||
layout: 'admin'
|
|
||||||
})
|
|
||||||
</script>
|
|
||||||
@@ -20,7 +20,6 @@
|
|||||||
class="grid grid-cols-6 gap-4 px-4 py-3 text-sm hover:bg-slate-50 cursor-pointer border-t border-slate-200"
|
class="grid grid-cols-6 gap-4 px-4 py-3 text-sm hover:bg-slate-50 cursor-pointer border-t border-slate-200"
|
||||||
role="button"
|
role="button"
|
||||||
tabindex="0"
|
tabindex="0"
|
||||||
@click="goToReception(reception.id)"
|
|
||||||
>
|
>
|
||||||
<div>{{ reception.identificationNumber}}</div>
|
<div>{{ reception.identificationNumber}}</div>
|
||||||
<div>{{ reception.receptionDate}}</div>
|
<div>{{ reception.receptionDate}}</div>
|
||||||
@@ -48,10 +47,6 @@ const formatWeighing = (reception: ReceptionData, type: 'gross' | 'tare') => {
|
|||||||
return `${entry.weight} kg`
|
return `${entry.weight} kg`
|
||||||
}
|
}
|
||||||
|
|
||||||
const goToReception = (id: number) => {
|
|
||||||
router.push(`/reception/update/${id}`)
|
|
||||||
}
|
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
receptionList.value = await getReceptionList(true)
|
receptionList.value = await getReceptionList(true)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,518 +0,0 @@
|
|||||||
<template>
|
|
||||||
|
|
||||||
<form @submit.prevent="validate">
|
|
||||||
<div class="flex items-center justify-between mt-8 mb-8 ">
|
|
||||||
<h1 class="font-bold text-5xl uppercase">Réception {{receptionLoad?.identificationNumber}}</h1>
|
|
||||||
<button
|
|
||||||
type="submit"
|
|
||||||
class="text-xl uppercase bg-primary-500 text-white h-[50px] w-[272px] justify-self-end"
|
|
||||||
>Enregistrer
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
<div class="grid grid-cols-2 items-start gap-y-8 gap-x-40 mb-16">
|
|
||||||
<!-- Nom de l'utilisateur -->
|
|
||||||
<UiSelect
|
|
||||||
id="reception-user"
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
v-model="form.userId"
|
|
||||||
label="Nom de l'utilisateur"
|
|
||||||
:options="users.map((user) => ({
|
|
||||||
value: String(user.id),
|
|
||||||
label: user.username
|
|
||||||
}))"
|
|
||||||
:loading="isLoadingUsers"
|
|
||||||
wrapper-class="col-start-1 row-start-1"
|
|
||||||
/>
|
|
||||||
<!-- Date de réception -->
|
|
||||||
<UiDateInput
|
|
||||||
id="reception-date"
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
v-model="form.receptionDate"
|
|
||||||
label="Date de réception"
|
|
||||||
wrapper-class="col-start-1 row-start-2"
|
|
||||||
/>
|
|
||||||
<!-- Fournisseur -->
|
|
||||||
<UiSelect
|
|
||||||
id="reception-supplier"
|
|
||||||
v-model="form.supplierId"
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
label="Fournisseur"
|
|
||||||
:options="suppliers.map((supplier) => ({
|
|
||||||
value: String(supplier.id),
|
|
||||||
label: supplier.name
|
|
||||||
}))"
|
|
||||||
:loading="isLoadingSuppliers"
|
|
||||||
wrapper-class="col-start-1 row-start-3"
|
|
||||||
/>
|
|
||||||
<!-- Adresse fournisseur -->
|
|
||||||
<UiSelect
|
|
||||||
id="reception-address"
|
|
||||||
v-model="form.addressId"
|
|
||||||
label="Adresse"
|
|
||||||
:options="supplierAddresses.map((address) => ({
|
|
||||||
value: String(address.id),
|
|
||||||
label: address.fullAddress
|
|
||||||
}))"
|
|
||||||
:disabled="(isLoadingSuppliers || supplierAddresses.length === 0) && !auth.isAdmin"
|
|
||||||
wrapper-class="col-start-1 row-start-4"
|
|
||||||
/>
|
|
||||||
<!-- Camion -->
|
|
||||||
<UiSelect
|
|
||||||
id="reception-truck"
|
|
||||||
v-model="form.truckId"
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
label="Camion"
|
|
||||||
:options="trucks.map((truck) => ({
|
|
||||||
value: String(truck.id),
|
|
||||||
label: truck.name
|
|
||||||
}))"
|
|
||||||
:loading="isLoadingTrucks"
|
|
||||||
wrapper-class="col-start-2 row-start-1"
|
|
||||||
/>
|
|
||||||
<!-- Transporteur -->
|
|
||||||
<UiSelect
|
|
||||||
id="reception-carrier"
|
|
||||||
v-model="form.carrierId"
|
|
||||||
label="Transporteur"
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
:options="carriers.map((carrier) => ({
|
|
||||||
value: String(carrier.id),
|
|
||||||
label: carrier.name
|
|
||||||
}))"
|
|
||||||
:loading="isLoadingCarriers"
|
|
||||||
select-class="h-[34px]"
|
|
||||||
wrapper-class="col-start-2 row-start-2"
|
|
||||||
/>
|
|
||||||
<!-- Chauffeur (LIOT) -->
|
|
||||||
<UiSelect
|
|
||||||
id="reception-driver"
|
|
||||||
v-model="form.driverId"
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
label="Nom du chauffeur si LIOT"
|
|
||||||
:options="filteredDrivers.map((driver) => ({
|
|
||||||
value: String(driver.id),
|
|
||||||
label: driver.name
|
|
||||||
}))"
|
|
||||||
:loading="isLoadingDrivers"
|
|
||||||
wrapper-class="col-start-2 row-start-3"
|
|
||||||
/>
|
|
||||||
<!-- Plaque d'immatriculation -->
|
|
||||||
<div v-if="!isLiotCarrier" class="col-start-2 row-start-4">
|
|
||||||
<UiLicensePlateInput
|
|
||||||
:disabled="!auth.isAdmin"
|
|
||||||
v-model="form.licensePlate"
|
|
||||||
v-model:allowAny="allowAnyLicensePlate"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
<!-- Immatriculation (LIOT) -->
|
|
||||||
<UiSelect
|
|
||||||
v-if="isLiotCarrier"
|
|
||||||
id="reception-vehicle"
|
|
||||||
v-model="form.vehicleId"
|
|
||||||
label="Immatriculation"
|
|
||||||
:options="filteredVehicles.map((vehicle) => ({
|
|
||||||
value: String(vehicle.id),
|
|
||||||
label: vehicle.plate
|
|
||||||
}))"
|
|
||||||
:loading="isLoadingVehicles"
|
|
||||||
:disabled="(isLoadingVehicles || filteredVehicles.length === 0) && !auth.isAdmin"
|
|
||||||
wrapper-class="col-start-2 row-start-4"
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script setup lang="ts">
|
|
||||||
import {useReceptionStore} from '~/stores/reception'
|
|
||||||
import type {UserData} from '~/services/dto/user-data'
|
|
||||||
import {getUsers} from '~/services/auth'
|
|
||||||
import {useAuthStore} from '~/stores/auth'
|
|
||||||
import type {SupplierData} from '~/services/dto/supplier-data'
|
|
||||||
import {getSupplierList} from '~/services/supplier'
|
|
||||||
import type {TruckData} from '~/services/dto/truck-data'
|
|
||||||
import {getTruckList} from '~/services/truck'
|
|
||||||
import type {CarrierData} from '~/services/dto/carrier-data'
|
|
||||||
import {getCarrierList} from '~/services/carrier'
|
|
||||||
import type {DriverData} from '~/services/dto/driver-data'
|
|
||||||
import {getDriverList} from '~/services/driver'
|
|
||||||
import type {VehicleData} from '~/services/dto/vehicle-data'
|
|
||||||
import {getVehicleList} from '~/services/vehicle'
|
|
||||||
import {SUPLLIER_CODE} from "~/utils/constants";
|
|
||||||
import {deleteReceptionBovine, getReceptionBovineList} from "~/services/reception-bovine";
|
|
||||||
import type {ReceptionData, ReceptionFormData} from "~/services/dto/reception-data";
|
|
||||||
import {getReception} from "~/services/reception";
|
|
||||||
|
|
||||||
const router = useRouter()
|
|
||||||
const receptionStore = useReceptionStore()
|
|
||||||
const form = reactive<ReceptionFormData>({
|
|
||||||
licensePlate: '',
|
|
||||||
receptionDate: new Date().toISOString().slice(0, 10),
|
|
||||||
receptionTypeId: '',
|
|
||||||
userId: '',
|
|
||||||
supplierId: '',
|
|
||||||
addressId: '',
|
|
||||||
truckId: '',
|
|
||||||
carrierId: '',
|
|
||||||
driverId: '',
|
|
||||||
vehicleId: ''
|
|
||||||
})
|
|
||||||
const allowAnyLicensePlate = ref(false)
|
|
||||||
const isLoading = ref(false)
|
|
||||||
const users = ref<UserData[]>([])
|
|
||||||
const isLoadingUsers = ref(false)
|
|
||||||
const suppliers = ref<SupplierData[]>([])
|
|
||||||
const isLoadingSuppliers = ref(false)
|
|
||||||
const trucks = ref<TruckData[]>([])
|
|
||||||
const isLoadingTrucks = ref(false)
|
|
||||||
const carriers = ref<CarrierData[]>([])
|
|
||||||
const isLoadingCarriers = ref(false)
|
|
||||||
const drivers = ref<DriverData[]>([])
|
|
||||||
const isLoadingDrivers = ref(false)
|
|
||||||
const vehicles = ref<VehicleData[]>([])
|
|
||||||
const isLoadingVehicles = ref(false)
|
|
||||||
const authStore = useAuthStore()
|
|
||||||
|
|
||||||
// Empêche les watchers de reset des champs pendant le remplissage initial
|
|
||||||
const isHydrating = ref(false)
|
|
||||||
const route = useRoute()
|
|
||||||
const idReception = Number(route.params.id)
|
|
||||||
const receptionLoad = await getReception(idReception)
|
|
||||||
const receptionType = receptionLoad.receptionType
|
|
||||||
const auth = useAuthStore()
|
|
||||||
|
|
||||||
// Transporteur sélectionné dans le formulaire
|
|
||||||
const selectedCarrier = computed(() =>
|
|
||||||
carriers.value.find((carrier) => String(carrier.id) === form.carrierId) ?? null
|
|
||||||
)
|
|
||||||
// Indique si le transporteur est LIOT
|
|
||||||
const isLiotCarrier = computed(() => selectedCarrier.value?.code === SUPLLIER_CODE.LIOT)
|
|
||||||
// Adresses disponibles pour le fournisseur sélectionné
|
|
||||||
const supplierAddresses = computed(() => {
|
|
||||||
const supplierId = Number(form.supplierId)
|
|
||||||
if (!Number.isFinite(supplierId)) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
return suppliers.value.find((supplier) => supplier.id === supplierId)?.addresses ?? []
|
|
||||||
})
|
|
||||||
// Chauffeurs filtrés par transporteur (LIOT)
|
|
||||||
const filteredDrivers = computed<DriverData[]>(() => {
|
|
||||||
if (!form.carrierId) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
return drivers.value.filter((driver) => String(driver.carrier?.id) === form.carrierId)
|
|
||||||
})
|
|
||||||
// Véhicules filtrés par transporteur + type de camion
|
|
||||||
const filteredVehicles = computed<VehicleData[]>(() => {
|
|
||||||
if (!form.carrierId) {
|
|
||||||
return []
|
|
||||||
}
|
|
||||||
return vehicles.value.filter(
|
|
||||||
(vehicle) =>
|
|
||||||
String(vehicle.carrier?.id) === form.carrierId &&
|
|
||||||
(!form.truckId || String(vehicle.truck?.id) === form.truckId)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
// Supprime les données bovines si on change de type de réception
|
|
||||||
const clearReceptionBovines = async (receptionIri: string) => {
|
|
||||||
const existing = await getReceptionBovineList(receptionIri)
|
|
||||||
for (const selection of existing) {
|
|
||||||
await deleteReceptionBovine(selection.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const hydrateFromUser = (reception: ReceptionData | null)=> {
|
|
||||||
if (!reception) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isHydrating.value = true
|
|
||||||
form.licensePlate = reception?.licensePlate ?? ''
|
|
||||||
form.receptionDate = reception?.receptionDate ?? new Date().toISOString().slice(0, 10)
|
|
||||||
form.userId = reception?.user?.id
|
|
||||||
? String(reception.user.id)
|
|
||||||
: form.userId
|
|
||||||
form.supplierId = reception?.supplier?.id
|
|
||||||
? String(reception.supplier.id)
|
|
||||||
: ''
|
|
||||||
form.addressId = reception?.address?.id
|
|
||||||
? String(reception.address.id)
|
|
||||||
: ''
|
|
||||||
form.truckId = reception?.truck?.id
|
|
||||||
? String(reception.truck.id)
|
|
||||||
: ''
|
|
||||||
form.carrierId = reception?.carrier?.id
|
|
||||||
? String(reception.carrier.id)
|
|
||||||
: ''
|
|
||||||
form.driverId = reception?.driver?.id
|
|
||||||
? String(reception.driver.id)
|
|
||||||
: ''
|
|
||||||
isHydrating.value = false
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => idReception,
|
|
||||||
async (id) => {
|
|
||||||
if (id === null) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
isLoading.value = true
|
|
||||||
try {
|
|
||||||
const user = await getReception(id)
|
|
||||||
hydrateFromUser(user)
|
|
||||||
} finally {
|
|
||||||
isLoading.value = false
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Charge la liste des users pour le select
|
|
||||||
const loadUsers = async () => {
|
|
||||||
isLoadingUsers.value = true
|
|
||||||
try {
|
|
||||||
users.value = await getUsers()
|
|
||||||
} finally {
|
|
||||||
isLoadingUsers.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charge la liste des fournisseurs pour le select
|
|
||||||
const loadSuppliers = async () => {
|
|
||||||
isLoadingSuppliers.value = true
|
|
||||||
try {
|
|
||||||
suppliers.value = await getSupplierList()
|
|
||||||
} finally {
|
|
||||||
isLoadingSuppliers.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charge la liste des camions pour le select
|
|
||||||
const loadTrucks = async () => {
|
|
||||||
isLoadingTrucks.value = true
|
|
||||||
try {
|
|
||||||
trucks.value = await getTruckList()
|
|
||||||
} finally {
|
|
||||||
isLoadingTrucks.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charge la liste des transporteurs pour le select
|
|
||||||
const loadCarriers = async () => {
|
|
||||||
isLoadingCarriers.value = true
|
|
||||||
try {
|
|
||||||
carriers.value = await getCarrierList()
|
|
||||||
} finally {
|
|
||||||
isLoadingCarriers.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charge la liste des chauffeurs pour le select
|
|
||||||
const loadDrivers = async () => {
|
|
||||||
isLoadingDrivers.value = true
|
|
||||||
try {
|
|
||||||
drivers.value = await getDriverList()
|
|
||||||
} finally {
|
|
||||||
isLoadingDrivers.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Charge la liste des véhicules pour le select
|
|
||||||
const loadVehicles = async () => {
|
|
||||||
isLoadingVehicles.value = true
|
|
||||||
try {
|
|
||||||
vehicles.value = await getVehicleList()
|
|
||||||
} finally {
|
|
||||||
isLoadingVehicles.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// On met le user connecté par défaut dans le select
|
|
||||||
const setDefaultUser = () => {
|
|
||||||
if (form.userId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (authStore.user?.id) {
|
|
||||||
form.userId = String(authStore.user.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// On récupère toutes les données des selects au chargement du composant
|
|
||||||
onMounted(async () => {
|
|
||||||
await loadUsers()
|
|
||||||
await loadSuppliers()
|
|
||||||
await loadTrucks()
|
|
||||||
await loadCarriers()
|
|
||||||
await loadDrivers()
|
|
||||||
await loadVehicles()
|
|
||||||
await authStore.ensureSession()
|
|
||||||
setDefaultUser()
|
|
||||||
})
|
|
||||||
|
|
||||||
// Ajuste driver/vehicle quand le transporteur change (logique LIOT)
|
|
||||||
watch(
|
|
||||||
() => [form.supplierId, suppliers.value],
|
|
||||||
() => {
|
|
||||||
if (!form.supplierId) {
|
|
||||||
form.addressId = ''
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!form.addressId && supplierAddresses.value.length === 1) {
|
|
||||||
form.addressId = String(supplierAddresses.value[0].id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!form.addressId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const matches = supplierAddresses.value.some(
|
|
||||||
(address) => String(address.id) === form.addressId
|
|
||||||
)
|
|
||||||
if (!matches) {
|
|
||||||
form.addressId = ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Valide/auto-sélectionne le véhicule selon camion + transporteur (LIOT)
|
|
||||||
watch(
|
|
||||||
() => form.carrierId,
|
|
||||||
() => {
|
|
||||||
if (isHydrating.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!form.carrierId && idReception == null) {
|
|
||||||
form.driverId = ''
|
|
||||||
form.vehicleId = ''
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!isLiotCarrier.value && idReception == null) {
|
|
||||||
form.driverId = ''
|
|
||||||
form.vehicleId = ''
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (filteredDrivers.value.length === 1) {
|
|
||||||
form.driverId = String(filteredDrivers.value[0].id)
|
|
||||||
}
|
|
||||||
if (filteredVehicles.value.length === 1) {
|
|
||||||
form.vehicleId = String(filteredVehicles.value[0].id)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Récupère la plaque depuis le véhicule choisi (LIOT)
|
|
||||||
watch(
|
|
||||||
() => [form.truckId, form.carrierId, vehicles.value],
|
|
||||||
() => {
|
|
||||||
if (!isLiotCarrier.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (filteredVehicles.value.length === 1) {
|
|
||||||
form.vehicleId = String(filteredVehicles.value[0].id)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!form.vehicleId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const matches = filteredVehicles.value.some(
|
|
||||||
(vehicle) => String(vehicle.id) === form.vehicleId
|
|
||||||
)
|
|
||||||
if (!matches) {
|
|
||||||
form.vehicleId = ''
|
|
||||||
}
|
|
||||||
},
|
|
||||||
{immediate: true}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Auto-renseigne le véhicule si la plaque correspond (LIOT)
|
|
||||||
watch(
|
|
||||||
() => [form.vehicleId, form.carrierId, vehicles.value],
|
|
||||||
() => {
|
|
||||||
if (!isLiotCarrier.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (isHydrating.value) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const selected = filteredVehicles.value.find(
|
|
||||||
(vehicle) => String(vehicle.id) === form.vehicleId
|
|
||||||
)
|
|
||||||
if (selected) {
|
|
||||||
form.licensePlate = selected.plate
|
|
||||||
allowAnyLicensePlate.value = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
watch(
|
|
||||||
() => [form.licensePlate, form.carrierId, vehicles.value],
|
|
||||||
() => {
|
|
||||||
if (!isLiotCarrier.value || form.vehicleId) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
const match = filteredVehicles.value.find(
|
|
||||||
(vehicle) => vehicle.plate === form.licensePlate
|
|
||||||
)
|
|
||||||
if (match) {
|
|
||||||
form.vehicleId = String(match.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
// Valide le formulaire et crée/met à jour la réception
|
|
||||||
async function validate() {
|
|
||||||
const normalizedLicensePlate = form.licensePlate.trim()
|
|
||||||
const normalizedReceptionDate = form.receptionDate.trim()
|
|
||||||
const normalizedUserId = form.userId.trim()
|
|
||||||
const normalizedSupplierId = form.supplierId.trim()
|
|
||||||
const normalizedAddressId = form.addressId.trim()
|
|
||||||
const normalizedTruckId = form.truckId.trim()
|
|
||||||
const normalizedCarrierId = form.carrierId.trim()
|
|
||||||
const normalizedDriverId = form.driverId.trim()
|
|
||||||
const userIri = normalizedUserId
|
|
||||||
? `/api/users/${normalizedUserId}`
|
|
||||||
: null
|
|
||||||
const supplierIri = normalizedSupplierId
|
|
||||||
? `/api/suppliers/${normalizedSupplierId}`
|
|
||||||
: null
|
|
||||||
const addressIri = normalizedAddressId
|
|
||||||
? `/api/addresses/${normalizedAddressId}`
|
|
||||||
: null
|
|
||||||
const truckIri = normalizedTruckId
|
|
||||||
? `/api/trucks/${normalizedTruckId}`
|
|
||||||
: null
|
|
||||||
const carrierIri = normalizedCarrierId
|
|
||||||
? `/api/carriers/${normalizedCarrierId}`
|
|
||||||
: null
|
|
||||||
const driverIri = normalizedDriverId
|
|
||||||
? `/api/drivers/${normalizedDriverId}`
|
|
||||||
: null
|
|
||||||
|
|
||||||
const basePayload = {
|
|
||||||
licensePlate: normalizedLicensePlate,
|
|
||||||
receptionDate: normalizedReceptionDate,
|
|
||||||
user: userIri,
|
|
||||||
supplier: supplierIri,
|
|
||||||
address: addressIri,
|
|
||||||
truck: truckIri,
|
|
||||||
carrier: carrierIri
|
|
||||||
}
|
|
||||||
|
|
||||||
const payload = {
|
|
||||||
...basePayload,
|
|
||||||
...(isLiotCarrier.value && driverIri ? {driver: driverIri} : {})
|
|
||||||
}
|
|
||||||
|
|
||||||
if (idReception) {
|
|
||||||
const updated = await receptionStore.updateReception(idReception,{
|
|
||||||
...payload
|
|
||||||
})
|
|
||||||
if (updated) {
|
|
||||||
await router.push(`/reception/update/${updated.id}`)
|
|
||||||
}
|
|
||||||
router.push("/reception/finish-reception")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
</script>
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
import { useApi } from '~/composables/useApi'
|
|
||||||
import type { AddressData } from '~/services/dto/address-data'
|
|
||||||
export interface AddressPayload {
|
|
||||||
label: string
|
|
||||||
street: string
|
|
||||||
street2?: string | null
|
|
||||||
postalCode: string
|
|
||||||
city: string
|
|
||||||
countryCode: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface AddressData extends AddressPayload {
|
|
||||||
id: number
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createAddress(
|
|
||||||
payload: AddressPayload
|
|
||||||
): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.post<AddressData>('addresses', payload, {
|
|
||||||
toastErrorKey: 'errors.address.create',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateAddress(
|
|
||||||
id: number,
|
|
||||||
payload: AddressPayload
|
|
||||||
): Promise<AddressData> {
|
|
||||||
const api = useApi()
|
|
||||||
|
|
||||||
return await api.patch<AddressData>(`addresses/${id}`, payload, {
|
|
||||||
toastErrorKey: 'errors.address.update',
|
|
||||||
})
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
import { useApi } from '~/composables/useApi'
|
import { useApi } from '~/composables/useApi'
|
||||||
import type { UserData } from '~/services/dto/user-data'
|
import type { UserData } from '~/services/dto/user-data'
|
||||||
import type {UserPayload} from "~/services/dto/user-data";
|
|
||||||
|
|
||||||
export async function getUsers() {
|
export async function getUsers() {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
@@ -13,40 +12,7 @@ export async function getUsers() {
|
|||||||
|
|
||||||
return data['hydra:member'] ?? []
|
return data['hydra:member'] ?? []
|
||||||
}
|
}
|
||||||
export async function getAdminUsers() {
|
|
||||||
const api = useApi()
|
|
||||||
const data = await api.get<UserData[] | { 'hydra:member': UserData[] }>('admin/users', {}, {
|
|
||||||
toastErrorKey: 'errors.auth.users'
|
|
||||||
})
|
|
||||||
if (Array.isArray(data)) {
|
|
||||||
return data
|
|
||||||
}
|
|
||||||
|
|
||||||
return data['hydra:member'] ?? []
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function getUser(id: number) {
|
|
||||||
const api = useApi()
|
|
||||||
return api.get<UserData>(`users/${id}`, {}, {
|
|
||||||
toastErrorKey: 'errors.auth.user'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createUser(payload: UserPayload = {}) {
|
|
||||||
const api = useApi()
|
|
||||||
return api.post<UserData>('users', payload, {
|
|
||||||
toastErrorKey: 'errors.auth.create',
|
|
||||||
toastSuccessKey : 'success.auth.create'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateUser(id : number, playload: UserPayload = {}){
|
|
||||||
const api = useApi()
|
|
||||||
return api.patch<UserData>(`users/${id}`, playload, {
|
|
||||||
toastErrorKey: 'errors.auth.update',
|
|
||||||
toastSuccessKey: 'success.auth.update'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
export async function getCurrentUser() {
|
export async function getCurrentUser() {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
return api.get<UserData>('me', {}, {
|
return api.get<UserData>('me', {}, {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useApi } from '~/composables/useApi'
|
import { useApi } from '~/composables/useApi'
|
||||||
import type {CarrierData, CarrierPayload} from "~/services/dto/carrier-data";
|
import type { CarrierData } from '~/services/dto/carrier-data'
|
||||||
|
|
||||||
export type CarrierListResponse =
|
export type CarrierListResponse =
|
||||||
| CarrierData[]
|
| CarrierData[]
|
||||||
@@ -21,26 +21,3 @@ export async function getCarrierList(): Promise<CarrierData[]> {
|
|||||||
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getCarrier(id: number) {
|
|
||||||
const api = useApi()
|
|
||||||
return api.get<CarrierData>(`carriers/${id}`, {}, {
|
|
||||||
toastErrorKey: 'errors.carrier.fetch'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateCarrier(id: number, payload: CarrierPayload) {
|
|
||||||
const api = useApi()
|
|
||||||
return api.patch<CarrierData>(`carriers/${id}`, payload, {
|
|
||||||
toastErrorKey: 'errors.carrier.update',
|
|
||||||
toastSuccessKey: 'success.carrier.update'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createCarrier(payload: CarrierPayload = {}) {
|
|
||||||
const api = useApi()
|
|
||||||
return api.post<CarrierData>('carriers', payload, {
|
|
||||||
toastErrorKey: 'errors.carrier.create',
|
|
||||||
toastSuccessKey: 'success.carrier.update'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,14 +6,5 @@ export interface AddressData {
|
|||||||
postalCode: string
|
postalCode: string
|
||||||
city: string
|
city: string
|
||||||
countryCode: string
|
countryCode: string
|
||||||
}
|
fullAddress?: string
|
||||||
|
|
||||||
export interface AddressFormData {
|
|
||||||
id?: number | null
|
|
||||||
label: string
|
|
||||||
street: string
|
|
||||||
street2?: string | null
|
|
||||||
postalCode: string
|
|
||||||
city: string
|
|
||||||
countryCode: string
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,13 +3,3 @@ export interface CarrierData {
|
|||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CarrierFormData {
|
|
||||||
name: string
|
|
||||||
code: string
|
|
||||||
}
|
|
||||||
|
|
||||||
export type CarrierPayload = {
|
|
||||||
name?: string | null
|
|
||||||
code?: string
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -59,16 +59,3 @@ export type ReceptionPayload = {
|
|||||||
carrier?: string | null
|
carrier?: string | null
|
||||||
driver?: string | null
|
driver?: string | null
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ReceptionFormData = {
|
|
||||||
licensePlate: string
|
|
||||||
receptionDate: string
|
|
||||||
receptionTypeId: string
|
|
||||||
userId: string
|
|
||||||
supplierId: string
|
|
||||||
addressId: string
|
|
||||||
truckId: string
|
|
||||||
carrierId: string
|
|
||||||
driverId: string
|
|
||||||
vehicleId: string
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,25 +1,9 @@
|
|||||||
import type { AddressFormData } from "~/services/dto/address-data"
|
import type { AddressData } from '~/services/dto/address-data'
|
||||||
|
|
||||||
export type SupplierAddresses = AddressFormData[] | string[]
|
|
||||||
|
|
||||||
export interface SupplierData {
|
export interface SupplierData {
|
||||||
id: number
|
id: number
|
||||||
name: string
|
name: string
|
||||||
email?: string | null
|
email?: string | null
|
||||||
phone?: string | null
|
phone?: string | null
|
||||||
addresses: SupplierAddresses
|
addresses?: AddressData[] | null
|
||||||
}
|
|
||||||
|
|
||||||
export interface SupplierFormData {
|
|
||||||
name: string
|
|
||||||
email?: string
|
|
||||||
phone?: string
|
|
||||||
addresses: AddressFormData[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type SupplierPayload = {
|
|
||||||
name: string
|
|
||||||
email?: string | null
|
|
||||||
phone?: string | null
|
|
||||||
addresses: string[]
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,5 @@
|
|||||||
export interface UserData {
|
export interface UserData {
|
||||||
id: number
|
id: number
|
||||||
username: string
|
username: string
|
||||||
roles: string[]
|
|
||||||
}
|
|
||||||
|
|
||||||
export type UserPayload = {
|
|
||||||
username?: string
|
|
||||||
password?: string
|
|
||||||
roles?: string[]
|
roles?: string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export type UserFormData = {
|
|
||||||
username: string
|
|
||||||
password: string
|
|
||||||
role: string
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,42 +1,23 @@
|
|||||||
import { useApi } from "~/composables/useApi"
|
import { useApi } from '~/composables/useApi'
|
||||||
import type { SupplierData, SupplierPayload } from "~/services/dto/supplier-data"
|
import type { SupplierData } from '~/services/dto/supplier-data'
|
||||||
|
|
||||||
export type SupplierListResponse =
|
export type SupplierListResponse =
|
||||||
| SupplierData[]
|
| SupplierData[]
|
||||||
| { "hydra:member"?: SupplierData[] }
|
| { 'hydra:member'?: SupplierData[] }
|
||||||
|
|
||||||
export async function getSupplierList(): Promise<SupplierData[]> {
|
export async function getSupplierList(): Promise<SupplierData[]> {
|
||||||
const api = useApi()
|
const api = useApi()
|
||||||
const response = await api.get<SupplierListResponse>("suppliers", {}, {
|
const response = await api.get<SupplierListResponse>('suppliers', {}, {
|
||||||
toastErrorKey: "errors.supplier.list",
|
toastErrorKey: 'errors.supplier.list'
|
||||||
})
|
})
|
||||||
|
|
||||||
if (Array.isArray(response)) return response
|
if (Array.isArray(response)) {
|
||||||
if (response && typeof response === "object" && Array.isArray(response["hydra:member"])) {
|
return response
|
||||||
return response["hydra:member"]
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||||
|
return response['hydra:member']
|
||||||
|
}
|
||||||
|
|
||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getSupplier(id: number): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.get<SupplierData>(`suppliers/${id}`, {}, {
|
|
||||||
toastErrorKey: "errors.supplier.fetch",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function updateSupplier(id: number, payload: SupplierPayload): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.patch<SupplierData>(`suppliers/${id}`, payload, {
|
|
||||||
toastErrorKey: "errors.supplier.update",
|
|
||||||
toastSuccessKey: "success.supplier.update",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createSupplier(payload: SupplierPayload): Promise<SupplierData> {
|
|
||||||
const api = useApi()
|
|
||||||
return api.post<SupplierData>("suppliers", payload, {
|
|
||||||
toastErrorKey: "errors.supplier.create",
|
|
||||||
toastSuccessKey: "success.supplier.create",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { defineStore } from 'pinia'
|
import { defineStore } from 'pinia'
|
||||||
import type { UserData } from '~/services/dto/user-data'
|
import type { UserData } from '~/services/dto/user-data'
|
||||||
import {getCurrentUser, createUser, login, logout} from '~/services/auth'
|
import { getCurrentUser, login, logout } from '~/services/auth'
|
||||||
import type {UserPayload} from "~/services/dto/user-data";
|
|
||||||
import {ROLE} from '~/utils/constants'
|
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', {
|
export const useAuthStore = defineStore('auth', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -11,8 +9,7 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
checked: false
|
checked: false
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
isAuthenticated: (state) => Boolean(state.user),
|
isAuthenticated: (state) => Boolean(state.user)
|
||||||
isAdmin: (state) => Boolean(state.user?.roles?.includes(ROLE[0].value))
|
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
clearSession() {
|
clearSession() {
|
||||||
@@ -49,20 +46,6 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async createUser(payload: UserPayload = {}) {
|
|
||||||
this.isLoading = true
|
|
||||||
const result = await createUser(payload).finally(() => {
|
|
||||||
this.isLoading = false
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
},
|
|
||||||
async updateUser(id: number, payload: UserPayload) {
|
|
||||||
this.isLoading = true
|
|
||||||
const result = await createUser(payload).finally(() => {
|
|
||||||
this.isLoading = false
|
|
||||||
})
|
|
||||||
return result
|
|
||||||
},
|
|
||||||
async logout() {
|
async logout() {
|
||||||
this.isLoading = true
|
this.isLoading = true
|
||||||
|
|
||||||
@@ -75,6 +58,6 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
this.checked = true
|
this.checked = true
|
||||||
this.isLoading = false
|
this.isLoading = false
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,10 +8,6 @@ export const MERCHANDISE_TYPE_CODES = {
|
|||||||
AUTRES: 'AUTRES'
|
AUTRES: 'AUTRES'
|
||||||
} as const
|
} as const
|
||||||
|
|
||||||
export const ROLE = [
|
|
||||||
{ label: 'Administrateur', value: 'ROLE_ADMIN' },
|
|
||||||
{ label: 'Utilisateur', value: 'ROLE_USER' }
|
|
||||||
]
|
|
||||||
export const SUPLLIER_CODE = {
|
export const SUPLLIER_CODE = {
|
||||||
LIOT: 'LIOT'
|
LIOT: 'LIOT'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace App\Entity;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -25,16 +23,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
normalizationContext: ['groups' => ['address:read']],
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
|
||||||
denormalizationContext: ['groups' => ['address:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['address:read']],
|
|
||||||
denormalizationContext: ['groups' => ['address:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -47,27 +35,27 @@ class Address
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $label = '';
|
private string $label = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $street = '';
|
private string $street = '';
|
||||||
|
|
||||||
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
#[ORM\Column(name: 'street2', length: 180, nullable: true)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private ?string $street2 = null;
|
private ?string $street2 = null;
|
||||||
|
|
||||||
#[ORM\Column(name: 'postal_code', length: 20)]
|
#[ORM\Column(name: 'postal_code', length: 20)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $postalCode = '';
|
private string $postalCode = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 120)]
|
#[ORM\Column(length: 120)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'reception:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read', 'reception:read'])]
|
||||||
private string $city = '';
|
private string $city = '';
|
||||||
|
|
||||||
#[ORM\Column(name: 'country_code', length: 2)]
|
#[ORM\Column(name: 'country_code', length: 2)]
|
||||||
#[Groups(['address:read', 'supplier:read', 'address:write'])]
|
#[Groups(['address:read', 'supplier:read'])]
|
||||||
private string $countryCode = '';
|
private string $countryCode = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ namespace App\Entity;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Serializer\Attribute\Groups;
|
use Symfony\Component\Serializer\Attribute\Groups;
|
||||||
|
|
||||||
@@ -23,17 +21,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['carrier:read']],
|
normalizationContext: ['groups' => ['carrier:read']],
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['carrier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['carrier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')"
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
requirements: ['id' => '\d+'],
|
|
||||||
normalizationContext: ['groups' => ['carrier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['carrier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')"
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -46,11 +33,11 @@ class Carrier
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['carrier:read', 'carrier:write', 'driver:read', 'vehicle:read', 'reception:read'])]
|
#[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
|
||||||
private string $name = '';
|
private string $name = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 30, nullable: true)]
|
#[ORM\Column(length: 30, nullable: true)]
|
||||||
#[Groups(['carrier:read', 'carrier:write', 'driver:read', 'vehicle:read', 'reception:read'])]
|
#[Groups(['carrier:read', 'driver:read', 'vehicle:read', 'reception:read'])]
|
||||||
private ?string $code = null;
|
private ?string $code = null;
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ use ApiPlatform\Metadata\ApiProperty;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use Doctrine\Common\Collections\ArrayCollection;
|
use Doctrine\Common\Collections\ArrayCollection;
|
||||||
use Doctrine\Common\Collections\Collection;
|
use Doctrine\Common\Collections\Collection;
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
@@ -26,16 +24,6 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
normalizationContext: ['groups' => ['supplier:read']],
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['supplier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['supplier:read']],
|
|
||||||
denormalizationContext: ['groups' => ['supplier:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
security: "is_granted('ROLE_USER')",
|
security: "is_granted('ROLE_USER')",
|
||||||
)]
|
)]
|
||||||
@@ -48,15 +36,15 @@ class Supplier
|
|||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180)]
|
#[ORM\Column(length: 180)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private string $name = '';
|
private string $name = '';
|
||||||
|
|
||||||
#[ORM\Column(length: 180, nullable: true)]
|
#[ORM\Column(length: 180, nullable: true)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private ?string $email = null;
|
private ?string $email = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 40, nullable: true)]
|
#[ORM\Column(length: 40, nullable: true)]
|
||||||
#[Groups(['supplier:read', 'reception:read', 'supplier:write'])]
|
#[Groups(['supplier:read', 'reception:read'])]
|
||||||
private ?string $phone = null;
|
private ?string $phone = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -64,7 +52,7 @@ class Supplier
|
|||||||
*/
|
*/
|
||||||
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
#[ORM\ManyToMany(targetEntity: Address::class, inversedBy: 'suppliers')]
|
||||||
#[ORM\JoinTable(name: 'supplier_address')]
|
#[ORM\JoinTable(name: 'supplier_address')]
|
||||||
#[Groups(['supplier:read', 'supplier:write'])]
|
#[Groups(['supplier:read'])]
|
||||||
#[ApiProperty(readableLink: true)]
|
#[ApiProperty(readableLink: true)]
|
||||||
private Collection $addresses;
|
private Collection $addresses;
|
||||||
|
|
||||||
@@ -121,30 +109,4 @@ class Supplier
|
|||||||
{
|
{
|
||||||
return $this->addresses;
|
return $this->addresses;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAddresses(iterable $addresses): self
|
|
||||||
{
|
|
||||||
$this->addresses->clear();
|
|
||||||
foreach ($addresses as $address) {
|
|
||||||
$this->addAddress($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function addAddress(Address $address): self
|
|
||||||
{
|
|
||||||
if (!$this->addresses->contains($address)) {
|
|
||||||
$this->addresses->add($address);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function removeAddress(Address $address): self
|
|
||||||
{
|
|
||||||
$this->addresses->removeElement($address);
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,10 +7,7 @@ namespace App\Entity;
|
|||||||
use ApiPlatform\Metadata\ApiResource;
|
use ApiPlatform\Metadata\ApiResource;
|
||||||
use ApiPlatform\Metadata\Get;
|
use ApiPlatform\Metadata\Get;
|
||||||
use ApiPlatform\Metadata\GetCollection;
|
use ApiPlatform\Metadata\GetCollection;
|
||||||
use ApiPlatform\Metadata\Patch;
|
|
||||||
use ApiPlatform\Metadata\Post;
|
|
||||||
use App\State\MeProvider;
|
use App\State\MeProvider;
|
||||||
use App\State\UserPasswordProcessor;
|
|
||||||
use Doctrine\ORM\Mapping as ORM;
|
use Doctrine\ORM\Mapping as ORM;
|
||||||
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
use Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface;
|
||||||
use Symfony\Component\Security\Core\User\UserInterface;
|
use Symfony\Component\Security\Core\User\UserInterface;
|
||||||
@@ -31,27 +28,10 @@ use Symfony\Component\Serializer\Attribute\Groups;
|
|||||||
normalizationContext: ['groups' => ['user:read']],
|
normalizationContext: ['groups' => ['user:read']],
|
||||||
security: "is_granted('ROLE_USER')"
|
security: "is_granted('ROLE_USER')"
|
||||||
),
|
),
|
||||||
new Post(
|
|
||||||
normalizationContext: ['groups' => ['user:read']],
|
|
||||||
denormalizationContext: ['groups' => ['user:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
processor: UserPasswordProcessor::class
|
|
||||||
),
|
|
||||||
new Patch(
|
|
||||||
normalizationContext: ['groups' => ['user:read']],
|
|
||||||
denormalizationContext: ['groups' => ['user:write']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')",
|
|
||||||
processor: UserPasswordProcessor::class
|
|
||||||
),
|
|
||||||
new GetCollection(
|
new GetCollection(
|
||||||
normalizationContext: ['groups' => ['user-login:read']],
|
normalizationContext: ['groups' => ['user:read']],
|
||||||
security: "is_granted('PUBLIC_ACCESS')"
|
security: "is_granted('PUBLIC_ACCESS')"
|
||||||
),
|
),
|
||||||
new GetCollection(
|
|
||||||
uriTemplate: '/admin/users',
|
|
||||||
normalizationContext: ['groups' => ['user:read']],
|
|
||||||
security: "is_granted('ROLE_ADMIN')"
|
|
||||||
),
|
|
||||||
],
|
],
|
||||||
normalizationContext: ['groups' => ['user:read']],
|
normalizationContext: ['groups' => ['user:read']],
|
||||||
paginationEnabled: false
|
paginationEnabled: false
|
||||||
@@ -61,19 +41,18 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface
|
|||||||
#[ORM\Id]
|
#[ORM\Id]
|
||||||
#[ORM\GeneratedValue]
|
#[ORM\GeneratedValue]
|
||||||
#[ORM\Column(type: 'integer')]
|
#[ORM\Column(type: 'integer')]
|
||||||
#[Groups(['user:read', 'user-login:read', 'reception:read'])]
|
#[Groups(['user:read', 'reception:read'])]
|
||||||
private ?int $id = null;
|
private ?int $id = null;
|
||||||
|
|
||||||
#[ORM\Column(length: 180, unique: true)]
|
#[ORM\Column(length: 180, unique: true)]
|
||||||
#[Groups(['user:read', 'user:write', 'user-login:read', 'reception:read'])]
|
#[Groups(['user:read', 'reception:read'])]
|
||||||
private string $username = '';
|
private string $username = '';
|
||||||
|
|
||||||
#[ORM\Column(type: 'json')]
|
#[ORM\Column(type: 'json')]
|
||||||
#[Groups(['user:write', 'user:read'])]
|
#[Groups(['user:read'])]
|
||||||
private array $roles = [];
|
private array $roles = [];
|
||||||
|
|
||||||
#[ORM\Column]
|
#[ORM\Column]
|
||||||
#[Groups(['user:write'])]
|
|
||||||
private string $password = '';
|
private string $password = '';
|
||||||
|
|
||||||
public function getId(): ?int
|
public function getId(): ?int
|
||||||
|
|||||||
@@ -1,40 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
declare(strict_types=1);
|
|
||||||
|
|
||||||
namespace App\State;
|
|
||||||
|
|
||||||
use ApiPlatform\Metadata\Operation;
|
|
||||||
use ApiPlatform\State\ProcessorInterface;
|
|
||||||
use App\Entity\User;
|
|
||||||
use Symfony\Component\DependencyInjection\Attribute\Autowire;
|
|
||||||
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
|
|
||||||
|
|
||||||
final class UserPasswordProcessor implements ProcessorInterface
|
|
||||||
{
|
|
||||||
public function __construct(
|
|
||||||
private readonly UserPasswordHasherInterface $hasher,
|
|
||||||
#[Autowire(service: 'api_platform.doctrine.orm.state.persist_processor')]
|
|
||||||
private readonly ProcessorInterface $persistProcessor
|
|
||||||
) {}
|
|
||||||
|
|
||||||
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): mixed
|
|
||||||
{
|
|
||||||
if ($data instanceof User) {
|
|
||||||
$plain = $data->getPassword();
|
|
||||||
if ('' !== $plain) {
|
|
||||||
$data->setPassword($this->hasher->hashPassword(
|
|
||||||
$data,
|
|
||||||
$plain
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->persistProcessor->process(
|
|
||||||
$data,
|
|
||||||
$operation,
|
|
||||||
$uriVariables,
|
|
||||||
$context
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user