fixed premium upgrade endpoint
This commit is contained in:
parent
c760bf7892
commit
cec6f3f059
@ -427,6 +427,39 @@ app.get('/api/areas', (req, res) => {
|
||||
});
|
||||
});
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
PREMIUM UPGRADE ENDPOINT
|
||||
------------------------------------------------------------------ */
|
||||
app.post('/api/activate-premium', (req, res) => {
|
||||
const token = req.headers.authorization?.split(' ')[1];
|
||||
if (!token) {
|
||||
return res.status(401).json({ error: 'Authorization token is required' });
|
||||
}
|
||||
|
||||
let userId; // Will hold the auto-increment "id" from user_profile
|
||||
try {
|
||||
const decoded = jwt.verify(token, SECRET_KEY);
|
||||
userId = decoded.userId; // => user_profile.id (auto-inc PK)
|
||||
} catch (error) {
|
||||
return res.status(401).json({ error: 'Invalid or expired token' });
|
||||
}
|
||||
|
||||
// Use MySQL pool.query instead of db.run (which is for SQLite)
|
||||
const query = `
|
||||
UPDATE user_profile
|
||||
SET is_premium = 1,
|
||||
is_pro_premium = 1
|
||||
WHERE id = ?
|
||||
`;
|
||||
pool.query(query, [userId], (err, results) => {
|
||||
if (err) {
|
||||
console.error('Error updating premium status:', err.message);
|
||||
return res.status(500).json({ error: 'Failed to activate premium' });
|
||||
}
|
||||
return res.status(200).json({ message: 'Premium activated successfully' });
|
||||
});
|
||||
});
|
||||
|
||||
// =============== START SERVER ===============
|
||||
app.listen(PORT, () => {
|
||||
console.log(`Server running on http://localhost:${PORT}`);
|
||||
|
@ -66,38 +66,6 @@ const authenticatePremiumUser = (req, res, next) => {
|
||||
}
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
PREMIUM UPGRADE ENDPOINT
|
||||
------------------------------------------------------------------ */
|
||||
app.post('/api/activate-premium', (req, res) => {
|
||||
const token = req.headers.authorization?.split(' ')[1];
|
||||
if (!token) {
|
||||
return res.status(401).json({ error: 'Authorization token is required' });
|
||||
}
|
||||
|
||||
let userId;
|
||||
try {
|
||||
const decoded = jwt.verify(token, SECRET_KEY);
|
||||
userId = decoded.userId;
|
||||
} catch (error) {
|
||||
return res.status(401).json({ error: 'Invalid or expired token' });
|
||||
}
|
||||
|
||||
const query = `
|
||||
UPDATE user_profile
|
||||
SET is_premium = 1, is_pro_premium = 1
|
||||
WHERE user_id = ?
|
||||
`;
|
||||
db.run(query, [userId], (err) => {
|
||||
if (err) {
|
||||
console.error('Error updating premium status:', err.message);
|
||||
return res.status(500).json({ error: 'Failed to activate premium' });
|
||||
}
|
||||
res.status(200).json({ message: 'Premium activated successfully' });
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------
|
||||
CAREER PROFILE ENDPOINTS
|
||||
------------------------------------------------------------------ */
|
||||
|
Loading…
Reference in New Issue
Block a user