RecentlyViewed API, view API, home page file added
This commit is contained in:
7
src/api-server/Routes/homepageRoutes.ts
Normal file
7
src/api-server/Routes/homepageRoutes.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import * as express from "express";
|
||||
import { recentDataController } from "../controller/home/recentsControllers.ts";
|
||||
|
||||
const homePageRouter = express.Router();
|
||||
|
||||
homePageRouter.get("/RecentlyViewed/:userId/:organization", recentDataController);
|
||||
export default homePageRouter;
|
||||
@@ -21,11 +21,12 @@ import widget3dRoutes from "./Routes/widget3dRoutes.ts";
|
||||
import productRouter from "./Routes/productRoutes.ts";
|
||||
import projectRouter from "./Routes/projectRoutes.ts";
|
||||
import trashRouter from "./Routes/trashRoutes.ts";
|
||||
import homePageRouter from "./Routes/homepageRoutes.ts";
|
||||
// import productFlowRoutes from "./Routes/productFlowRouts.ts";
|
||||
|
||||
const app = express();
|
||||
app.use(cors());
|
||||
// const allowedOriginsDev = [
|
||||
// const allowedOriginsDev = [
|
||||
// "http://localhost:3000",
|
||||
// "http://192.168.0.183:8200",
|
||||
// "http://192.168.0.101:8200",
|
||||
@@ -45,11 +46,11 @@ app.use(cors());
|
||||
// ) {
|
||||
// return callback(null, true);
|
||||
// }
|
||||
|
||||
|
||||
// if (typeof allowedOrigin === "string" && origin === allowedOrigin) {
|
||||
// return callback(null, true);
|
||||
// }
|
||||
|
||||
|
||||
// return callback(new Error("Not allowed by CORS"));
|
||||
// },
|
||||
// credentials: true
|
||||
@@ -57,7 +58,7 @@ app.use(cors());
|
||||
|
||||
app.use(express.json({ limit: "50mb" }));
|
||||
app.use(
|
||||
express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 })
|
||||
express.urlencoded({ limit: "50mb", extended: true, parameterLimit: 50000 })
|
||||
);
|
||||
dotenv.config();
|
||||
app.get("/", (req, res) => {
|
||||
@@ -87,6 +88,7 @@ app.use("/api/v2", templateRoutes);
|
||||
app.use("/api/v2", widget3dRoutes);
|
||||
app.use("/api/v2", productRouter);
|
||||
// app.use("/api/v2", productFlowRoutes);
|
||||
app.use("/api/v1",projectRouter)
|
||||
app.use("/api/v1",trashRouter)
|
||||
app.use("/api/v1", projectRouter);
|
||||
app.use("/api/v1", trashRouter);
|
||||
app.use("/api/v1", homePageRouter);
|
||||
export default app;
|
||||
|
||||
46
src/api-server/controller/home/recentsControllers.ts
Normal file
46
src/api-server/controller/home/recentsControllers.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Request, Response } from "express";
|
||||
import { RecentlyAdded } from "../../../shared/services/home/recentDatasService.ts";
|
||||
|
||||
export const recentDataController = async (
|
||||
req: Request,
|
||||
res: Response
|
||||
): Promise<void> => {
|
||||
try {
|
||||
const { userId, organization } = req.params;
|
||||
if (!userId || !organization) {
|
||||
res.status(400).json({
|
||||
message: "All fields are required",
|
||||
});
|
||||
return;
|
||||
}
|
||||
const result = await RecentlyAdded({ userId, organization });
|
||||
|
||||
switch (result.status) {
|
||||
case "User not found":
|
||||
res.status(404).json({
|
||||
message: "User not found",
|
||||
});
|
||||
break;
|
||||
case "Datas were empty":
|
||||
res.status(200).json({
|
||||
RecentlyViewed: [],
|
||||
});
|
||||
break;
|
||||
case "Success":
|
||||
res.status(200).json({
|
||||
RecentlyViewed: result.data,
|
||||
});
|
||||
break;
|
||||
default:
|
||||
res.status(500).json({
|
||||
message: "Internal server error",
|
||||
});
|
||||
break;
|
||||
}
|
||||
} catch (error) {
|
||||
res.status(500).json({
|
||||
message: "Unknown error",
|
||||
});
|
||||
return;
|
||||
}
|
||||
};
|
||||
@@ -186,6 +186,7 @@ export const updateProjectController = async (
|
||||
};
|
||||
export const ViewData = async (req: Request, res: Response): Promise<void> => {
|
||||
try {
|
||||
console.log("req.query: ", req.query);
|
||||
const { projectId, organization, userId } = req.query as {
|
||||
organization: string;
|
||||
projectId: string;
|
||||
@@ -202,6 +203,7 @@ export const ViewData = async (req: Request, res: Response): Promise<void> => {
|
||||
organization,
|
||||
userId,
|
||||
});
|
||||
console.log("result: ", result);
|
||||
switch (result?.status) {
|
||||
case "Project not found":
|
||||
res.status(404).json({
|
||||
|
||||
Reference in New Issue
Block a user