feat : admin fournisseurs creation et modif (WIP)
This commit is contained in:
35
frontend/services/address.ts
Normal file
35
frontend/services/address.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { useApi } from '~/composables/useApi'
|
||||
import type { AddressData } from '~/services/dto/address-data'
|
||||
export interface AddressPayload {
|
||||
label: string
|
||||
street: string
|
||||
street2?: string | null
|
||||
postalCode: string
|
||||
city: string
|
||||
countryCode: string
|
||||
}
|
||||
|
||||
export interface AddressData extends AddressPayload {
|
||||
id: number
|
||||
}
|
||||
|
||||
export async function createAddress(
|
||||
payload: AddressPayload
|
||||
): Promise<AddressData> {
|
||||
const api = useApi()
|
||||
|
||||
return await api.post<AddressData>('addresses', payload, {
|
||||
toastErrorKey: 'errors.address.create',
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateAddress(
|
||||
id: number,
|
||||
payload: AddressPayload
|
||||
): Promise<AddressData> {
|
||||
const api = useApi()
|
||||
|
||||
return await api.patch<AddressData>(`addresses/${id}`, payload, {
|
||||
toastErrorKey: 'errors.address.update',
|
||||
})
|
||||
}
|
||||
@@ -6,13 +6,14 @@ export interface AddressData {
|
||||
postalCode: string
|
||||
city: string
|
||||
countryCode: string
|
||||
fullAddress?: string
|
||||
}
|
||||
|
||||
export interface AddressFormData {
|
||||
id?: number | null
|
||||
label: string
|
||||
street: string
|
||||
street2?: string
|
||||
street2?: string | null
|
||||
postalCode: string
|
||||
city: string
|
||||
country: string
|
||||
countryCode: string
|
||||
}
|
||||
|
||||
@@ -1,12 +1,15 @@
|
||||
import type { AddressFormData } from '~/services/dto/address-data'
|
||||
import type { AddressFormData } from "~/services/dto/address-data"
|
||||
|
||||
export type SupplierAddresses = AddressFormData[] | string[]
|
||||
|
||||
export interface SupplierData {
|
||||
id: number
|
||||
name: string
|
||||
email?: string | null
|
||||
phone?: string | null
|
||||
addresses: AddressFormData[]
|
||||
addresses: SupplierAddresses
|
||||
}
|
||||
|
||||
export interface SupplierFormData {
|
||||
name: string
|
||||
email?: string
|
||||
@@ -18,8 +21,5 @@ export type SupplierPayload = {
|
||||
name: string
|
||||
email?: string | null
|
||||
phone?: string | null
|
||||
street?: string | null
|
||||
city?: string | null
|
||||
postalCode?: string | null
|
||||
country?: string | null
|
||||
addresses: string[]
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export type SupplierListResponse =
|
||||
export async function getSupplierList(): Promise<SupplierData[]> {
|
||||
const api = useApi()
|
||||
const response = await api.get<SupplierListResponse>("suppliers", {}, {
|
||||
toastErrorKey: "errors.supplier.list"
|
||||
toastErrorKey: "errors.supplier.list",
|
||||
})
|
||||
|
||||
if (Array.isArray(response)) return response
|
||||
@@ -20,23 +20,23 @@ export async function getSupplierList(): Promise<SupplierData[]> {
|
||||
|
||||
export async function getSupplier(id: number): Promise<SupplierData> {
|
||||
const api = useApi()
|
||||
return api.get<SupplierData>(`supplier/${id}`, {}, {
|
||||
toastErrorKey: "errors.supplier.fetch"
|
||||
return api.get<SupplierData>(`suppliers/${id}`, {}, {
|
||||
toastErrorKey: "errors.supplier.fetch",
|
||||
})
|
||||
}
|
||||
|
||||
export async function updateSupplier(id: number, payload: SupplierPayload): Promise<SupplierData> {
|
||||
const api = useApi()
|
||||
return api.patch<SupplierData>(`supplier/${id}`, payload, {
|
||||
return api.patch<SupplierData>(`suppliers/${id}`, payload, {
|
||||
toastErrorKey: "errors.supplier.update",
|
||||
toastSuccessKey: "success.supplier.update"
|
||||
toastSuccessKey: "success.supplier.update",
|
||||
})
|
||||
}
|
||||
|
||||
export async function createSupplier(payload: SupplierPayload): Promise<SupplierData> {
|
||||
const api = useApi()
|
||||
return api.post<SupplierData>("supplier", payload, {
|
||||
return api.post<SupplierData>("suppliers", payload, {
|
||||
toastErrorKey: "errors.supplier.create",
|
||||
toastSuccessKey: "success.supplier.create"
|
||||
toastSuccessKey: "success.supplier.create",
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user