adding @me /:userId/roles

This commit is contained in:
2024-03-31 20:12:51 +00:00
parent d93bfe333d
commit 82486c68e7
5 changed files with 7 additions and 2 deletions

BIN
bun.lockb

Binary file not shown.

View File

@@ -47,6 +47,7 @@ export async function verifyPermissions(userId, permissionName, permissionType)
} }
export async function checkIfUserEmailIsVerified(userId) { export async function checkIfUserEmailIsVerified(userId) {
return true;
try { try {
const [user] = await pool.execute('SELECT email_verified FROM users WHERE id = ? LIMIT 1', [userId]); const [user] = await pool.execute('SELECT email_verified FROM users WHERE id = ? LIMIT 1', [userId]);
if (user.length === 0) return false; if (user.length === 0) return false;

View File

@@ -29,6 +29,7 @@
"node-cron": "^3.0.3", "node-cron": "^3.0.3",
"nodemailer": "^6.9.10", "nodemailer": "^6.9.10",
"path": "^0.12.7", "path": "^0.12.7",
"pino": "^8.16.2" "pino": "^8.16.2",
"pino-pretty": "^11.0.0"
} }
} }

View File

@@ -63,7 +63,7 @@ router.post('/register', verifyToken, checkEmailVerified, checkBanned, async (re
if ([ email, phone, speciality, status ].every(Boolean)) { if ([ email, phone, speciality, status ].every(Boolean)) {
try { try {
const [result] = await pool.execute( const [result] = await pool.execute(
'INSERT INTO doctors (user_id, email, phone, speciality, status) VALUES (?, ?, ?, ?, ?, ?)', 'INSERT INTO doctors (user_id, email, phone, speciality, status) VALUES (?, ?, ?, ?, ?)',
[req.userId, email, phone, speciality, status], [req.userId, email, phone, speciality, status],
); );
if (result.affectedRows === 0) return await respondWithStatus(res, 500, 'Error storing doctor'); if (result.affectedRows === 0) return await respondWithStatus(res, 500, 'Error storing doctor');

View File

@@ -327,6 +327,9 @@ router.delete('/:userId', verifyToken, checkBanned, async (req, res) => {
router.get('/:userId/roles', verifyToken, checkBanned, async (req, res) => { router.get('/:userId/roles', verifyToken, checkBanned, async (req, res) => {
try { try {
if (req.params.userId == '@me') {
req.params.userId = req.userId;
}
if (req.params.userId != req.userId && !verifyPermissions(req.userId, 'user', 1)) return await respondWithStatus(res, 403, 'Missing permission'); if (req.params.userId != req.userId && !verifyPermissions(req.userId, 'user', 1)) return await respondWithStatus(res, 403, 'Missing permission');
const [rows] = await pool.execute('SELECT r.* FROM users u INNER JOIN user_roles ur ON u.id = ur.user_id INNER JOIN roles r ON ur.role_id = r.id WHERE u.id = ?', [ req.params.userId ]); const [rows] = await pool.execute('SELECT r.* FROM users u INNER JOIN user_roles ur ON u.id = ur.user_id INNER JOIN roles r ON ur.role_id = r.id WHERE u.id = ?', [ req.params.userId ]);
if (rows.length === 0) return await respondWithStatus(res, 404, 'No roles found'); if (rows.length === 0) return await respondWithStatus(res, 404, 'No roles found');