virtual tour sidebar info
This commit is contained in:
@@ -11,6 +11,8 @@ const aparmentsApi =
|
||||
const searchApartmentApi =
|
||||
"https://www.zohoapis.com/crm/v6/Apartments/search?fields=Floor,Property_Status,Project_Name,Balcony_Area_Sqft,Unit_Type,Suite_Area_Sqft,No_Of_Bedrooms,Total_Area_Sqft,No_of_Bathrooms,Property_Name,Unit_View,Balcony_Area_Sqft,Unit_No,Suite_Area_Sqft";
|
||||
|
||||
const searchCurrentApartmentApi = "https://www.zohoapis.com/crm/v6/Apartments";
|
||||
|
||||
export {
|
||||
updateAccessTokenApi,
|
||||
aparmentsApi,
|
||||
@@ -19,4 +21,5 @@ export {
|
||||
clientSecret,
|
||||
grantType,
|
||||
searchApartmentApi,
|
||||
searchCurrentApartmentApi,
|
||||
};
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@ import path from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import morgan from "morgan";
|
||||
import apartmentsRoute from "./routes/apartments.js";
|
||||
import apartmentRoute from "./routes/apartment.js";
|
||||
import updateAccessToken from "./routes/zohoAccessToken.js";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
@@ -24,7 +25,7 @@ app.use(json());
|
||||
app.use(morgan("combined", { stream: accessLogStream }));
|
||||
|
||||
app.use("/apartments", apartmentsRoute);
|
||||
app.use("/apartments/:id", apartmentsRoute);
|
||||
app.use("/apartment", apartmentRoute);
|
||||
app.use("/updateAccessToken", updateAccessToken);
|
||||
|
||||
app.listen(port, () => {
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { Router } from "express";
|
||||
import { searchCurrentApartmentApi } from "../consts.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
import { IApartment } from "../types/apartment.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
function ConvertApartmentRes(apartment: IApartment) {
|
||||
const convertedApartment: IApartment = {
|
||||
Balcony_Area_Sqft: apartment.Balcony_Area_Sqft,
|
||||
Floor: apartment.Floor,
|
||||
Property_Status: apartment.Property_Status,
|
||||
Unit_Type: apartment.Unit_Type,
|
||||
Project_Name: apartment.Project_Name,
|
||||
Suite_Area_Sqft: apartment.Suite_Area_Sqft,
|
||||
No_Of_Bedrooms: apartment.No_Of_Bedrooms,
|
||||
Unit_No: apartment.Unit_No,
|
||||
id: apartment.id,
|
||||
Total_Area_Sqft: apartment.Total_Area_Sqft,
|
||||
No_of_Bathrooms: apartment.No_of_Bathrooms,
|
||||
Property_Name: apartment.Property_Name,
|
||||
Unit_View: apartment.Unit_View,
|
||||
};
|
||||
|
||||
return convertedApartment;
|
||||
}
|
||||
|
||||
router.get("/:id", async (req, res) => {
|
||||
const accessToken = req?.headers?.authorization;
|
||||
const { id } = req.params;
|
||||
|
||||
try {
|
||||
const url = `${searchCurrentApartmentApi}/${id}`;
|
||||
const requestHeaders: HeadersInit = new Headers();
|
||||
requestHeaders.set("Authorization", `${accessToken}`);
|
||||
const response = await fetch(url, {
|
||||
headers: requestHeaders,
|
||||
});
|
||||
|
||||
if (response.status === 404) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "Квартира не найдена", code: 404 });
|
||||
}
|
||||
if (response.status === 401) {
|
||||
return res
|
||||
.status(401)
|
||||
.json({ message: "Неправильный токен или токен устарел", code: 401 });
|
||||
}
|
||||
const result = await response.json();
|
||||
|
||||
const convertedApartment = ConvertApartmentRes(result.data[0]);
|
||||
|
||||
return res.status(200).json({
|
||||
message: "ok",
|
||||
apartment: convertedApartment,
|
||||
code: 200,
|
||||
});
|
||||
} catch (error) {
|
||||
if (
|
||||
(error as Error).message === "invalid oauth token" ||
|
||||
(error as Error).message === "INVALID_TOKEN"
|
||||
) {
|
||||
console.log("error", error);
|
||||
logger.error(error);
|
||||
|
||||
return res
|
||||
.status(401)
|
||||
.json({ message: "Неправильный токен или токен устарел", code: 401 });
|
||||
}
|
||||
if (
|
||||
(error as Error).message ===
|
||||
"Please check if the URL trying to access is a correct one"
|
||||
) {
|
||||
return res
|
||||
.status(404)
|
||||
.json({ message: "Квартира не найдена", code: 404 });
|
||||
}
|
||||
console.log("error", error);
|
||||
logger.error(error);
|
||||
|
||||
return res.status(500).json({ message: "Server Error", code: 500 });
|
||||
}
|
||||
});
|
||||
|
||||
const apartmentRoute = router;
|
||||
|
||||
export default apartmentRoute;
|
||||
@@ -1,22 +1,7 @@
|
||||
import { Router } from "express";
|
||||
import { aparmentsApi, searchApartmentApi } from "../consts.js";
|
||||
import { aparmentsApi, searchCurrentApartmentApi } from "../consts.js";
|
||||
import { logger } from "../utils/logger.js";
|
||||
|
||||
interface IApartment {
|
||||
Floor: number;
|
||||
Property_Status: string;
|
||||
Unit_Type: string;
|
||||
Project_Name: string;
|
||||
Suite_Area_Sqft: number;
|
||||
Balcony_Area_Sqft: number;
|
||||
No_Of_Bedrooms: number;
|
||||
Unit_No: string;
|
||||
id: string;
|
||||
Total_Area_Sqft: number;
|
||||
No_of_Bathrooms: number;
|
||||
Property_Name: string;
|
||||
Unit_View: string;
|
||||
}
|
||||
import { IApartment } from "../types/apartment.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -276,54 +261,6 @@ router.get("/", async (req, res) => {
|
||||
console.log("error", error);
|
||||
}
|
||||
});
|
||||
// router.get("/:id", async (req, res) => {
|
||||
// const accessToken = req?.headers?.authorization;
|
||||
// const {id} = req.params;
|
||||
|
||||
// try {
|
||||
// const response = await fetch(`${aparmentsApi}&page=${page}&per_page=200`, {
|
||||
// headers: {
|
||||
// Authorization: accessToken,
|
||||
// },
|
||||
// });
|
||||
|
||||
// if (!accessToken)
|
||||
// return res
|
||||
// .status(401)
|
||||
// .json({ message: "Отсутсвует access token", code: 401 });
|
||||
|
||||
// try {
|
||||
|
||||
// res.status(200).json({
|
||||
// message: "ok",
|
||||
// apartments: slicedApartments,
|
||||
// code: 200,
|
||||
// });
|
||||
|
||||
// return;
|
||||
// } catch (error) {
|
||||
// if (
|
||||
// (error as Error).message === "invalid oauth token" ||
|
||||
// (error as Error).message === "INVALID_TOKEN"
|
||||
// ) {
|
||||
// console.log("error", error);
|
||||
// logger.error(error);
|
||||
|
||||
// return res
|
||||
// .status(401)
|
||||
// .json({ message: "Неправильный токен или токен устарел", code: 401 });
|
||||
// }
|
||||
|
||||
// console.log("error", error);
|
||||
// logger.error(error);
|
||||
|
||||
// return res.status(500).json({ message: "Server Error", code: 500 });
|
||||
// }
|
||||
// } catch (error) {
|
||||
// logger.error(error);
|
||||
// console.log("error", error);
|
||||
// }
|
||||
// });
|
||||
|
||||
const apartmentsRoute = router;
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
interface IApartment {
|
||||
Floor: number;
|
||||
Property_Status: string;
|
||||
Unit_Type: string;
|
||||
Project_Name: string;
|
||||
Suite_Area_Sqft: number;
|
||||
Balcony_Area_Sqft: number;
|
||||
No_Of_Bedrooms: number;
|
||||
Unit_No: string;
|
||||
id: string;
|
||||
Total_Area_Sqft: number;
|
||||
No_of_Bathrooms: number;
|
||||
Property_Name: string;
|
||||
Unit_View: string;
|
||||
}
|
||||
|
||||
export type { IApartment };
|
||||
Reference in New Issue
Block a user