58 lines
1.2 KiB
TypeScript
58 lines
1.2 KiB
TypeScript
/* eslint-disable import/no-unresolved */
|
|
/* eslint-disable import/order */
|
|
|
|
|
|
import { sageService } from '@/service/sageService';
|
|
import { Fournisseur, FournisseurRequest, FournisseurUpdateRequest } from '@/types/fournisseurType';
|
|
import { createAsyncThunk } from '@reduxjs/toolkit';
|
|
|
|
|
|
/**
|
|
* get all fournisseurs
|
|
*/
|
|
export const getFournisseurs = createAsyncThunk(
|
|
'fournisseur/getFournisseurs',
|
|
async (): Promise<Fournisseur[]> => {
|
|
try {
|
|
return await sageService.getFournisseurs();
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
* add fournisseur
|
|
*/
|
|
export const addFournisseur = createAsyncThunk(
|
|
'fournisseur/addFournisseur',
|
|
async (data: FournisseurRequest): Promise<Fournisseur> => {
|
|
try {
|
|
return await sageService.addFournisseur(data);
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|
|
);
|
|
|
|
|
|
|
|
|
|
/**
|
|
* update fournisseur
|
|
*/
|
|
export const updateFournisseur = createAsyncThunk(
|
|
'fournisseur/updateFournisseur',
|
|
async (
|
|
{ numero, data }: { numero: string; data: FournisseurUpdateRequest }
|
|
): Promise<Fournisseur> => {
|
|
try {
|
|
return await sageService.updateFournisseur(numero, data);
|
|
} catch (err) {
|
|
throw err;
|
|
}
|
|
}
|
|
);
|