auto(agent): added try/catch and proper HTTP status codes in profile.js
This commit is contained in:
parent
b03b264c5e
commit
cd7fa3bac2
1 changed files with 11 additions and 6 deletions
|
|
@ -7,13 +7,18 @@ import { encryptText } from '../services/encryption.js';
|
||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.post('/phone', requireAuth, async (req, res) => {
|
router.post('/phone', requireAuth, async (req, res) => {
|
||||||
|
try {
|
||||||
const parsed = z.object({ phone: z.string().min(6).max(40) }).safeParse(req.body);
|
const parsed = z.object({ phone: z.string().min(6).max(40) }).safeParse(req.body);
|
||||||
if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() });
|
if (!parsed.success) return res.status(400).json({ error: parsed.error.flatten() });
|
||||||
|
|
||||||
const encryptedPhone = encryptText(parsed.data.phone);
|
const encryptedPhone = encryptText(parsed.data.phone);
|
||||||
await pool.query('UPDATE users SET phone_encrypted = ? WHERE id = ?', [encryptedPhone, req.user.userId]);
|
await pool.query('UPDATE users SET phone_encrypted = ? WHERE id = ?', [encryptedPhone, req.user.userId]);
|
||||||
|
|
||||||
res.json({ status: 'updated' });
|
res.status(200).json({ status: 'updated' });
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error updating phone:', error);
|
||||||
|
res.status(500).json({ error: 'Internal server error' });
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue