Skip to content

Commit

Permalink
Update api.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
keyskull authored Jun 27, 2024
1 parent 9a0cb07 commit 01639a5
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions lib/api.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const apiUrl = process.env.NEXT_PUBLIC_API_BASE_URL;
const API_BASE_URL = '/api/ad';
const API_CHANNEL_URL = '/api/channel';
const API_CAMPAIGN_URL = API_BASE_URL + '/campaign';
const API_GROUP_URL = API_BASE_URL + '/group';

export const createAdvertisement = async (adData: any) => {
const data = JSON.stringify(adData);
const response = await fetch(`${apiUrl}${API_BASE_URL}/create`, {
const response = await fetch(`${API_BASE_URL}/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -17,7 +16,7 @@ export const createAdvertisement = async (adData: any) => {
};

export const updateAdvertisement = async (adData: any) => {
const response = await fetch(`${apiUrl}${API_BASE_URL}/update`, {
const response = await fetch(`${API_BASE_URL}/update`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Expand All @@ -28,39 +27,39 @@ export const updateAdvertisement = async (adData: any) => {
};

export const deleteAd = async (ad_id: string) => {
const response = await fetch(`${apiUrl}${API_BASE_URL}/delete?id=${ad_id}`, {
const response = await fetch(`${API_BASE_URL}/delete?id=${ad_id}`, {
method: 'DELETE',
});
return response.json();
};

export const publishAd = async (ad_id: string) => {
const response = await fetch(`${apiUrl}${API_BASE_URL}/publish?ad_id=${ad_id}`, {
const response = await fetch(`${API_BASE_URL}/publish?ad_id=${ad_id}`, {
method: 'POST',
});
return response.json();
};

export const unpublishAd = async (ad_id: string) => {
const response = await fetch(`${apiUrl}${API_BASE_URL}/unpublish?ad_id=${ad_id}`, {
const response = await fetch(`${API_BASE_URL}/unpublish?ad_id=${ad_id}`, {
method: 'POST',
});
return response.json();
};


export const fetchAd = async (id: string) => {
const response = await fetch(`${apiUrl}${API_BASE_URL}/${id}`);
const response = await fetch(`${API_BASE_URL}/${id}`);
return response.json();
};

export const fetchAds = async () => {
const response = await fetch(`${apiUrl}${API_BASE_URL}/list`);
const response = await fetch(`${API_BASE_URL}/list`);
return response.json();
};

export const fetchChannels = async () => {
const response = await fetch(`${apiUrl}${API_CHANNEL_URL}/list`);
const response = await fetch(`${API_CHANNEL_URL}/list`);
return response.json();
};

Expand All @@ -71,7 +70,7 @@ export const fetchImage = async (imageId:string) => {

export const createCampaign = async (campaignData: any) => {
const data = JSON.stringify(campaignData);
const response = await fetch(`${apiUrl}${API_BASE_URL}/campaign/create`, {
const response = await fetch(`${API_BASE_URL}/campaign/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -82,7 +81,7 @@ export const createCampaign = async (campaignData: any) => {
};

export const updateCampaign = async (campaignData: any) => {
const response = await fetch(`${apiUrl}${API_CAMPAIGN_URL}/campaign/update`, {
const response = await fetch(`${API_CAMPAIGN_URL}/campaign/update`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Expand All @@ -93,25 +92,25 @@ export const createCampaign = async (campaignData: any) => {
};

export const deleteCampaign = async (id: string) => {
const response = await fetch(`${apiUrl}${API_CAMPAIGN_URL}/delete?id=${id}`, {
const response = await fetch(`${API_CAMPAIGN_URL}/delete?id=${id}`, {
method: 'DELETE',
});
return response.json();
};

export const fetchCampaign = async (id: string) => {
const response = await fetch(`${apiUrl}${API_CAMPAIGN_URL}/${id}`);
const response = await fetch(`${API_CAMPAIGN_URL}/${id}`);
return response.json();
};

export const fetchCampaignList = async () => {
const response = await fetch(`${apiUrl}${API_CAMPAIGN_URL}/list`);
const response = await fetch(`${API_CAMPAIGN_URL}/list`);
return response.json();
};

export const createGroup = async (groupData: any) => {
const data = JSON.stringify(groupData);
const response = await fetch(`${apiUrl}${API_GROUP_URL}/create`, {
const response = await fetch(`${API_GROUP_URL}/create`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Expand All @@ -122,7 +121,7 @@ export const createGroup = async (groupData: any) => {
};

export const updateGroup = async (groupData: any) => {
const response = await fetch(`${apiUrl}${API_GROUP_URL}/update`, {
const response = await fetch(`${API_GROUP_URL}/update`, {
method: 'PATCH',
headers: {
'Content-Type': 'application/json',
Expand All @@ -133,18 +132,18 @@ export const createGroup = async (groupData: any) => {
};

export const deleteGroup = async (id: string) => {
const response = await fetch(`${apiUrl}${API_GROUP_URL}/delete?id=${id}`, {
const response = await fetch(`${API_GROUP_URL}/delete?id=${id}`, {
method: 'DELETE',
});
return response.json();
};

export const fetchGroup = async (id: string) => {
const response = await fetch(`${apiUrl}${API_GROUP_URL}/${id}`);
const response = await fetch(`${API_GROUP_URL}/${id}`);
return response.json();
};

export const fetchGroupList = async (campaignId: string) => {
const response = await fetch(`${apiUrl}${API_GROUP_URL}/list?campaignId=${campaignId}`);
const response = await fetch(`${API_GROUP_URL}/list?campaignId=${campaignId}`);
return response.json();
};
};

0 comments on commit 01639a5

Please sign in to comment.