You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
44 lines
1.3 KiB
44 lines
1.3 KiB
import {setPostJoke} from "../actions/CustomJoke";
|
|
import {SampleJoke} from "../../model/SampleJoke";
|
|
import {setJokesList} from "../actions/SampleAction";
|
|
import {getList} from "./GetThunk";
|
|
|
|
export const setItem = <TItem>(
|
|
uri: string,
|
|
type : string,
|
|
setup : string,
|
|
punchline : string
|
|
) => {
|
|
return async dispatch => {
|
|
try {
|
|
// @ts-ignore
|
|
const response = await fetch(uri, {
|
|
method: 'POST',
|
|
headers: {
|
|
Accept: "application/json",
|
|
"Content-Type": 'application/json',
|
|
},
|
|
body: JSON.stringify(
|
|
{
|
|
type: type,
|
|
setup: setup,
|
|
punchline: punchline
|
|
}
|
|
)
|
|
});
|
|
const data = await response.json();
|
|
dispatch(setPostJoke(data));
|
|
if (response.ok) {
|
|
console.log('Envoie ok de custom joke')
|
|
} else {
|
|
console.log('Erreur lors de la requête POST');
|
|
}
|
|
} catch (error) {
|
|
console.log('Erreur :', error);
|
|
}
|
|
};
|
|
};
|
|
|
|
export const postCustomJoke = (joke, downgrade, category) => {
|
|
return setItem('https://iut-weather-api.azurewebsites.net/jokes', joke, downgrade, category)
|
|
} |