43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
import {useApi} from '~/composables/useApi'
|
|
import type {ShipmentData, ShipmentPayload} from '~/services/dto/shipment-data'
|
|
import type {WeightData} from '~/services/dto/weight-data'
|
|
|
|
export async function getShipmentList(isValid: boolean|null = null) {
|
|
const api = useApi()
|
|
const query = isValid !== null ? { isValid: isValid} : {}
|
|
return api.get<ShipmentData[]>('shipments', query, {
|
|
toastErrorKey: 'errors.shipment.list'
|
|
})
|
|
}
|
|
|
|
export async function getShipment(id: number) {
|
|
const api = useApi()
|
|
return api.get<ShipmentData>(`shipments/${id}`, {}, {
|
|
toastErrorKey: 'errors.shipment.fetch'
|
|
})
|
|
}
|
|
|
|
export async function createShipment(payload: ShipmentPayload = {}) {
|
|
console.log('test')
|
|
const api = useApi()
|
|
return api.post<ShipmentData>('shipments', payload, {
|
|
toastSuccessKey: 'success.shipment.create',
|
|
toastErrorKey: 'errors.shipment.create'
|
|
})
|
|
}
|
|
|
|
export async function updateShipment(id: number, payload: ShipmentPayload) {
|
|
const api = useApi()
|
|
return api.patch<ShipmentData>(`shipments/${id}`, payload, {
|
|
toastErrorKey: 'errors.shipment.update',
|
|
toastSuccessKey: 'success.shipment.update'
|
|
})
|
|
}
|
|
|
|
export async function getWeightShipment(): Promise<WeightData> {
|
|
const api = useApi()
|
|
return api.get<WeightData>('shipments/weigh', {}, {
|
|
toastErrorKey: 'errors.shipment.weigh'
|
|
})
|
|
}
|