update 00000

This commit is contained in:
smfahim25 2025-03-19 10:54:15 +06:00
parent 6bbf2137b5
commit 9ed91b4a06
2 changed files with 21 additions and 143 deletions

View file

@ -1,4 +1,4 @@
import Elysia, { t } from "elysia"; import { Elysia, t } from "elysia";
import { generateToken, getUserData, updateUser } from "./auth.controller"; import { generateToken, getUserData, updateUser } from "./auth.controller";
import { verifyAuth } from "../../middlewares/auth.middlewares"; import { verifyAuth } from "../../middlewares/auth.middlewares";
@ -11,27 +11,10 @@ authRoute.get(
detail: { detail: {
tags: ["Auth"], tags: ["Auth"],
summary: "Get user data", summary: "Get user data",
description: "Retrieve user data by user ID",
}, },
params: t.Object({ params: t.Object({
userId: t.String({ description: "The user ID" }), userId: t.String(),
}), }),
response: {
200: t.Object({
status: t.Number(),
message: t.String(),
data: t.Object({
// Define user data properties here
// For example:
id: t.String(),
// Add other fields
}),
}),
404: t.Object({
status: t.Number(),
message: t.String(),
}),
},
} }
); );
@ -41,27 +24,15 @@ authRoute.post(
{ {
detail: { detail: {
tags: ["Auth"], tags: ["Auth"],
summary: "Update user data", summary: "Update user",
description: "Update user payment status and expiration date",
}, },
params: t.Object({ params: t.Object({
userId: t.String({ description: "The user ID to update" }), userId: t.String(),
}), }),
body: t.Object({ body: t.Object({
paid_status: t.String({ description: "User payment status" }), paid_status: t.String(),
package_expire_date: t.String({ description: "Package expiration date" }), package_expire_date: t.String(),
}), }),
response: {
200: t.Object({
status: t.Number(),
message: t.String(),
// Add other expected response properties
}),
400: t.Object({
status: t.Number(),
message: t.String(),
}),
},
} }
); );
@ -71,23 +42,11 @@ authRoute.get(
{ {
detail: { detail: {
tags: ["Auth"], tags: ["Auth"],
summary: "Generate authentication token", summary: "Generate token",
description: "Generate a new auth token for the specified user",
}, },
params: t.Object({ params: t.Object({
userId: t.String({ description: "The user ID" }), userId: t.String(),
}), }),
response: {
200: t.Object({
status: t.Number(),
message: t.String(),
token: t.String(),
}),
400: t.Object({
status: t.Number(),
message: t.String(),
}),
},
} }
); );
@ -98,7 +57,7 @@ authRoute.get(
if (authData.status !== 200) { if (authData.status !== 200) {
return authData; return authData;
} else { } else {
const userId: string | any = authData.userId; const userId = authData.userId;
const response = await getUserData(userId); const response = await getUserData(userId);
if (response?.status === 200) { if (response?.status === 200) {
return { return {
@ -115,20 +74,7 @@ authRoute.get(
{ {
detail: { detail: {
tags: ["Auth"], tags: ["Auth"],
summary: "Get current user data", summary: "Get current user",
description: "Get currently authenticated user data from cookie",
},
response: {
200: t.Object({
status: t.Number(),
message: t.String(),
token: t.String(),
// Add other user data properties
}),
401: t.Object({
status: t.Number(),
message: t.String(),
}),
}, },
} }
); );

View file

@ -4,17 +4,15 @@ import cors from "@elysiajs/cors";
import { ENV } from "./config/env"; import { ENV } from "./config/env";
import { api } from "./api"; import { api } from "./api";
const allowedOrigins = [
"http://localhost:5175",
"http://localhost:5173",
"https://dashboard.planpostai.com",
"https://canvas.planpostai.com",
];
const app = new Elysia() const app = new Elysia()
.use( .use(
cors({ cors({
origin: allowedOrigins, origin: [
"http://localhost:5175",
"http://localhost:5173",
"https://dashboard.planpostai.com",
"https://canvas.planpostai.com",
],
methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"], methods: ["GET", "POST", "PUT", "DELETE", "PATCH", "HEAD", "OPTIONS"],
allowedHeaders: [ allowedHeaders: [
"Content-Type", "Content-Type",
@ -43,10 +41,9 @@ const app = new Elysia()
{ name: "Auth", description: "Authentication related endpoints" }, { name: "Auth", description: "Authentication related endpoints" },
{ name: "Download", description: "Download count related endpoints" }, { name: "Download", description: "Download count related endpoints" },
], ],
// Add server information to help Swagger understand your API
servers: [ servers: [
{ {
url: ENV.SERVER_URL + ":" + ENV.SERVER_PORT, url: ENV.SERVER_URL,
description: "Canvas API Server", description: "Canvas API Server",
}, },
], ],
@ -57,81 +54,16 @@ const app = new Elysia()
detail: { detail: {
tags: ["Default"], tags: ["Default"],
summary: "Server root", summary: "Server root",
description: "Returns a message indicating server is running",
},
response: {
200: t.String(),
}, },
}) })
.get("/test-swagger", () => "Test route with complete swagger docs", { .get("/test-swagger", () => "Test route with Swagger docs", {
detail: { detail: {
tags: ["Default"], tags: ["Default"],
summary: "Test Swagger", summary: "Test Swagger",
description: "Test route with complete Swagger documentation",
},
response: {
200: t.String(),
}, },
}) })
.get(
"/debug/routes",
() => {
return {
routes: app.routes.map((route) => ({
method: route.method,
path: route.path,
detail: route.detail
? {
tags: route.detail.tags,
summary: route.detail.summary,
}
: "No detail",
})),
};
},
{
detail: {
tags: ["Default"],
summary: "Debug Routes",
description: "Shows all registered routes",
},
response: {
200: t.Object({
routes: t.Array(
t.Object({
method: t.String(),
path: t.String(),
detail: t.Any(),
})
),
}),
},
}
)
.use(api) .use(api)
.onError(({ code, error }) => { .listen(ENV.SERVER_PORT);
console.error(`App Error: ${code}`, error);
if (code === "NOT_FOUND") return "Not Found :(";
return "An error occurred";
});
// Log environment configuration console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}`);
console.log("Environment configuration:", { console.log(`Swagger docs available at ${ENV.SERVER_URL}/docs`);
SERVER_URL: ENV.SERVER_URL,
SERVER_PORT: ENV.SERVER_PORT,
});
app.listen(ENV.SERVER_PORT, () => {
console.log(`🦊 Elysia is running at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}`);
console.log(
`Swagger docs available at ${ENV.SERVER_URL}:${ENV.SERVER_PORT}/docs`
);
console.log("All registered routes:");
app.routes.forEach((route) => {
// Also log the detail object to see if routes have Swagger metadata
console.log(
`${route.method} ${route.path} - Detail: ${route.detail ? "Yes" : "No"}`
);
});
});