adding @me /:userId/roles
This commit is contained in:
@@ -47,6 +47,7 @@ export async function verifyPermissions(userId, permissionName, permissionType)
|
||||
}
|
||||
|
||||
export async function checkIfUserEmailIsVerified(userId) {
|
||||
return true;
|
||||
try {
|
||||
const [user] = await pool.execute('SELECT email_verified FROM users WHERE id = ? LIMIT 1', [userId]);
|
||||
if (user.length === 0) return false;
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
"node-cron": "^3.0.3",
|
||||
"nodemailer": "^6.9.10",
|
||||
"path": "^0.12.7",
|
||||
"pino": "^8.16.2"
|
||||
"pino": "^8.16.2",
|
||||
"pino-pretty": "^11.0.0"
|
||||
}
|
||||
}
|
||||
@@ -63,7 +63,7 @@ router.post('/register', verifyToken, checkEmailVerified, checkBanned, async (re
|
||||
if ([ email, phone, speciality, status ].every(Boolean)) {
|
||||
try {
|
||||
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],
|
||||
);
|
||||
if (result.affectedRows === 0) return await respondWithStatus(res, 500, 'Error storing doctor');
|
||||
|
||||
@@ -327,6 +327,9 @@ router.delete('/:userId', verifyToken, checkBanned, async (req, res) => {
|
||||
|
||||
router.get('/:userId/roles', verifyToken, checkBanned, async (req, res) => {
|
||||
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');
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user