All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [x] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [x] CHANGELOG modifié Reviewed-on: #42 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
30 lines
935 B
TypeScript
30 lines
935 B
TypeScript
import { useApi } from '~/composables/useApi'
|
|
import type { BovineData, BovinePayload } from '~/services/dto/bovine-data'
|
|
|
|
export async function createBovine(payload: BovinePayload) {
|
|
const api = useApi()
|
|
return api.post<BovineData>('bovines', payload, {
|
|
headers: { 'Content-Type': 'application/ld+json' },
|
|
toastErrorKey: 'errors.bovine.create',
|
|
toastSuccessKey: 'success.bovine.create'
|
|
})
|
|
}
|
|
|
|
export async function createBovines(nationalNumbers: string[]): Promise<{ created: BovineData[]; errors: string[] }> {
|
|
const created: BovineData[] = []
|
|
const errors: string[] = []
|
|
|
|
for (const nationalNumber of nationalNumbers) {
|
|
try {
|
|
const bovine = await createBovine({ nationalNumber })
|
|
if (bovine) {
|
|
created.push(bovine)
|
|
}
|
|
} catch {
|
|
errors.push(nationalNumber)
|
|
}
|
|
}
|
|
|
|
return { created, errors }
|
|
}
|