Add github actions, refactor seed and beer p likes

This commit is contained in:
Aaron William Po
2023-02-09 02:23:18 -05:00
parent d8ae58844c
commit c2eb4d1371
10 changed files with 299 additions and 483 deletions

View File

@@ -0,0 +1,30 @@
import BeerPostQueryResult from '@/services/BeerPost/schema/BeerPostQueryResult';
import APIResponseValidationSchema from '@/validation/APIResponseValidationSchema';
const sendLikeRequest = async (beerPost: BeerPostQueryResult) => {
const response = await fetch(`/api/beers/${beerPost.id}/like`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: '',
});
if (!response.ok) {
throw new Error('Something went wrong.');
}
const data = await response.json();
const parsed = APIResponseValidationSchema.safeParse(data);
if (!parsed.success) {
throw new Error('Invalid API response.');
}
const { success, message } = parsed.data;
return { success, message };
};
export default sendLikeRequest;