feat : finalisation de l'étape 1 "Réception" (formulaire)
This commit is contained in:
23
frontend/services/carrier.ts
Normal file
23
frontend/services/carrier.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { CarrierData } from '~/services/dto/carrier-data'
|
||||
|
||||
export type CarrierListResponse =
|
||||
| CarrierData[]
|
||||
| { 'hydra:member'?: CarrierData[] }
|
||||
|
||||
export async function getCarrierList(): Promise<CarrierData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<CarrierListResponse>('carriers', {}, {
|
||||
toastErrorKey: 'errors.carrier.list'
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return response['hydra:member']
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
23
frontend/services/driver.ts
Normal file
23
frontend/services/driver.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { DriverData } from '~/services/dto/driver-data'
|
||||
|
||||
export type DriverListResponse =
|
||||
| DriverData[]
|
||||
| { 'hydra:member'?: DriverData[] }
|
||||
|
||||
export async function getDriverList(): Promise<DriverData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<DriverListResponse>('drivers', {}, {
|
||||
toastErrorKey: 'errors.driver.list'
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return response['hydra:member']
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
9
frontend/services/dto/address-data.ts
Normal file
9
frontend/services/dto/address-data.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export interface AddressData {
|
||||
id: number
|
||||
label: string
|
||||
street: string
|
||||
postalCode: string
|
||||
city: string
|
||||
countryCode: string
|
||||
fullAddress?: string
|
||||
}
|
||||
5
frontend/services/dto/carrier-data.ts
Normal file
5
frontend/services/dto/carrier-data.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface CarrierData {
|
||||
id: number
|
||||
name: string
|
||||
code: string
|
||||
}
|
||||
7
frontend/services/dto/driver-data.ts
Normal file
7
frontend/services/dto/driver-data.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { CarrierData } from '~/services/dto/carrier-data'
|
||||
|
||||
export interface DriverData {
|
||||
id: number
|
||||
name: string
|
||||
carrier?: CarrierData | null
|
||||
}
|
||||
@@ -1,3 +1,11 @@
|
||||
import type { ReceptionTypeData } from '~/services/dto/reception-type-data'
|
||||
import type { UserData } from '~/services/dto/user-data'
|
||||
import type { SupplierData } from '~/services/dto/supplier-data'
|
||||
import type { AddressData } from '~/services/dto/address-data'
|
||||
import type { TruckData } from '~/services/dto/truck-data'
|
||||
import type { CarrierData } from '~/services/dto/carrier-data'
|
||||
import type { DriverData } from '~/services/dto/driver-data'
|
||||
|
||||
export interface ReceptionData {
|
||||
id: number
|
||||
licensePlate: string | null
|
||||
@@ -5,6 +13,13 @@ export interface ReceptionData {
|
||||
receptionDate: string
|
||||
currentStep: number
|
||||
isValid: boolean
|
||||
receptionType?: ReceptionTypeData | null
|
||||
user?: UserData | null
|
||||
supplier?: SupplierData | null
|
||||
address?: AddressData | null
|
||||
truck?: TruckData | null
|
||||
carrier?: CarrierData | null
|
||||
driver?: DriverData | null
|
||||
}
|
||||
|
||||
export interface WeightEntryData {
|
||||
@@ -14,3 +29,17 @@ export interface WeightEntryData {
|
||||
weight: number | null
|
||||
weighedAt: string | null
|
||||
}
|
||||
|
||||
export type ReceptionPayload = {
|
||||
licensePlate?: string | null
|
||||
receptionDate?: string
|
||||
currentStep?: number
|
||||
isValid?: boolean
|
||||
receptionType?: string | null
|
||||
user?: string | null
|
||||
supplier?: string | null
|
||||
address?: string | null
|
||||
truck?: string | null
|
||||
carrier?: string | null
|
||||
driver?: string | null
|
||||
}
|
||||
|
||||
5
frontend/services/dto/reception-type-data.ts
Normal file
5
frontend/services/dto/reception-type-data.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
export interface ReceptionTypeData {
|
||||
id: number
|
||||
label: string
|
||||
code: string
|
||||
}
|
||||
7
frontend/services/dto/supplier-data.ts
Normal file
7
frontend/services/dto/supplier-data.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import type { AddressData } from '~/services/dto/address-data'
|
||||
|
||||
export interface SupplierData {
|
||||
id: number
|
||||
name: string
|
||||
addresses?: AddressData[] | null
|
||||
}
|
||||
4
frontend/services/dto/truck-data.ts
Normal file
4
frontend/services/dto/truck-data.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
export interface TruckData {
|
||||
id: number
|
||||
name: string
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
export interface UserData {
|
||||
id: number
|
||||
username: string
|
||||
}
|
||||
|
||||
9
frontend/services/dto/vehicle-data.ts
Normal file
9
frontend/services/dto/vehicle-data.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import type { CarrierData } from '~/services/dto/carrier-data'
|
||||
import type { TruckData } from '~/services/dto/truck-data'
|
||||
|
||||
export interface VehicleData {
|
||||
id: number
|
||||
plate: string
|
||||
carrier?: CarrierData | null
|
||||
truck?: TruckData | null
|
||||
}
|
||||
23
frontend/services/reception-type.ts
Normal file
23
frontend/services/reception-type.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { ReceptionTypeData } from '~/services/dto/reception-type-data'
|
||||
|
||||
export type ReceptionTypeListResponse =
|
||||
| ReceptionTypeData[]
|
||||
| { 'hydra:member'?: ReceptionTypeData[] }
|
||||
|
||||
export async function getReceptionTypeList(): Promise<ReceptionTypeData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<ReceptionTypeListResponse>('reception_types', {}, {
|
||||
toastErrorKey: 'errors.receptionType.list'
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return response['hydra:member']
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
import {useApi} from '~/composables/useApi'
|
||||
import type {ReceptionData} from '~/services/dto/reception-data'
|
||||
import type {ReceptionData, ReceptionPayload} from '~/services/dto/reception-data'
|
||||
import type {WeightData} from '~/services/dto/weight-data'
|
||||
|
||||
export async function getReceptionList() {
|
||||
@@ -16,14 +16,14 @@ export async function getReception(id: number) {
|
||||
})
|
||||
}
|
||||
|
||||
export async function createReception(payload: Partial<ReceptionData> = {}) {
|
||||
export async function createReception(payload: ReceptionPayload = {}) {
|
||||
const api = useApi()
|
||||
return api.post<ReceptionData>('receptions', payload, {
|
||||
toastErrorKey: 'errors.reception.create'
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateReception(id: number, payload: Partial<ReceptionData>) {
|
||||
export async function updateReception(id: number, payload: ReceptionPayload) {
|
||||
const api = useApi()
|
||||
return api.patch<ReceptionData>(`receptions/${id}`, payload, {
|
||||
toastErrorKey: 'errors.reception.update',
|
||||
|
||||
23
frontend/services/supplier.ts
Normal file
23
frontend/services/supplier.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { SupplierData } from '~/services/dto/supplier-data'
|
||||
|
||||
export type SupplierListResponse =
|
||||
| SupplierData[]
|
||||
| { 'hydra:member'?: SupplierData[] }
|
||||
|
||||
export async function getSupplierList(): Promise<SupplierData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<SupplierListResponse>('suppliers', {}, {
|
||||
toastErrorKey: 'errors.supplier.list'
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return response['hydra:member']
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
23
frontend/services/truck.ts
Normal file
23
frontend/services/truck.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { TruckData } from '~/services/dto/truck-data'
|
||||
|
||||
export type TruckListResponse =
|
||||
| TruckData[]
|
||||
| { 'hydra:member'?: TruckData[] }
|
||||
|
||||
export async function getTruckList(): Promise<TruckData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<TruckListResponse>('trucks', {}, {
|
||||
toastErrorKey: 'errors.truck.list'
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return response['hydra:member']
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
23
frontend/services/vehicle.ts
Normal file
23
frontend/services/vehicle.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { VehicleData } from '~/services/dto/vehicle-data'
|
||||
|
||||
export type VehicleListResponse =
|
||||
| VehicleData[]
|
||||
| { 'hydra:member'?: VehicleData[] }
|
||||
|
||||
export async function getVehicleList(): Promise<VehicleData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<VehicleListResponse>('vehicles', {}, {
|
||||
toastErrorKey: 'errors.vehicle.list'
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) {
|
||||
return response
|
||||
}
|
||||
|
||||
if (response && typeof response === 'object' && Array.isArray(response['hydra:member'])) {
|
||||
return response['hydra:member']
|
||||
}
|
||||
|
||||
return []
|
||||
}
|
||||
Reference in New Issue
Block a user