feat(front): aligner api platform et sessions [INV-20260111-02]
This commit is contained in:
@@ -10,6 +10,7 @@ export function useApi () {
|
||||
const apiCall = async (endpoint, options = {}) => {
|
||||
const url = `${API_BASE_URL}${endpoint}`
|
||||
const defaultOptions = {
|
||||
credentials: 'include',
|
||||
headers: {
|
||||
'Content-Type': 'application/json'
|
||||
}
|
||||
@@ -32,7 +33,7 @@ export function useApi () {
|
||||
let data = null
|
||||
if (response.status !== 204) {
|
||||
const contentType = response.headers.get('content-type') || ''
|
||||
if (contentType.includes('application/json')) {
|
||||
if (contentType.includes('application/json') || contentType.includes('application/ld+json') || contentType.includes('+json')) {
|
||||
const text = await response.text()
|
||||
data = text ? JSON.parse(text) : null
|
||||
} else {
|
||||
|
||||
@@ -3,10 +3,27 @@ import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload, uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import { useConstructeurs } from './useConstructeurs'
|
||||
import { extractRelationId, normalizeRelationIds } from '~/shared/apiRelations'
|
||||
|
||||
const composants = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
const extractCollection = (payload) => {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (Array.isArray(payload?.member)) {
|
||||
return payload.member
|
||||
}
|
||||
if (Array.isArray(payload?.['hydra:member'])) {
|
||||
return payload['hydra:member']
|
||||
}
|
||||
if (Array.isArray(payload?.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export function useComposants () {
|
||||
const { showSuccess, showError, showInfo } = useToast()
|
||||
const { get, post, patch, delete: del } = useApi()
|
||||
@@ -16,6 +33,18 @@ export function useComposants () {
|
||||
if (!composant || typeof composant !== 'object') {
|
||||
return composant
|
||||
}
|
||||
if (!composant.typeComposantId) {
|
||||
const typeComposantId = extractRelationId(composant.typeComposant)
|
||||
if (typeComposantId) {
|
||||
composant.typeComposantId = typeComposantId
|
||||
}
|
||||
}
|
||||
if (!composant.productId) {
|
||||
const productId = extractRelationId(composant.product)
|
||||
if (productId) {
|
||||
composant.productId = productId
|
||||
}
|
||||
}
|
||||
const ids = uniqueConstructeurIds(
|
||||
composant.constructeurIds,
|
||||
composant.constructeurs,
|
||||
@@ -34,27 +63,28 @@ export function useComposants () {
|
||||
return composant
|
||||
}
|
||||
|
||||
const loadComposants = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await get('/composants')
|
||||
if (result.success) {
|
||||
const items = Array.isArray(result.data) ? result.data : []
|
||||
const enrichedItems = await Promise.all(items.map((item) => withResolvedConstructeurs(item)))
|
||||
composants.value = enrichedItems
|
||||
showInfo(`Chargement de ${composants.value.length} composant(s) réussi`)
|
||||
const loadComposants = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await get('/composants')
|
||||
if (result.success) {
|
||||
const items = extractCollection(result.data)
|
||||
const enrichedItems = await Promise.all(items.map((item) => withResolvedConstructeurs(item)))
|
||||
composants.value = enrichedItems
|
||||
showInfo(`Chargement de ${composants.value.length} composant(s) réussi`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des composants:', error)
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const createComposant = async (composantData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/composants', buildConstructeurRequestPayload(composantData))
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(composantData))
|
||||
const result = await post('/composants', normalizedPayload)
|
||||
if (result.success) {
|
||||
const enriched = await withResolvedConstructeurs(result.data)
|
||||
composants.value.push(enriched)
|
||||
@@ -76,7 +106,8 @@ const loadComposants = async () => {
|
||||
const updateComposantData = async (id, composantData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/composants/${id}`, buildConstructeurRequestPayload(composantData))
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(composantData))
|
||||
const result = await patch(`/composants/${id}`, normalizedPayload)
|
||||
if (result.success) {
|
||||
const updated = await withResolvedConstructeurs(result.data)
|
||||
const index = composants.value.findIndex(comp => comp.id === id)
|
||||
|
||||
@@ -39,6 +39,22 @@ const upsertConstructeurs = (items = []) => {
|
||||
const getIndexedConstructeur = (id) =>
|
||||
constructeurs.value.find((item) => item && item.id === id) || null
|
||||
|
||||
const extractCollection = (payload) => {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (Array.isArray(payload?.member)) {
|
||||
return payload.member
|
||||
}
|
||||
if (Array.isArray(payload?.['hydra:member'])) {
|
||||
return payload['hydra:member']
|
||||
}
|
||||
if (Array.isArray(payload?.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
const pendingFetches = new Map()
|
||||
|
||||
export function useConstructeurs () {
|
||||
@@ -51,7 +67,7 @@ export function useConstructeurs () {
|
||||
const query = search ? `?search=${encodeURIComponent(search)}` : ''
|
||||
const result = await get(`/constructeurs${query}`)
|
||||
if (result.success) {
|
||||
const items = Array.isArray(result.data) ? result.data : []
|
||||
const items = extractCollection(result.data)
|
||||
constructeurs.value = uniqueConstructeurs(items)
|
||||
}
|
||||
return result
|
||||
|
||||
@@ -1,10 +1,27 @@
|
||||
import { ref } from 'vue'
|
||||
import { useApi } from './useApi'
|
||||
import { useToast } from './useToast'
|
||||
import { normalizeRelationIds } from '~/shared/apiRelations'
|
||||
|
||||
const documents = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
const extractCollection = (payload) => {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (Array.isArray(payload?.member)) {
|
||||
return payload.member
|
||||
}
|
||||
if (Array.isArray(payload?.['hydra:member'])) {
|
||||
return payload['hydra:member']
|
||||
}
|
||||
if (Array.isArray(payload?.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
const fileToBase64 = file =>
|
||||
new Promise((resolve, reject) => {
|
||||
const reader = new FileReader()
|
||||
@@ -22,7 +39,7 @@ export function useDocuments () {
|
||||
try {
|
||||
const result = await get(endpoint)
|
||||
if (result.success) {
|
||||
const data = result.data || []
|
||||
const data = extractCollection(result.data)
|
||||
if (updateStore) {
|
||||
documents.value = data
|
||||
}
|
||||
@@ -80,14 +97,14 @@ export function useDocuments () {
|
||||
for (const file of files) {
|
||||
const dataUrl = await fileToBase64(file)
|
||||
|
||||
const payload = {
|
||||
const payload = normalizeRelationIds({
|
||||
name: file.name,
|
||||
filename: file.name,
|
||||
mimeType: file.type || 'application/octet-stream',
|
||||
size: file.size,
|
||||
path: dataUrl,
|
||||
...context
|
||||
}
|
||||
})
|
||||
|
||||
const result = await post('/documents', payload)
|
||||
if (result.success) {
|
||||
|
||||
@@ -1,11 +1,30 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { extractRelationId } from '~/shared/apiRelations'
|
||||
|
||||
const machineTypes = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
const normalizeRequirementList = (value) => (Array.isArray(value) ? value : [])
|
||||
const normalizeRequirementList = (value, relationKey) => {
|
||||
if (!Array.isArray(value)) {
|
||||
return []
|
||||
}
|
||||
return value.map((entry) => {
|
||||
if (!entry || typeof entry !== 'object') {
|
||||
return entry
|
||||
}
|
||||
const normalized = { ...entry }
|
||||
if (relationKey && !normalized[relationKey]) {
|
||||
const relationValue = normalized[relationKey.replace('Id', '')]
|
||||
const relationId = extractRelationId(relationValue)
|
||||
if (relationId) {
|
||||
normalized[relationKey] = relationId
|
||||
}
|
||||
}
|
||||
return normalized
|
||||
})
|
||||
}
|
||||
|
||||
const normalizeMachineType = (type) => {
|
||||
if (!type || typeof type !== 'object') {
|
||||
@@ -13,12 +32,28 @@ const normalizeMachineType = (type) => {
|
||||
}
|
||||
return {
|
||||
...type,
|
||||
componentRequirements: normalizeRequirementList(type.componentRequirements),
|
||||
pieceRequirements: normalizeRequirementList(type.pieceRequirements),
|
||||
productRequirements: normalizeRequirementList(type.productRequirements),
|
||||
componentRequirements: normalizeRequirementList(type.componentRequirements, 'typeComposantId'),
|
||||
pieceRequirements: normalizeRequirementList(type.pieceRequirements, 'typePieceId'),
|
||||
productRequirements: normalizeRequirementList(type.productRequirements, 'typeProductId'),
|
||||
}
|
||||
}
|
||||
|
||||
const extractCollection = (payload) => {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (Array.isArray(payload?.member)) {
|
||||
return payload.member
|
||||
}
|
||||
if (Array.isArray(payload?.['hydra:member'])) {
|
||||
return payload['hydra:member']
|
||||
}
|
||||
if (Array.isArray(payload?.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export function useMachineTypesApi () {
|
||||
const { showSuccess, showError, showInfo } = useToast()
|
||||
const { get, post, patch, delete: del } = useApi()
|
||||
@@ -26,11 +61,10 @@ export function useMachineTypesApi () {
|
||||
const loadMachineTypes = async () => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await get('/types/machines')
|
||||
const result = await get('/type_machines')
|
||||
if (result.success) {
|
||||
machineTypes.value = Array.isArray(result.data)
|
||||
? result.data.map(normalizeMachineType)
|
||||
: []
|
||||
const items = extractCollection(result.data)
|
||||
machineTypes.value = items.map(normalizeMachineType)
|
||||
showInfo(`Chargement de ${machineTypes.value.length} type(s) de machine réussi`)
|
||||
}
|
||||
} catch (error) {
|
||||
@@ -43,7 +77,7 @@ export function useMachineTypesApi () {
|
||||
const createMachineType = async (typeData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/types/machines', typeData)
|
||||
const result = await post('/type_machines', typeData)
|
||||
if (result.success) {
|
||||
machineTypes.value.push(normalizeMachineType(result.data))
|
||||
showSuccess(`Type de machine "${typeData.name}" créé avec succès`)
|
||||
@@ -60,7 +94,7 @@ export function useMachineTypesApi () {
|
||||
const updateMachineType = async (id, typeData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/types/machines/${id}`, typeData)
|
||||
const result = await patch(`/type_machines/${id}`, typeData)
|
||||
if (result.success) {
|
||||
const normalized = normalizeMachineType(result.data)
|
||||
const index = machineTypes.value.findIndex(type => type.id === id)
|
||||
@@ -81,7 +115,7 @@ export function useMachineTypesApi () {
|
||||
const deleteMachineType = async (id) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await del(`/types/machines/${id}`)
|
||||
const result = await del(`/type_machines/${id}`)
|
||||
if (result.success) {
|
||||
const deletedType = machineTypes.value.find(type => type.id === id)
|
||||
machineTypes.value = machineTypes.value.filter(type => type.id !== id)
|
||||
@@ -105,7 +139,7 @@ export function useMachineTypesApi () {
|
||||
|
||||
// Si pas trouvé localement, récupérer depuis l'API
|
||||
try {
|
||||
const result = await get(`/types/machines/${id}`)
|
||||
const result = await get(`/type_machines/${id}`)
|
||||
if (result.success) {
|
||||
// Ajouter au cache local
|
||||
machineTypes.value.push(normalizeMachineType(result.data))
|
||||
|
||||
@@ -2,6 +2,7 @@ import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload } from '~/shared/constructeurUtils'
|
||||
import { extractRelationId, normalizeRelationIds } from '~/shared/apiRelations'
|
||||
|
||||
const machines = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -32,6 +33,20 @@ const normalizeMachineResponse = (payload) => {
|
||||
|
||||
const normalized = { ...container }
|
||||
|
||||
if (!normalized.siteId) {
|
||||
const siteId = extractRelationId(container.site)
|
||||
if (siteId) {
|
||||
normalized.siteId = siteId
|
||||
}
|
||||
}
|
||||
|
||||
if (!normalized.typeMachineId) {
|
||||
const typeMachineId = extractRelationId(container.typeMachine)
|
||||
if (typeMachineId) {
|
||||
normalized.typeMachineId = typeMachineId
|
||||
}
|
||||
}
|
||||
|
||||
const componentLinks = resolveLinkCollection(payload, ['componentLinks', 'machineComponentLinks']) ??
|
||||
resolveLinkCollection(container, ['componentLinks', 'machineComponentLinks']) ??
|
||||
[]
|
||||
@@ -56,11 +71,15 @@ export function useMachines () {
|
||||
if (result.success) {
|
||||
const machineList = Array.isArray(result.data)
|
||||
? result.data
|
||||
: Array.isArray(result.data?.machines)
|
||||
? result.data.machines
|
||||
: Array.isArray(result.data?.data)
|
||||
? result.data.data
|
||||
: []
|
||||
: Array.isArray(result.data?.member)
|
||||
? result.data.member
|
||||
: Array.isArray(result.data?.['hydra:member'])
|
||||
? result.data['hydra:member']
|
||||
: Array.isArray(result.data?.machines)
|
||||
? result.data.machines
|
||||
: Array.isArray(result.data?.data)
|
||||
? result.data.data
|
||||
: []
|
||||
const normalized = machineList
|
||||
.map((item) => normalizeMachineResponse(item))
|
||||
.filter(Boolean)
|
||||
@@ -77,7 +96,8 @@ export function useMachines () {
|
||||
const createMachine = async (machineData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/machines', buildConstructeurRequestPayload(machineData))
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(machineData))
|
||||
const result = await post('/machines', normalizedPayload)
|
||||
if (result.success) {
|
||||
const createdMachine = normalizeMachineResponse(result.data) ||
|
||||
normalizeMachineResponse(result.data?.machine) ||
|
||||
@@ -106,13 +126,14 @@ export function useMachines () {
|
||||
// Les composants et pièces seront créés automatiquement
|
||||
}
|
||||
|
||||
return await createMachine(buildConstructeurRequestPayload(machineWithStructure))
|
||||
return await createMachine(machineWithStructure)
|
||||
}
|
||||
|
||||
const updateMachineData = async (id, machineData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/machines/${id}`, buildConstructeurRequestPayload(machineData))
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(machineData))
|
||||
const result = await patch(`/machines/${id}`, normalizedPayload)
|
||||
if (result.success) {
|
||||
const updatedMachine = normalizeMachineResponse(result.data) ||
|
||||
normalizeMachineResponse(result.data?.machine) ||
|
||||
|
||||
@@ -3,10 +3,27 @@ import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload, uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import { useConstructeurs } from './useConstructeurs'
|
||||
import { extractRelationId, normalizeRelationIds } from '~/shared/apiRelations'
|
||||
|
||||
const pieces = ref([])
|
||||
const loading = ref(false)
|
||||
|
||||
const extractCollection = (payload) => {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (Array.isArray(payload?.member)) {
|
||||
return payload.member
|
||||
}
|
||||
if (Array.isArray(payload?.['hydra:member'])) {
|
||||
return payload['hydra:member']
|
||||
}
|
||||
if (Array.isArray(payload?.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export function usePieces () {
|
||||
const { showSuccess, showError, showInfo } = useToast()
|
||||
const { get, post, patch, delete: del } = useApi()
|
||||
@@ -16,6 +33,18 @@ export function usePieces () {
|
||||
if (!piece || typeof piece !== 'object') {
|
||||
return piece
|
||||
}
|
||||
if (!piece.typePieceId) {
|
||||
const typePieceId = extractRelationId(piece.typePiece)
|
||||
if (typePieceId) {
|
||||
piece.typePieceId = typePieceId
|
||||
}
|
||||
}
|
||||
if (!piece.productId) {
|
||||
const productId = extractRelationId(piece.product)
|
||||
if (productId) {
|
||||
piece.productId = productId
|
||||
}
|
||||
}
|
||||
const ids = uniqueConstructeurIds(
|
||||
piece.constructeurIds,
|
||||
piece.constructeurs,
|
||||
@@ -39,7 +68,7 @@ export function usePieces () {
|
||||
try {
|
||||
const result = await get('/pieces')
|
||||
if (result.success) {
|
||||
const items = Array.isArray(result.data) ? result.data : []
|
||||
const items = extractCollection(result.data)
|
||||
const enrichedItems = await Promise.all(items.map((item) => withResolvedConstructeurs(item)))
|
||||
pieces.value = enrichedItems
|
||||
showInfo(`Chargement de ${pieces.value.length} pièce(s) réussi`)
|
||||
@@ -54,7 +83,8 @@ export function usePieces () {
|
||||
const createPiece = async (pieceData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/pieces', buildConstructeurRequestPayload(pieceData))
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(pieceData))
|
||||
const result = await post('/pieces', normalizedPayload)
|
||||
if (result.success) {
|
||||
const enriched = await withResolvedConstructeurs(result.data)
|
||||
pieces.value.push(enriched)
|
||||
@@ -76,7 +106,8 @@ export function usePieces () {
|
||||
const updatePieceData = async (id, pieceData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/pieces/${id}`, buildConstructeurRequestPayload(pieceData))
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(pieceData))
|
||||
const result = await patch(`/pieces/${id}`, normalizedPayload)
|
||||
if (result.success) {
|
||||
const updated = await withResolvedConstructeurs(result.data)
|
||||
const index = pieces.value.findIndex(piece => piece.id === id)
|
||||
|
||||
@@ -3,6 +3,7 @@ import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload, uniqueConstructeurIds } from '~/shared/constructeurUtils'
|
||||
import { useConstructeurs } from './useConstructeurs'
|
||||
import { extractRelationId, normalizeRelationIds } from '~/shared/apiRelations'
|
||||
|
||||
const products = ref([])
|
||||
const total = ref(0)
|
||||
@@ -25,6 +26,22 @@ const replaceInCache = (item) => {
|
||||
return false
|
||||
}
|
||||
|
||||
const extractCollection = (payload) => {
|
||||
if (Array.isArray(payload)) {
|
||||
return payload
|
||||
}
|
||||
if (Array.isArray(payload?.member)) {
|
||||
return payload.member
|
||||
}
|
||||
if (Array.isArray(payload?.['hydra:member'])) {
|
||||
return payload['hydra:member']
|
||||
}
|
||||
if (Array.isArray(payload?.data)) {
|
||||
return payload.data
|
||||
}
|
||||
return []
|
||||
}
|
||||
|
||||
export function useProducts () {
|
||||
const { showError } = useToast()
|
||||
const { get, post, patch, delete: del } = useApi()
|
||||
@@ -34,6 +51,12 @@ export function useProducts () {
|
||||
if (!product || typeof product !== 'object') {
|
||||
return product
|
||||
}
|
||||
if (!product.typeProductId) {
|
||||
const typeProductId = extractRelationId(product.typeProduct)
|
||||
if (typeProductId) {
|
||||
product.typeProductId = typeProductId
|
||||
}
|
||||
}
|
||||
const ids = uniqueConstructeurIds(
|
||||
product.constructeurIds,
|
||||
product.constructeurs,
|
||||
@@ -69,12 +92,14 @@ export function useProducts () {
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
const result = await get('/products?limit=100')
|
||||
const result = await get('/products?itemsPerPage=100')
|
||||
if (result.success) {
|
||||
const items = Array.isArray(result.data?.items) ? result.data.items : []
|
||||
const items = extractCollection(result.data)
|
||||
const enrichedItems = await Promise.all(items.map((item) => withResolvedConstructeurs(item)))
|
||||
products.value = enrichedItems
|
||||
total.value = typeof result.data?.total === 'number' ? result.data.total : items.length
|
||||
total.value = typeof result.data?.totalItems === 'number'
|
||||
? result.data.totalItems
|
||||
: items.length
|
||||
loaded.value = true
|
||||
} else if (result.error) {
|
||||
error.value = result.error
|
||||
@@ -93,7 +118,7 @@ export function useProducts () {
|
||||
}
|
||||
|
||||
const createProduct = async (payload) => {
|
||||
const normalizedPayload = buildConstructeurRequestPayload(payload)
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(payload))
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
@@ -121,7 +146,7 @@ export function useProducts () {
|
||||
}
|
||||
|
||||
const updateProduct = async (id, payload) => {
|
||||
const normalizedPayload = buildConstructeurRequestPayload(payload)
|
||||
const normalizedPayload = normalizeRelationIds(buildConstructeurRequestPayload(payload))
|
||||
loading.value = true
|
||||
error.value = null
|
||||
try {
|
||||
|
||||
@@ -2,7 +2,10 @@ import { useState, useRequestHeaders, useRuntimeConfig } from '#imports'
|
||||
|
||||
const buildUrl = (path) => {
|
||||
const config = useRuntimeConfig()
|
||||
const base = config.public.apiBaseUrl?.replace(/\/$/, '') || ''
|
||||
const baseUrl = process.server
|
||||
? (config.apiBaseUrl || config.public.apiBaseUrl || '')
|
||||
: (config.public.apiBaseUrl || '')
|
||||
const base = baseUrl.replace(/\/$/, '')
|
||||
return `${base}${path}`
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export function useProfiles () {
|
||||
const fetchProfiles = async () => {
|
||||
loadingProfiles.value = true
|
||||
try {
|
||||
profiles.value = await $fetch(buildUrl('/profiles'), {
|
||||
profiles.value = await $fetch(buildUrl('/session/profiles'), {
|
||||
method: 'GET',
|
||||
credentials: 'include',
|
||||
headers: getSessionHeaders()
|
||||
@@ -37,7 +37,7 @@ export function useProfiles () {
|
||||
}
|
||||
|
||||
const createProfile = async ({ firstName, lastName }) => {
|
||||
const profile = await $fetch(buildUrl('/profiles'), {
|
||||
const profile = await $fetch(buildUrl('/session/profiles'), {
|
||||
method: 'POST',
|
||||
credentials: 'include',
|
||||
body: { firstName, lastName },
|
||||
@@ -48,7 +48,7 @@ export function useProfiles () {
|
||||
}
|
||||
|
||||
const deleteProfile = async (profileId) => {
|
||||
await $fetch(buildUrl(`/profiles/${profileId}`), {
|
||||
await $fetch(buildUrl(`/session/profiles/${profileId}`), {
|
||||
method: 'DELETE',
|
||||
credentials: 'include',
|
||||
headers: getSessionHeaders()
|
||||
|
||||
@@ -13,9 +13,20 @@ export function useSites () {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await get('/sites')
|
||||
console.log('sites api result', result)
|
||||
|
||||
if (result.success) {
|
||||
sites.value = result.data
|
||||
showInfo(`Chargement de ${sites.value.length} site(s) réussi`)
|
||||
const collection = Array.isArray(result.data)
|
||||
? result.data
|
||||
: Array.isArray(result.data?.member)
|
||||
? result.data.member
|
||||
: Array.isArray(result.data?.['hydra:member'])
|
||||
? result.data['hydra:member']
|
||||
: Array.isArray(result.data?.data)
|
||||
? result.data.data
|
||||
: []
|
||||
sites.value = collection
|
||||
showInfo(`Chargement de ${collection.length} site(s) réussi`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Erreur lors du chargement des sites:', error)
|
||||
|
||||
Reference in New Issue
Block a user