50 lines
1.5 KiB
TypeScript
50 lines
1.5 KiB
TypeScript
let url_Backend_dwinzoMajor = "http://192.168.0.110:3503";
|
|
//Login Api
|
|
export const createCamera = async (userId:string, position:Object) => {
|
|
try {
|
|
const response = await fetch(`${url_Backend_dwinzoMajor}/api/v1/createCamera`, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({ userId, position }),
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error("Failed to create Camera");
|
|
}
|
|
|
|
const result = await response.json();
|
|
return result;
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
throw new Error(error.message); // Now TypeScript knows `error` is an instance of `Error`
|
|
} else {
|
|
throw new Error("An unknown error occurred");
|
|
}
|
|
}
|
|
};
|
|
|
|
export const getCamera = async (userId:string) => {
|
|
try {
|
|
const response = await fetch(`${url_Backend_dwinzoMajor}/api/v1/getCamera/${userId}`, {
|
|
method: "GET",
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
});
|
|
|
|
if (!response.ok) {
|
|
throw new Error("Failed to get Camera");
|
|
}
|
|
|
|
const result = await response.json();
|
|
return result;
|
|
} catch (error) {
|
|
if (error instanceof Error) {
|
|
throw new Error(error.message); // Now TypeScript knows `error` is an instance of `Error`
|
|
} else {
|
|
throw new Error("An unknown error occurred");
|
|
}
|
|
}
|
|
}; |