| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [ ] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #7 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { defineStore } from 'pinia'
|
|
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', {
|
|
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
|
|
}
|
|
}
|
|
})
|