AWS SES preview
This commit is contained in:
46
server/src/routes/profile.ts
Normal file
46
server/src/routes/profile.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { Router } from 'express';
|
||||
import { requireAuth } from '../auth/middleware';
|
||||
import { pool } from '../db/pool';
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.get('/', requireAuth, async (req, res) => {
|
||||
try {
|
||||
const result = await pool.query(
|
||||
'SELECT * FROM user_profile WHERE user_id = $1',
|
||||
[req.user!.id]
|
||||
);
|
||||
if (result.rows.length === 0) {
|
||||
return res.status(404).json({ error: 'Profile not found' });
|
||||
}
|
||||
res.json(result.rows[0]);
|
||||
} catch {
|
||||
res.status(500).json({ error: 'Server error' });
|
||||
}
|
||||
});
|
||||
|
||||
router.post('/', requireAuth, async (req, res) => {
|
||||
const { pi_first_name, bldg_code, lab, contact } = req.body;
|
||||
if (!pi_first_name || !bldg_code || !lab) {
|
||||
return res.status(400).json({ error: 'pi_first_name, bldg_code, and lab are required' });
|
||||
}
|
||||
try {
|
||||
const result = await pool.query(
|
||||
`INSERT INTO user_profile (user_id, pi_first_name, bldg_code, lab, contact)
|
||||
VALUES ($1, $2, $3, $4, $5)
|
||||
ON CONFLICT (user_id) DO UPDATE SET
|
||||
pi_first_name = EXCLUDED.pi_first_name,
|
||||
bldg_code = EXCLUDED.bldg_code,
|
||||
lab = EXCLUDED.lab,
|
||||
contact = EXCLUDED.contact,
|
||||
updated_at = NOW()
|
||||
RETURNING *`,
|
||||
[req.user!.id, pi_first_name, bldg_code, lab, contact || null]
|
||||
);
|
||||
res.json(result.rows[0]);
|
||||
} catch {
|
||||
res.status(500).json({ error: 'Server error' });
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
Reference in New Issue
Block a user