tududi/backend/services/rolesService.js
2025-10-11 13:26:56 +03:00

18 lines
450 B
JavaScript

const { Role, User } = require('../models');
async function isAdmin(userUid) {
if (!userUid) return false;
// Find user by uid to get numeric id for role lookup
const user = await User.findOne({
where: { uid: userUid },
attributes: ['id'],
});
if (!user) return false;
const role = await Role.findOne({ where: { user_id: user.id } });
return !!(role && role.is_admin);
}
module.exports = { isAdmin };