update 00000

This commit is contained in:
smfahim25 2025-03-19 10:37:06 +06:00
parent e13b787836
commit 2f80b6dc56
2 changed files with 57 additions and 40 deletions

View file

@ -3,45 +3,58 @@ import { generateToken, getUserData, updateUser } from "./auth.controller";
import { verifyAuth } from "../../middlewares/auth.middlewares";
export const authRoute = new Elysia({
prefix: "/auth",
prefix: "/api/auth",
tags: ["Auth"],
detail: {
description: "Routes for managing users",
}
})
authRoute.get("/user/:userId", async ({ params: { userId } }) => await getUserData(userId), {
params: t.Object({
userId: t.String()
})
},
});
authRoute.post("/user/update/:userId", async ({ params: { userId }, body }) => await updateUser(userId, body), {
authRoute.get(
"/user/:userId",
async ({ params: { userId } }) => await getUserData(userId),
{
params: t.Object({
userId: t.String()
userId: t.String(),
}),
}
);
authRoute.post(
"/user/update/:userId",
async ({ params: { userId }, body }) => await updateUser(userId, body),
{
params: t.Object({
userId: t.String(),
}),
body: t.Object({
paid_status: t.String(),
package_expire_date: t.String(),
})
});
}),
}
);
authRoute.get("/generate-token/:userId", async (context) => await generateToken(context));
authRoute.get(
"/generate-token/:userId",
async (context) => await generateToken(context)
);
authRoute.get("/user/me", async ({ cookie }) => {
const authData = await verifyAuth(cookie);
if (authData.status !== 200) {
return authData;
}
else {
} else {
const userId: string | any = authData.userId;
const response = await getUserData(userId);
if (response?.status === 200) {
return { ...response.data, token: authData.token, status: 200, message: "User data fetched successfully" };
}
else {
return {
...response.data,
token: authData.token,
status: 200,
message: "User data fetched successfully",
};
} else {
return response;
}
}
})
});

View file

@ -58,16 +58,20 @@ const app = new Elysia({
console.error(error);
});
// all routes here
app.use(api);
const api = app.group("/api", (app) => {
app.get("/", () => "API root is working");
// Debug - Print all registered routes
console.log("All registered routes:");
app.routes.forEach((route) => {
console.log(`${route.method} ${route.path}`);
// Include all your other routes inside this group
app.use(authRoute);
app.use(projectRoutes);
app.use(uploadRoutes);
app.use(downloadRoute);
return app;
});
app.get("/", () => "API root is working");
// all routes here
app.use(api);
app.listen(ENV.SERVER_PORT, () => {
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);