fix : correction des retours de la V0
This commit is contained in:
@@ -1,59 +1,19 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { useWorkflowStoreLogic } from '~/stores/workflow-store'
|
||||
import { receptionService } from '~/services/reception'
|
||||
import type { ReceptionData, ReceptionPayload } from '~/services/dto/reception-data'
|
||||
import { createReception, getReception, updateReception } from '~/services/reception'
|
||||
|
||||
const isReceptionData = (value: unknown): value is ReceptionData => {
|
||||
return Boolean(value && typeof value === 'object' && 'id' in value)
|
||||
}
|
||||
export const useReceptionStore = defineStore('reception', () => {
|
||||
const { current, isLoading, setCurrent, clearCurrent, load, create, update } =
|
||||
useWorkflowStoreLogic<ReceptionData, ReceptionPayload>(receptionService)
|
||||
|
||||
export const useReceptionStore = defineStore('reception', {
|
||||
state: () => ({
|
||||
current: null as ReceptionData | null,
|
||||
isLoading: false
|
||||
}),
|
||||
actions: {
|
||||
setCurrent(reception: ReceptionData | null) {
|
||||
this.current = reception
|
||||
},
|
||||
clearCurrent() {
|
||||
this.current = null
|
||||
},
|
||||
async loadReception(id: number) {
|
||||
this.isLoading = true
|
||||
const result = await getReception(id).finally(() => {
|
||||
this.isLoading = false
|
||||
})
|
||||
if (!isReceptionData(result)) {
|
||||
this.current = null
|
||||
return null
|
||||
}
|
||||
|
||||
this.current = result
|
||||
return result
|
||||
},
|
||||
async createReception(payload: ReceptionPayload = {}) {
|
||||
this.isLoading = true
|
||||
const result = await createReception(payload).finally(() => {
|
||||
this.isLoading = false
|
||||
})
|
||||
if (!isReceptionData(result)) {
|
||||
return null
|
||||
}
|
||||
|
||||
this.current = result
|
||||
return result
|
||||
},
|
||||
async updateReception(id: number, payload: ReceptionPayload) {
|
||||
this.isLoading = true
|
||||
const result = await updateReception(id, payload).finally(() => {
|
||||
this.isLoading = false
|
||||
})
|
||||
if (!isReceptionData(result)) {
|
||||
return null
|
||||
}
|
||||
|
||||
this.current = result
|
||||
return result
|
||||
return {
|
||||
current,
|
||||
isLoading,
|
||||
setCurrent,
|
||||
clearCurrent,
|
||||
loadReception: load,
|
||||
createReception: create,
|
||||
updateReception: update
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user