update 00000
This commit is contained in:
parent
e13b787836
commit
2f80b6dc56
2 changed files with 57 additions and 40 deletions
|
|
@ -3,45 +3,58 @@ import { generateToken, getUserData, updateUser } from "./auth.controller";
|
||||||
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
import { verifyAuth } from "../../middlewares/auth.middlewares";
|
||||||
|
|
||||||
export const authRoute = new Elysia({
|
export const authRoute = new Elysia({
|
||||||
prefix: "/auth",
|
prefix: "/api/auth",
|
||||||
tags: ["Auth"],
|
tags: ["Auth"],
|
||||||
detail: {
|
detail: {
|
||||||
description: "Routes for managing users",
|
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({
|
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({
|
body: t.Object({
|
||||||
paid_status: t.String(),
|
paid_status: t.String(),
|
||||||
package_expire_date: 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 }) => {
|
authRoute.get("/user/me", async ({ cookie }) => {
|
||||||
const authData = await verifyAuth(cookie);
|
const authData = await verifyAuth(cookie);
|
||||||
if (authData.status !== 200) {
|
if (authData.status !== 200) {
|
||||||
return authData;
|
return authData;
|
||||||
|
} 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;
|
||||||
}
|
}
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
|
|
||||||
18
src/app.ts
18
src/app.ts
|
|
@ -58,16 +58,20 @@ const app = new Elysia({
|
||||||
console.error(error);
|
console.error(error);
|
||||||
});
|
});
|
||||||
|
|
||||||
// all routes here
|
const api = app.group("/api", (app) => {
|
||||||
app.use(api);
|
app.get("/", () => "API root is working");
|
||||||
|
|
||||||
// Debug - Print all registered routes
|
// Include all your other routes inside this group
|
||||||
console.log("All registered routes:");
|
app.use(authRoute);
|
||||||
app.routes.forEach((route) => {
|
app.use(projectRoutes);
|
||||||
console.log(`${route.method} ${route.path}`);
|
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, () => {
|
app.listen(ENV.SERVER_PORT, () => {
|
||||||
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);
|
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue