Something went wrong. Try again.
A comprehensive digital solution dedicated to bridging the gap between those offering services and those seeking them, providing a centrali… gigwork.co.in
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818import axios from 'axios';import { log } from 'console';
// const BASE_URL = "https://gigworks-server.devmorphix.workers.dev";const BASE_URL = process.env.NEXT_PUBLIC_API_URL;
export const ASSET_BASE_URL = process.env.NEXT_PUBLIC_ASSET_BASE_URL;// export const ASSET_BASE_URL = 'https://pub-3aaf2182691d4cb6b5270a8f14ad704a.r2.dev';
export const fetchBusinessData = async (params:any = {}) => { try { const response = await axios.get( `${BASE_URL}/api/v1/category?hasBusiness=true`, ///api/v1/category?page=1&limit=3 ); return response.data; } catch (error) { console.error('Error fetching business data:', error); throw error; }};
export const fetchBusinessesByCategory = async (categoryId: string) => { try { const response = await axios.get( `${BASE_URL}/api/v1/business?category_id=${categoryId}` ); return response.data; } catch (error) { console.error('Error fetching businesses:', error); throw error; }};
export const fetchBusinessesByslug = async (slug: string) => { try { const response = await axios.get( `${BASE_URL}/api/v1/business/${slug}` ); return response.data; } catch (error) { console.error('Error fetching businesses:', error); throw error; }};
export const fetchBusinessCount = async () => { try { const response = await axios.get( `${BASE_URL}/api/v1/business/count`
); return response.data; } catch (error) { console.error('Error fetching businesses:', error); throw error; }};
interface GetURLParams { type: string; category: 'identity' | 'avatar' | 'license' | 'banner' | 'media'; // Added 'media' as valid category}
// Update the response interface to match the expected structureinterface GetURLResponse { data: { presignedUrl: string; assetPath: string; }; presignedUrl: string; // Add this assetpath: string; // Add this}
export const GetURL = async (params: GetURLParams): Promise<GetURLResponse> => { try { const response = await axios.get( `${BASE_URL}/api/v1/media/get-presigned-url`, { params: { type: params.type, category: params.category } } ); // Transform the response to match both interfaces return { ...response.data, presignedUrl: response.data.data.presignedUrl, assetpath: response.data.data.assetPath }; } catch (error) { console.error('Error getting presigned URL:', error); throw error; }};
// Add BusinessProfile interface at the top of the fileinterface BusinessProfile { id: string; name: string; description: string; email: string; phone: string | null; address: string; city: string; state: string; country: string; operating_hours: { [key: string]: string; }; socials: { website?: string; facebook?: string; instagram?: string; twitter?: string; linkedin?: string; youtube?: string; [key: string]: string | undefined; }; avatar: string; banner: string; type: string; additional_services: string; gstin: string; [key: string]: any;}
// export const GetURL = async (category: 'avatar' | 'banner' | 'license' | 'identity', fileType: string) => {// try {// // Check if API URL is defined// if (!process.env.NEXT_PUBLIC_API_URL) {// throw new Error('API URL is not defined');// }
// const response = await axios.get(// `${process.env.NEXT_PUBLIC_API_URL}/api/v1/media/get-presigned-url`,// {// params: {// type: fileType,// category: category// }// }// );// return response.data;// } catch (error: any) {// // Better error handling// if (error.code === 'ERR_NAME_NOT_RESOLVED') {// console.error('API URL could not be resolved. Check your environment variables and API server.');// }// throw error;// }// };
export const uploadToPresignedUrl = async (presignedUrl: string, file: File) => { try { // console.log('Uploading to:', presignedUrl); // console.log('File details:', { // name: file.name, // type: file.type, // size: file.size // });
const response = await axios.put(presignedUrl, file, { headers: { 'Content-Type': file.type, }, });
return true; } catch (error) { console.error('Error uploading file:', { error, url: presignedUrl.split('?')[0], fileInfo: { name: file.name, type: file.type, size: file.size } }); throw error; }};
export const UserRegister = async (data: any) => { try { const response = await axios.post( `${BASE_URL}/auth/register`, data ); return response.data; } catch (error) { console.error('Error fetching businesses:', error); throw error; }};
export const UserLogin = async (data: any) => { try { const response = await axios.post( `${BASE_URL}/auth/login`, data ); return response; } catch (error) { console.error('Error during login:', error); throw error; }};
export const VerifyLoginOTP = async (data: any) => { try { const response = await axios.post( `${BASE_URL}/auth/verify/login`, data ); return response; } catch (error) { console.error('Error verifying OTP:', error); throw error; }};
export const CreatePartner = async (data: any) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
const response = await axios.post( `${BASE_URL}/api/v1/partner`, data, { headers: { Authorization: `Bearer ${token}` } } ); return response.data; } catch (error) { console.error('Error verifying OTP:', error); throw error; }};
export const BisunessMedia = async (data: any) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
const response = await axios.post( `${BASE_URL}/api/v1/media`, data, { headers: { Authorization: `Bearer ${token}` } } ); return response.data; } catch (error) { console.error('Error verifying OTP:', error); throw error; }};
export const DeleteLicense = async (profileId: string, licenseId: string) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
console.log('Deleting license:', profileId, licenseId);
const response = await axios.delete(`${BASE_URL}/api/v1/business/${profileId}/license/${licenseId}`, { headers: { Authorization: `Bearer ${token}` } }); console.log(response.data); return response.data; } catch (error) { console.error('Error in deleting license:', error); throw error; }};
export const AddLicense = async (profileId: string, licenseData: { url: string, number: string, type_id: string }) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('Authorization token not found'); }
const response = await axios.post(`${BASE_URL}/api/v1/business/${profileId}/license`, licenseData, { headers: { Authorization: `Bearer ${token}` } });
console.log('Add response:', response.data); return response.data; } catch (error) { if (axios.isAxiosError(error)) { console.error('Error in adding license:', error.response ? error.response.data : error.message); } else { console.error('Error in adding license:', error); } throw error; }};
export const updatePartner = async (data: any) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1]; console.log(data); const response = await axios.patch( `${BASE_URL}/api/v1/partner`, data, { headers: { Authorization: `Bearer ${token}` } } ); console.log(response.data); return response.data; } catch (error) { console.error('Error verifying OTP:', error); throw error; }}
export const GetPartner = async () => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
const response = await axios.get( `${BASE_URL}/api/v1/partner`, { headers: { Authorization: `Bearer ${token}` } } ); return response.data; } catch (error) { console.error('Error verifying OTP:', error); throw error; }};
export const GetPartnerAnalytics = async (start?: string, end?: string) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
const response = await axios.get( `${BASE_URL}/api/v1/partner/analytics`, { headers: { Authorization: `Bearer ${token}` }, params: { start, end } } ); return response.data; } catch (error) { console.error('Error fetching analytics:', error); throw error; }};
export const VerifyRegisterOTP = async (data: any) => { try { const response = await axios.post( `${BASE_URL}/auth/verify/register`, data ); return response; } catch (error) { console.error('Error verifying OTP:', error); throw error; }};
export const UserLogout = async (data: any) => { try {
const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('No token provided'); }
const response = await axios.post( `${BASE_URL}/auth/logout`, data, { headers: { Authorization: `Bearer ${token}` }, } ); return response; } catch (error) { console.error('Error in logout:', error); throw error; }};
interface BusinessPayload { user: { name: string phone: string } profile: { name: string slug: string description: string email: string website: string category_id: string sub_category_id: string address: string city: string state: string zip: string type: string } payment: { amount: number payment_status: string }}
export const createBusiness = async (data: BusinessPayload) => { try { const response = await axios.post( `${BASE_URL}/api/v1/business`,
data ) return response.data } catch (error) { console.error('Error creating business:', error) throw error }}
export const getPaymentLink = async (data: { profile_id: string, mode: string, type: string }) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('No token provided'); }
const response = await axios.post( `${BASE_URL}/api/v1/payment/initiate`, data, { headers: { Authorization: `Bearer ${token}` } } ); return response.data; } catch (error) { console.error('Error fetching payment link:', error); throw error; }}
export const fetchsubCategoryByCategory = async (categoryId: string) => { try { const response = await axios.get( `${BASE_URL}/api/v1/category/${categoryId}` ); return response.data; } catch (error) { console.error('Error fetching subcategory:', error); throw error; }}
export const fetchDataBySubCategory = async (subCategoryId: string) => { try { const response = await axios.get( `${BASE_URL}/api/v1/sub_category/${subCategoryId}` ); return response.data; } catch (error) { console.error('Error fetching subcategory:', error); throw error; }}
export const checkSlug = async (value: string) => { try { const response = await axios.get( `${BASE_URL}/api/v1/business/slug/check`, { params: { value } } ); return response.data; } catch (error) { console.error('Error fetching businesses:', error); throw error; }}
export const fetchLicenseData = async () => { try { const response = await axios.get( `${BASE_URL}/api/v1/license` ); return response.data; } catch (error) { console.error('Error fetching license data:', error); throw error; }}
export const createBusinessMedia = async (businessId: string, data: { url: string, type: string, description: string }) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
// console.log(typeof data); // console.log(data); const response = await axios.post( `${BASE_URL}/api/v1/business/${businessId}/media`, data, { headers: { Authorization: `Bearer ${token}` } } ); return response.data; } catch (error) { console.error('Error creating media:', error); throw error; }};
export const deletebusinessMedia = async (businessId: string, mediaId: string) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
const response = await axios.delete( `${BASE_URL}/api/v1/business/${businessId}/media/${mediaId}`, { headers: { Authorization: `Bearer ${token}` } } ); return response.data; } catch (error) { console.error('Error deleting media:', error); throw error; }}
export const updateBusiness = async (businessId: string, updateData: Record<string, any>) => { try { // console.log("Sending update request for business:", businessId); // console.log("Update data:", updateData);
const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('No token provided'); }
const response = await axios.patch( `${BASE_URL}/api/v1/business/${businessId}`, updateData, { headers: { Authorization: `Bearer ${token}` } } );
// console.log("Update response:", response.data); return response.data; } catch (error) { console.error("Error updating business:", error); throw error; }};
export const createLicense = async (businessId: string, licenseData: { url: string; number: string; type_id: string;}) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('No token provided'); }
const response = await axios.post( `${BASE_URL}/api/v1/business/${businessId}/license`, licenseData, { headers: { Authorization: `Bearer ${token}` } } );
return response.data; } catch (error) { console.error("Error creating license:", error); throw error; }};
// location search
export const fetchServices = async (query: string) => { try { console.log(query); const response = await axios.get( `${BASE_URL}/api/v1/sub_category_option?search=${query}` ); return response.data; } catch (error) { console.error('Error fetching services:', error); throw error; }}
// fetch location based services
export const searchBusinesses = async ( service: string, coordinates: { lat: string; lon: string }) => { try { const response = await axios.post( `${BASE_URL}/api/v1/bot/request_service`, { service }, { headers: { 'Content-Type': 'application/json', 'X-User-Location': JSON.stringify({ latitude: coordinates.lat, longitude: coordinates.lon }) } } ); console.log(response.data); return response.data; } catch (error) { console.error('Error searching businesses:', error); throw error; }};
export const submitContactForm = async (formData: { firstName: string; lastName: string; email: string; phone: string; message: string; turnstileToken: string;}) => { try { const response = await axios.post( `${BASE_URL}/api/v1/bot/send_email`, { ...formData } ); return response.data; } catch (error) { console.error('Error submitting contact form:', error); throw error; }}
export const fetchCorrdinates = async (url: string ) =>{ console.log(url); try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('No token provided'); }
const data = { url: url }; const response = await axios.post(`${BASE_URL}/api/v1/location`, data,{ headers: { Authorization: `Bearer ${token}` } }) console.log(response.data.data); return response.data; } catch (error) { console.error('Error fetching coordinates:', error); throw error; }
}
export const checkPaymentStatus = async (transaction_id: string) => { try { const token = document.cookie .split('; ') .find(row => row.startsWith('token=')) ?.split('=')[1];
if (!token) { throw new Error('No token provided'); }
const response = await axios.get( `${BASE_URL}/api/v1/payment/status`, { headers: { Authorization: `Bearer ${token}` }, params: { transaction_id } } ); return response.data; } catch (error) { console.error('Error checking payment status:', error); throw error; }}