Fix token packages authentication issue - add public endpoint for token packages

This commit is contained in:
2025-09-20 16:54:59 +02:00
parent e75424aac0
commit 528be6027a
3 changed files with 31 additions and 8 deletions
@@ -51,6 +51,33 @@ export class PaymentController {
return user;
}
// Get available token packages (public endpoint for purchasing)
@Get("/token-packages")
@Summary("Get available token packages for purchase")
@Description("Returns all active token packages that users can purchase")
@Returns(200, Array).Description("List of available token packages")
async getTokenPackages() {
const connection = await pool.getConnection();
try {
const [rows] = await connection.execute(`
SELECT * FROM token_packages
WHERE is_active = 1
ORDER BY quantity ASC
`);
return {
success: true,
packages: Array.isArray(rows) ? rows : []
};
} catch (error) {
console.error('Error getting token packages:', error);
throw new BadRequest("Failed to fetch token packages");
} finally {
connection.release();
}
}
/**
* Calculate token price for a given quantity
*/