feat: gérer les constructeurs multiples
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload } from '~/shared/constructeurUtils'
|
||||
|
||||
const composants = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -27,7 +28,7 @@ const loadComposants = async () => {
|
||||
const createComposant = async (composantData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/composants', composantData)
|
||||
const result = await post('/composants', buildConstructeurRequestPayload(composantData))
|
||||
if (result.success) {
|
||||
composants.value.push(result.data)
|
||||
const displayName = result.data?.name
|
||||
@@ -48,7 +49,7 @@ const loadComposants = async () => {
|
||||
const updateComposantData = async (id, composantData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/composants/${id}`, composantData)
|
||||
const result = await patch(`/composants/${id}`, buildConstructeurRequestPayload(composantData))
|
||||
if (result.success) {
|
||||
const updated = result.data
|
||||
const index = composants.value.findIndex(comp => comp.id === id)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload } from '~/shared/constructeurUtils'
|
||||
|
||||
const machines = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -76,7 +77,7 @@ export function useMachines () {
|
||||
const createMachine = async (machineData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/machines', machineData)
|
||||
const result = await post('/machines', buildConstructeurRequestPayload(machineData))
|
||||
if (result.success) {
|
||||
const createdMachine = normalizeMachineResponse(result.data) ||
|
||||
normalizeMachineResponse(result.data?.machine) ||
|
||||
@@ -105,13 +106,13 @@ export function useMachines () {
|
||||
// Les composants et pièces seront créés automatiquement
|
||||
}
|
||||
|
||||
return await createMachine(machineWithStructure)
|
||||
return await createMachine(buildConstructeurRequestPayload(machineWithStructure))
|
||||
}
|
||||
|
||||
const updateMachineData = async (id, machineData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/machines/${id}`, machineData)
|
||||
const result = await patch(`/machines/${id}`, buildConstructeurRequestPayload(machineData))
|
||||
if (result.success) {
|
||||
const updatedMachine = normalizeMachineResponse(result.data) ||
|
||||
normalizeMachineResponse(result.data?.machine) ||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { ref } from 'vue'
|
||||
import { useToast } from './useToast'
|
||||
import { useApi } from './useApi'
|
||||
import { buildConstructeurRequestPayload } from '~/shared/constructeurUtils'
|
||||
|
||||
const pieces = ref([])
|
||||
const loading = ref(false)
|
||||
@@ -27,7 +28,7 @@ export function usePieces () {
|
||||
const createPiece = async (pieceData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await post('/pieces', pieceData)
|
||||
const result = await post('/pieces', buildConstructeurRequestPayload(pieceData))
|
||||
if (result.success) {
|
||||
pieces.value.push(result.data)
|
||||
const displayName = result.data?.name
|
||||
@@ -48,7 +49,7 @@ export function usePieces () {
|
||||
const updatePieceData = async (id, pieceData) => {
|
||||
loading.value = true
|
||||
try {
|
||||
const result = await patch(`/pieces/${id}`, pieceData)
|
||||
const result = await patch(`/pieces/${id}`, buildConstructeurRequestPayload(pieceData))
|
||||
if (result.success) {
|
||||
const updated = result.data
|
||||
const index = pieces.value.findIndex(piece => piece.id === id)
|
||||
|
||||
Reference in New Issue
Block a user